From 18d8aaddd4709ba1d1b74791a30c5c5f93926e48 Mon Sep 17 00:00:00 2001 From: Dobromir Palushev <dobromir@peaksandpies.com> Date: Sat, 3 Sep 2022 16:51:34 +0200 Subject: [PATCH] pipeline and docker updates --- .gitlab-ci.yml | 3 ++- app/Dockerfile | 29 ----------------------------- app/Dockerfile.test | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 30 deletions(-) create mode 100644 app/Dockerfile.test diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 31ffb58..3d322ef 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -49,7 +49,8 @@ run-tests: --network=host --build-arg MONGODB_URL_TEST=mongodb://localhost:27017/todo-app --build-arg JWT_SECRET_TEST=my-very-secret-jwt - --add-host=host.docker.internal:localhost + --add-host=host.docker.internal:host-gateway + --file Dockerfile.test "./app" after_script: - docker stop mongo-container diff --git a/app/Dockerfile b/app/Dockerfile index af43271..224291a 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -14,35 +14,6 @@ ENV \ MONGODB_URL=<dynamically-set-from-k8s> \ JWT_SECRET=<dynamically-set-from-k8s> -# ------------------------------------------------------------------ -# # Test stage -# FROM base AS test - -# # client tests -# WORKDIR /client - -# COPY ./client . - -# RUN npm ci --no-audit --no-fund - -# RUN npm run test - -# # server tests -# WORKDIR /server - -# COPY ./server/src ./src/ - -# COPY ./server/package*.json ./ - -# RUN npm ci --no-audit --no-fund - -# ARG MONGODB_URL_TEST -# ARG JWT_SECRET_TEST - -# # MONGODB_URL and JWT_SECRET are available as env variables -# RUN MONGODB_URL=$MONGODB_URL_TEST JWT_SECRET=$JWT_SECRET_TEST npm run test - -# ------------------------------------------------------------------ # Build stage FROM base AS build diff --git a/app/Dockerfile.test b/app/Dockerfile.test new file mode 100644 index 0000000..7b565b9 --- /dev/null +++ b/app/Dockerfile.test @@ -0,0 +1,29 @@ +ARG NODEJS_VERSION='16.17.0' + +# Test stage +FROM node:$NODEJS_VERSION-alpine + +# client tests +WORKDIR /client + +COPY ./client . + +RUN npm ci --no-audit --no-fund + +RUN npm run test + +# server tests +WORKDIR /server + +COPY ./server/src ./src/ + +COPY ./server/package*.json ./ + +RUN npm ci --no-audit --no-fund + +ARG \ + MONGODB_URL_TEST=mongodb://host.docker.internal:27017/todo-app \ + JWT_SECRET_TEST=<my-very-secret-jwt> + +# MONGODB_URL and JWT_SECRET are available as env variables +RUN MONGODB_URL=$MONGODB_URL_TEST JWT_SECRET=$JWT_SECRET_TEST npm run test -- GitLab