From bc7b5fc6c99888429e0e0b179482ae9f6a9abbf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 9 Apr 2020 11:00:30 +0200 Subject: [PATCH 01/12] Setting up continuous deployment --- .github/workflows/build-and-deploy.yml | 65 ++++++++++++++++++++++++++ back/.dockerignore | 4 ++ back/Dockerfile | 8 ++++ deeployer.json | 19 ++++++++ front/.dockerignore | 3 ++ front/Dockerfile | 9 ++++ 6 files changed, 108 insertions(+) create mode 100644 .github/workflows/build-and-deploy.yml create mode 100644 back/.dockerignore create mode 100644 back/Dockerfile create mode 100644 deeployer.json create mode 100644 front/.dockerignore create mode 100644 front/Dockerfile diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml new file mode 100644 index 00000000..ec7d3c69 --- /dev/null +++ b/.github/workflows/build-and-deploy.yml @@ -0,0 +1,65 @@ +name: Build, push and deploy Docker image + +on: + push: + branches: + - master + - cd +# tags: +# - '*' + +# Enables BuildKit +env: + DOCKER_BUILDKIT: 1 + +jobs: + + build-front: + + runs-on: ubuntu-latest + + steps: + + - name: Checkout + uses: actions/checkout@v2 + + - name: "Build and push front image" + uses: docker/build-push-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: thecodingmachine/workadventure-front + tag_with_ref: true + add_git_labels: true + working-directory: "front" + + build-back: + + runs-on: ubuntu-latest + + steps: + + - name: Checkout + uses: actions/checkout@v2 + + - name: "Build and push back image" + uses: docker/build-push-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: thecodingmachine/workadventure-back + tag_with_ref: true + add_git_labels: true + working-directory: "back" + + deeploy: + needs: + - build-front + - build-back + runs-on: ubuntu-latest + + - name: Checkout + uses: actions/checkout@v2 + + - name: "Deploy" + uses: thecodingmachine/deeployer@master diff --git a/back/.dockerignore b/back/.dockerignore new file mode 100644 index 00000000..ca0a17d7 --- /dev/null +++ b/back/.dockerignore @@ -0,0 +1,4 @@ +/dist/ +/node_modules/ +/dist/bundle.js +/yarn-error.log diff --git a/back/Dockerfile b/back/Dockerfile new file mode 100644 index 00000000..edaeee6a --- /dev/null +++ b/back/Dockerfile @@ -0,0 +1,8 @@ +FROM thecodingmachine/nodejs:12 + +COPY . . +RUN yarn install + +ENV NODE_ENV=production + +CMD ['yarn', 'run', 'prod'] diff --git a/deeployer.json b/deeployer.json new file mode 100644 index 00000000..2eaeeba0 --- /dev/null +++ b/deeployer.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://raw.githubusercontent.com/thecodingmachine/deeployer/master/deeployer.schema.json", + "containers": { + "back": { + "image": "", + "host": "http://api.workadventure.test.thecodingmachine.com", + "env": { + "SECRET_KEY": "tempSecretKeyNeedsToChange" + } + }, + "front": { + "image": "", + "host": "http://workadventure.test.thecodingmachine.com", + "env": { + "API_URL": "http://api.workadventure.test.thecodingmachine.com" + } + } + } +} diff --git a/front/.dockerignore b/front/.dockerignore new file mode 100644 index 00000000..048e02ca --- /dev/null +++ b/front/.dockerignore @@ -0,0 +1,3 @@ +/node_modules/ +/dist/bundle.js +/yarn-error.log diff --git a/front/Dockerfile b/front/Dockerfile new file mode 100644 index 00000000..4ab4f273 --- /dev/null +++ b/front/Dockerfile @@ -0,0 +1,9 @@ +# we are rebuilding on each deploy to cope with the API_URL environment URL +FROM thecodingmachine/nodejs:12-apache + +COPY . . +RUN yarn install + +ENV NODE_ENV=production +ENV STARTUP_COMMAND_1="yarn run build" +ENV APACHE_DOCUMENT_ROOT=dist/ From c6770042b3bcc3faf80f01c0893dcab03c768121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 9 Apr 2020 11:03:24 +0200 Subject: [PATCH 02/12] Fixing action file --- .github/workflows/build-and-deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index ec7d3c69..9318049d 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -58,6 +58,7 @@ jobs: - build-back runs-on: ubuntu-latest + steps: - name: Checkout uses: actions/checkout@v2 From 3b3e615e37a2fcc474208ad8f5b86985db1e0f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 9 Apr 2020 11:56:29 +0200 Subject: [PATCH 03/12] Fixing push action --- .github/workflows/build-and-deploy.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 9318049d..a2e21d3f 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -26,6 +26,7 @@ jobs: - name: "Build and push front image" uses: docker/build-push-action@v1 with: + dockerfile: front/Dockerfile username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} repository: thecodingmachine/workadventure-front @@ -45,12 +46,12 @@ jobs: - name: "Build and push back image" uses: docker/build-push-action@v1 with: + dockerfile: back/Dockerfile username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} repository: thecodingmachine/workadventure-back tag_with_ref: true add_git_labels: true - working-directory: "back" deeploy: needs: From 1376d5b24cb2a9dda4440cfac9d8be9d337f845b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 9 Apr 2020 11:57:19 +0200 Subject: [PATCH 04/12] Fixing push action --- .github/workflows/build-and-deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index a2e21d3f..54c143fb 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -32,7 +32,6 @@ jobs: repository: thecodingmachine/workadventure-front tag_with_ref: true add_git_labels: true - working-directory: "front" build-back: From 8eba5276dde8c0c816ec37137c4f0db9e75bfde2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 9 Apr 2020 12:14:06 +0200 Subject: [PATCH 05/12] Adding namespace to deeployer --- .github/workflows/build-and-deploy.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 54c143fb..c44607c4 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -62,5 +62,7 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: "Deploy" + - name: Deploy uses: thecodingmachine/deeployer@master + with: + namespace: workadventure-${GITHUB_REF#refs/heads/} From 3038141070a0fa99c7a6cfcfbf627a538c06f5cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 9 Apr 2020 14:21:43 +0200 Subject: [PATCH 06/12] Setting Kube config in deeployer --- .github/workflows/build-and-deploy.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index c44607c4..5f6cd582 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -64,5 +64,8 @@ jobs: - name: Deploy uses: thecodingmachine/deeployer@master + env: + KUBE_CONFIG_FILE: ${{ secrets.KUBE_CONFIG_FILE }} + AUTOCONNECT: 1 with: namespace: workadventure-${GITHUB_REF#refs/heads/} From d68e39f2e3a5326eeed7146ef503f63727d43175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 9 Apr 2020 14:50:43 +0200 Subject: [PATCH 07/12] Testing --- .github/workflows/build-and-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 5f6cd582..58566734 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -68,4 +68,4 @@ jobs: KUBE_CONFIG_FILE: ${{ secrets.KUBE_CONFIG_FILE }} AUTOCONNECT: 1 with: - namespace: workadventure-${GITHUB_REF#refs/heads/} + namespace: workadventure-master From fd4d8dc651b750013d89bc5d516a04d25a199019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 9 Apr 2020 15:10:44 +0200 Subject: [PATCH 08/12] Fixing deeployer file --- deeployer.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/deeployer.json b/deeployer.json index 2eaeeba0..7e0e4984 100644 --- a/deeployer.json +++ b/deeployer.json @@ -2,15 +2,17 @@ "$schema": "https://raw.githubusercontent.com/thecodingmachine/deeployer/master/deeployer.schema.json", "containers": { "back": { - "image": "", + "image": "thecodingmachine/workadventure-back:cd", "host": "http://api.workadventure.test.thecodingmachine.com", + "ports": [8080], "env": { "SECRET_KEY": "tempSecretKeyNeedsToChange" } }, "front": { - "image": "", + "image": "thecodingmachine/workadventure-front:cd", "host": "http://workadventure.test.thecodingmachine.com", + "ports": [80], "env": { "API_URL": "http://api.workadventure.test.thecodingmachine.com" } From 7b51f734c57c91cbd018880ed32e03550958723b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Sat, 11 Apr 2020 12:27:03 +0200 Subject: [PATCH 09/12] Fixing hosts in deeployer config --- deeployer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deeployer.json b/deeployer.json index 7e0e4984..930e6f37 100644 --- a/deeployer.json +++ b/deeployer.json @@ -3,7 +3,7 @@ "containers": { "back": { "image": "thecodingmachine/workadventure-back:cd", - "host": "http://api.workadventure.test.thecodingmachine.com", + "host": "api.workadventure.test.thecodingmachine.com", "ports": [8080], "env": { "SECRET_KEY": "tempSecretKeyNeedsToChange" @@ -11,7 +11,7 @@ }, "front": { "image": "thecodingmachine/workadventure-front:cd", - "host": "http://workadventure.test.thecodingmachine.com", + "host": "workadventure.test.thecodingmachine.com", "ports": [80], "env": { "API_URL": "http://api.workadventure.test.thecodingmachine.com" From d979636a19aa8fd8e011eb6d5bd7548f3e5b1e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Sat, 11 Apr 2020 15:11:22 +0200 Subject: [PATCH 10/12] Fixing Dockerfiles --- back/.dockerignore | 1 + back/Dockerfile | 4 ++-- front/.dockerignore | 1 + front/Dockerfile | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/back/.dockerignore b/back/.dockerignore index ca0a17d7..576c21a2 100644 --- a/back/.dockerignore +++ b/back/.dockerignore @@ -2,3 +2,4 @@ /node_modules/ /dist/bundle.js /yarn-error.log +/Dockerfile diff --git a/back/Dockerfile b/back/Dockerfile index edaeee6a..316f505b 100644 --- a/back/Dockerfile +++ b/back/Dockerfile @@ -1,8 +1,8 @@ FROM thecodingmachine/nodejs:12 -COPY . . +COPY --chown=docker:docker . . RUN yarn install ENV NODE_ENV=production -CMD ['yarn', 'run', 'prod'] +CMD ["yarn", "run", "prod"] diff --git a/front/.dockerignore b/front/.dockerignore index 048e02ca..64d1025d 100644 --- a/front/.dockerignore +++ b/front/.dockerignore @@ -1,3 +1,4 @@ /node_modules/ /dist/bundle.js /yarn-error.log +/Dockerfile diff --git a/front/Dockerfile b/front/Dockerfile index 4ab4f273..ee15270e 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -1,7 +1,7 @@ # we are rebuilding on each deploy to cope with the API_URL environment URL FROM thecodingmachine/nodejs:12-apache -COPY . . +COPY --chown=docker:docker . . RUN yarn install ENV NODE_ENV=production From 62dd34b5912d1006fcf36ffd069de30262dd7c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Sun, 12 Apr 2020 15:50:14 +0200 Subject: [PATCH 11/12] Triggerring CI rerun --- back/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/back/Dockerfile b/back/Dockerfile index 316f505b..8b1b8f61 100644 --- a/back/Dockerfile +++ b/back/Dockerfile @@ -6,3 +6,4 @@ RUN yarn install ENV NODE_ENV=production CMD ["yarn", "run", "prod"] + From 877a47e2dd133f2b2cce587b29f86e2eebd12bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 13 Apr 2020 14:46:45 +0200 Subject: [PATCH 12/12] Fixing Dockerfile build path --- .github/workflows/build-and-deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 58566734..607e6ae7 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -27,6 +27,7 @@ jobs: uses: docker/build-push-action@v1 with: dockerfile: front/Dockerfile + path: front/ username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} repository: thecodingmachine/workadventure-front @@ -46,6 +47,7 @@ jobs: uses: docker/build-push-action@v1 with: dockerfile: back/Dockerfile + path: back/ username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} repository: thecodingmachine/workadventure-back