From b5901b253acd9541d8ef0decbeb7e6778e9d366e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 13 Apr 2020 15:07:04 +0200 Subject: [PATCH 1/9] Deploying one environment per branch --- deeployer.json | 21 --------------------- deeployer.libsonnet | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 21 deletions(-) delete mode 100644 deeployer.json create mode 100644 deeployer.libsonnet diff --git a/deeployer.json b/deeployer.json deleted file mode 100644 index 930e6f37..00000000 --- a/deeployer.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/thecodingmachine/deeployer/master/deeployer.schema.json", - "containers": { - "back": { - "image": "thecodingmachine/workadventure-back:cd", - "host": "api.workadventure.test.thecodingmachine.com", - "ports": [8080], - "env": { - "SECRET_KEY": "tempSecretKeyNeedsToChange" - } - }, - "front": { - "image": "thecodingmachine/workadventure-front:cd", - "host": "workadventure.test.thecodingmachine.com", - "ports": [80], - "env": { - "API_URL": "http://api.workadventure.test.thecodingmachine.com" - } - } - } -} diff --git a/deeployer.libsonnet b/deeployer.libsonnet new file mode 100644 index 00000000..60c5d470 --- /dev/null +++ b/deeployer.libsonnet @@ -0,0 +1,24 @@ +{ + local env = std.extVar("env"), + # FIXME: namespace does not work if the branch contains a "/" + local namespace = std.split(env.GITHUB_REF, "/")[2] + "$schema": "https://raw.githubusercontent.com/thecodingmachine/deeployer/master/deeployer.schema.json", + "containers": { + "back": { + "image": "thecodingmachine/workadventure-back:"+namespace, + "host": "api."+namespace+".workadventure.test.thecodingmachine.com", + "ports": [8080], + "env": { + "SECRET_KEY": "tempSecretKeyNeedsToChange" + } + }, + "front": { + "image": "thecodingmachine/workadventure-front:"+namespace, + "host": namespace+".workadventure.test.thecodingmachine.com", + "ports": [80], + "env": { + "API_URL": "http://api."+namespace+".workadventure.test.thecodingmachine.com" + } + } + } +} From b0c347b41b6904d35bebfd9dd3283eadd424522d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 13 Apr 2020 15:08:36 +0200 Subject: [PATCH 2/9] Triggering build and deploy on every branch --- .github/workflows/build-and-deploy.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 607e6ae7..7425cb48 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -1,12 +1,7 @@ name: Build, push and deploy Docker image on: - push: - branches: - - master - - cd -# tags: -# - '*' + - push # Enables BuildKit env: From d5195385316031f647c04676987b2b5b2a72462e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 13 Apr 2020 15:14:16 +0200 Subject: [PATCH 3/9] Fixing libsonnet and changing deployment namespace --- .github/workflows/build-and-deploy.yml | 3 +-- deeployer.libsonnet | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 7425cb48..1dd48da8 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -63,6 +63,5 @@ jobs: uses: thecodingmachine/deeployer@master env: KUBE_CONFIG_FILE: ${{ secrets.KUBE_CONFIG_FILE }} - AUTOCONNECT: 1 with: - namespace: workadventure-master + namespace: workadventure-${GITHUB_REF##*/} diff --git a/deeployer.libsonnet b/deeployer.libsonnet index 60c5d470..51c55580 100644 --- a/deeployer.libsonnet +++ b/deeployer.libsonnet @@ -1,11 +1,11 @@ { local env = std.extVar("env"), # FIXME: namespace does not work if the branch contains a "/" - local namespace = std.split(env.GITHUB_REF, "/")[2] + local namespace = std.split(env.GITHUB_REF, "/")[2], "$schema": "https://raw.githubusercontent.com/thecodingmachine/deeployer/master/deeployer.schema.json", "containers": { "back": { - "image": "thecodingmachine/workadventure-back:"+namespace, + "image": "thecodingmachine/workadventure-back:"+(if namespace == "master" then "latest" else namespace), "host": "api."+namespace+".workadventure.test.thecodingmachine.com", "ports": [8080], "env": { @@ -13,7 +13,7 @@ } }, "front": { - "image": "thecodingmachine/workadventure-front:"+namespace, + "image": "thecodingmachine/workadventure-front:"+(if namespace == "master" then "latest" else namespace), "host": namespace+".workadventure.test.thecodingmachine.com", "ports": [80], "env": { From 0ba6941cd201ce617d63d1cee194d4c4105c5f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 13 Apr 2020 15:44:33 +0200 Subject: [PATCH 4/9] Fixing ref slug --- .github/workflows/build-and-deploy.yml | 5 ++++- deeployer.libsonnet | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 1dd48da8..7c5ca664 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -59,9 +59,12 @@ jobs: - name: Checkout uses: actions/checkout@v2 + # Create a slugified value of the branch + - uses: rlespinasse/github-slug-action@master + - name: Deploy uses: thecodingmachine/deeployer@master env: KUBE_CONFIG_FILE: ${{ secrets.KUBE_CONFIG_FILE }} with: - namespace: workadventure-${GITHUB_REF##*/} + namespace: workadventure-${{GITHUB_REF_SLUG}} diff --git a/deeployer.libsonnet b/deeployer.libsonnet index 51c55580..599012c4 100644 --- a/deeployer.libsonnet +++ b/deeployer.libsonnet @@ -1,11 +1,12 @@ { local env = std.extVar("env"), # FIXME: namespace does not work if the branch contains a "/" - local namespace = std.split(env.GITHUB_REF, "/")[2], + local namespace = env.GITHUB_REF_SLUG, + local tag = if namespace == "master" then "latest" else namespace, "$schema": "https://raw.githubusercontent.com/thecodingmachine/deeployer/master/deeployer.schema.json", "containers": { "back": { - "image": "thecodingmachine/workadventure-back:"+(if namespace == "master" then "latest" else namespace), + "image": "thecodingmachine/workadventure-back:"+tag, "host": "api."+namespace+".workadventure.test.thecodingmachine.com", "ports": [8080], "env": { @@ -13,7 +14,7 @@ } }, "front": { - "image": "thecodingmachine/workadventure-front:"+(if namespace == "master" then "latest" else namespace), + "image": "thecodingmachine/workadventure-front:"+tag, "host": namespace+".workadventure.test.thecodingmachine.com", "ports": [80], "env": { From efccdcbb06001b59286976ef4df5931ffc1dbb65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 13 Apr 2020 15:45:35 +0200 Subject: [PATCH 5/9] Fixing action --- .github/workflows/build-and-deploy.yml | 2 +- deeployer.libsonnet | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 7c5ca664..297c8405 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -67,4 +67,4 @@ jobs: env: KUBE_CONFIG_FILE: ${{ secrets.KUBE_CONFIG_FILE }} with: - namespace: workadventure-${{GITHUB_REF_SLUG}} + namespace: workadventure-${{ env.GITHUB_REF_SLUG }} diff --git a/deeployer.libsonnet b/deeployer.libsonnet index 599012c4..4e44db34 100644 --- a/deeployer.libsonnet +++ b/deeployer.libsonnet @@ -1,6 +1,5 @@ { local env = std.extVar("env"), - # FIXME: namespace does not work if the branch contains a "/" local namespace = env.GITHUB_REF_SLUG, local tag = if namespace == "master" then "latest" else namespace, "$schema": "https://raw.githubusercontent.com/thecodingmachine/deeployer/master/deeployer.schema.json", From 62e28bed1097d352a62d3fdbe196a1534c3f6eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 13 Apr 2020 18:15:27 +0200 Subject: [PATCH 6/9] Fixing slugify issue --- .github/workflows/build-and-deploy.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 297c8405..f2608367 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -18,6 +18,10 @@ jobs: - name: Checkout uses: actions/checkout@v2 + + # Create a slugified value of the branch + - uses: rlespinasse/github-slug-action@master + - name: "Build and push front image" uses: docker/build-push-action@v1 with: @@ -26,7 +30,7 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} repository: thecodingmachine/workadventure-front - tag_with_ref: true + tags: ${{ env.GITHUB_REF_SLUG }} add_git_labels: true build-back: @@ -38,6 +42,9 @@ jobs: - name: Checkout uses: actions/checkout@v2 + # Create a slugified value of the branch + - uses: rlespinasse/github-slug-action@master + - name: "Build and push back image" uses: docker/build-push-action@v1 with: @@ -46,7 +53,7 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} repository: thecodingmachine/workadventure-back - tag_with_ref: true + tags: ${{ env.GITHUB_REF_SLUG }} add_git_labels: true deeploy: From 226fbb1e9e482eb3216a8e930d3ebc003a7b62a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 13 Apr 2020 18:30:22 +0200 Subject: [PATCH 7/9] Adding a message with deployment location at the end of deployment --- .github/workflows/build-and-deploy.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index f2608367..ca8e5c02 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -75,3 +75,11 @@ jobs: KUBE_CONFIG_FILE: ${{ secrets.KUBE_CONFIG_FILE }} with: namespace: workadventure-${{ env.GITHUB_REF_SLUG }} + + - name: Add a comment in PR + uses: unsplash/comment-on-pr@1.2.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + msg: Environment deployed at http://${{ env.GITHUB_REF_SLUG }}.workadventure.test.thecodingmachine.com + check_for_duplicate_msg: true From 3a788b7c15c7d2087540ecbc122d421c3783c6ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 13 Apr 2020 18:33:27 +0200 Subject: [PATCH 8/9] Fixing version --- .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 ca8e5c02..ae11e07f 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -77,7 +77,7 @@ jobs: namespace: workadventure-${{ env.GITHUB_REF_SLUG }} - name: Add a comment in PR - uses: unsplash/comment-on-pr@1.2.0 + uses: unsplash/comment-on-pr@v1.2.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: From 6bf7a3eb437cb5e350b857288f5f8db042e0bb2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 13 Apr 2020 18:34:13 +0200 Subject: [PATCH 9/9] Using tagged version for rlespinasse/github-slug-action --- .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 ae11e07f..2b003230 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -67,7 +67,7 @@ jobs: uses: actions/checkout@v2 # Create a slugified value of the branch - - uses: rlespinasse/github-slug-action@master + - uses: rlespinasse/github-slug-action@1.1.0 - name: Deploy uses: thecodingmachine/deeployer@master