From ed54f9e1508356e2251b0d4af962aa4c9ab4e7c2 Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 25 Oct 2021 21:45:05 +0200 Subject: [PATCH 01/10] :whale: Create Dockerfile --- Dockerfile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..56c5078 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM node:lts as builder +WORKDIR /build + +COPY . . +RUN yarn install +RUN yarn build + +FROM node:lts + +WORKDIR /app + +COPY --from=builder /build/dist ./dist +COPY --from=builder /build/package.json package.json + +RUN yarn install --prod + +CMD ["yarn", "start:prod"] + From f79b57012052092a4feae157376aaf0d4f69e36e Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 25 Oct 2021 22:15:57 +0200 Subject: [PATCH 02/10] :construction_worker: Add docker push config --- .circleci/config.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index dded634..c4cdb47 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,6 +7,11 @@ globals: postgres: &postgres circleci/postgres:9.6.5 caches: dependencies: &dependencies dependencies-{{ checksum "package.json" }} + docker_hub: + user-id: &dockerhub-user-id anthonyjhoiro + password: &dockerhub-password $DOCKERHUB_PASSWORD + image: &dockerhub-image devops-tpfinal + # --- Commands --- # @@ -72,6 +77,27 @@ jobs: name: Lint files command: yarn lint + docker-build: + <<: *shared-config + environment: + DOCKER_HUB_PWD: *dockerhub-password + DOCKER_HUB_USER_ID: *dockerhub-user-id + DOCKER_HUB_IMAGE: *dockerhub-image + steps: + - checkout + - setup_remote_docker + - run: + name: Build docker image + command: docker build --cache-from=app -t app . + - deploy: + name: Publish image to Docker Hub + command: | + echo $DOCKER_HUB_PWD | docker login -u $DOCKER_HUB_USER_ID --password-stdin + docker tag app $DOCKER_HUB_USER_ID/$DOCKER_HUB_IMAGE:$CIRCLE_BUILD_NUM + docker tag app $DOCKER_HUB_USER_ID/$DOCKER_HUB_IMAGE:latest + docker push $DOCKER_HUB_USER_ID/$DOCKER_HUB_IMAGE:$CIRCLE_BUILD_NUM + docker push $DOCKER_HUB_USER_ID/$DOCKER_HUB_IMAGE:latest + # --- Workflow definition --- # workflows: @@ -88,3 +114,13 @@ workflows: - lint: requires: - build + - docker-build: + requires: + - test + - test:e2e + - lint +# Add it before pull request +# filters: +# branches: +# only: +# - main From 78ddddb03ac1998647a311819034f0137e3d43d8 Mon Sep 17 00:00:00 2001 From: anthony Date: Mon, 25 Oct 2021 22:17:36 +0200 Subject: [PATCH 03/10] :pencil2: Fix required step name --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c4cdb47..922b163 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: - docker-build: requires: - test - - test:e2e + - test-e2e - lint # Add it before pull request # filters: From 8248fe564d23943260304f8ccb2d3fa7bb90a556 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 26 Oct 2021 09:07:43 +0200 Subject: [PATCH 04/10] :green_heart: Remove docker cache when build image --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 922b163..940822a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -88,7 +88,7 @@ jobs: - setup_remote_docker - run: name: Build docker image - command: docker build --cache-from=app -t app . + command: docker build -t app . - deploy: name: Publish image to Docker Hub command: | From 5d2c4e7f84d01ace51845673125c53d04b3a48e6 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 26 Oct 2021 09:35:24 +0200 Subject: [PATCH 05/10] :green_heart: Switch to cimg/node:current image --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 940822a..5a16864 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2.1 globals: images: - node: &node cimg/node:lts + node: &node cimg/node:current postgres: &postgres circleci/postgres:9.6.5 caches: dependencies: &dependencies dependencies-{{ checksum "package.json" }} From afb07e13dc03f4ef94f519d29adbea1281c5d60f Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 26 Oct 2021 10:00:53 +0200 Subject: [PATCH 06/10] :green_heart: Change relative paths to absolute paths in the Dockerfile & clean yarn cache --- .circleci/config.yml | 2 +- Dockerfile | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5a16864..940822a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2.1 globals: images: - node: &node cimg/node:current + node: &node cimg/node:lts postgres: &postgres circleci/postgres:9.6.5 caches: dependencies: &dependencies dependencies-{{ checksum "package.json" }} diff --git a/Dockerfile b/Dockerfile index 56c5078..4f5ebce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,13 +4,14 @@ WORKDIR /build COPY . . RUN yarn install RUN yarn build +RUN yarn cache clean FROM node:lts WORKDIR /app -COPY --from=builder /build/dist ./dist -COPY --from=builder /build/package.json package.json +COPY --from=builder /build/dist /app/dist +COPY --from=builder /build/package.json /app/package.json RUN yarn install --prod From 03e9235fb07cd1c473a359ec46365342e0fe6d34 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 26 Oct 2021 10:08:13 +0200 Subject: [PATCH 07/10] :green_heart: Add auth for circleci image --- .circleci/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 940822a..1ac0c02 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -30,6 +30,9 @@ jobs: build: &shared-config docker: - image: *node + auth: + username: *dockerhub-user-id + password: *dockerhub-password working_directory: ~/app steps: - checkout From c79de8c28d70120ad51ff7a92447c6382884bf8c Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 26 Oct 2021 10:14:37 +0200 Subject: [PATCH 08/10] :green_heart: Upgrade docker engine version --- .circleci/config.yml | 3 ++- Dockerfile | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1ac0c02..47a2322 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -88,7 +88,8 @@ jobs: DOCKER_HUB_IMAGE: *dockerhub-image steps: - checkout - - setup_remote_docker + - setup_remote_docker: + version: 20.10.7 - run: name: Build docker image command: docker build -t app . diff --git a/Dockerfile b/Dockerfile index 4f5ebce..af00f65 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,6 @@ WORKDIR /build COPY . . RUN yarn install RUN yarn build -RUN yarn cache clean FROM node:lts From 706170e853dfed4a726e210328388506df1b9b4e Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 26 Oct 2021 10:25:50 +0200 Subject: [PATCH 09/10] :green_heart: Change the use of environement variable --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 47a2322..379c9f3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -96,7 +96,7 @@ jobs: - deploy: name: Publish image to Docker Hub command: | - echo $DOCKER_HUB_PWD | docker login -u $DOCKER_HUB_USER_ID --password-stdin + echo $DOCKERHUB_PASSWORD | docker login -u $DOCKER_HUB_USER_ID --password-stdin docker tag app $DOCKER_HUB_USER_ID/$DOCKER_HUB_IMAGE:$CIRCLE_BUILD_NUM docker tag app $DOCKER_HUB_USER_ID/$DOCKER_HUB_IMAGE:latest docker push $DOCKER_HUB_USER_ID/$DOCKER_HUB_IMAGE:$CIRCLE_BUILD_NUM From c820c105ef221500afcc59217a89e1bf2ed73b5d Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 26 Oct 2021 10:41:53 +0200 Subject: [PATCH 10/10] :construction_worker: Add filters for docker build step --- .circleci/config.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 379c9f3..461688f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -123,8 +123,7 @@ workflows: - test - test-e2e - lint -# Add it before pull request -# filters: -# branches: -# only: -# - main + filters: + branches: + only: + - main