From a17c4d6464da71a3837aa68240633b445b8f301d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D1=8E=D1=82=D1=80=D1=8E=D0=BC=D0=BE=D0=B2=20=D0=A1?= =?UTF-8?q?=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9C=D0=B8=D1=85=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2=D0=B8=D1=87?= Date: Sun, 19 May 2024 16:11:49 +0300 Subject: [PATCH] docker build --- .gitlab-ci.yml | 37 +++++++++++++++++++++++++------------ Dockerfile | 22 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 Dockerfile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ec45bba..4895737 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,17 +1,30 @@ stages: - - lint + - build + - push variables: - NODE_OPTIONS: "--openssl-legacy-provider" + DOCKER_DRIVER: overlay2 + DOCKER_TLS_CERTDIR: "" + DOCKER_HOST: tcp://docker:2375/ -lint_frontend: - stage: lint - image: node:18-slim - before_script: - - npm config set strict-ssl false +services: + - docker:dind + +before_script: + - docker info + +build_container: + stage: build + image: docker:19.03.12 script: - - cd notes-app - - npm cache clean --force - - npm ci - - npm install eslint - - npx eslint . + - docker build -t $CI_REGISTRY_IMAGE/my-container:latest . + - docker tag $CI_REGISTRY_IMAGE/my-container:latest $CI_REGISTRY_IMAGE/my-container:$CI_COMMIT_SHORT_SHA + +push_container: + stage: push + image: docker:19.03.12 + script: + - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY + - docker push $CI_REGISTRY_IMAGE/my-container:latest + - docker push $CI_REGISTRY_IMAGE/my-container:$CI_COMMIT_SHORT_SHA + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b337463 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +#Front +FROM node:18-slim +WORKDIR /usr/local/app +COPY notes-app/package*.json ./ +RUN npm i && npm cache clean --force +COPY notes-app/ . +RUN npm run build +#Backend +FROM node:18-slim +WORKDIR /usr/local/app +COPY notes-backend/package*.json ./ +RUN npm i && npm cache clean --force +COPY notes-backend/ . +RUN npm run build +#nginx +FROM nginx:alpine +COPY nginx/default.conf /etc/nginx/conf.d/default.conf +COPY --from=build-react /app/build /usr/share/nginx/html +COPY --from=build-node /app/dist /usr/share/nginx/html/api +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] +