From 9c757a01aa5050059d6ec34d3a313d64d2dfe767 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 3 Aug 2023 18:36:19 +0300 Subject: [PATCH 01/12] fix: do not deploy without a manual trigger This will fix automatic first deployment --- .github/workflows/pr-deploy.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 3202326b919dc..956d0ff6157ff 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -154,7 +154,7 @@ jobs: needs: get_info # Skips the build job if the workflow was triggered by a workflow_dispatch event and the skip_build input is set to true # or if the workflow was triggered by an issue_comment event and the comment body contains --skip-build - # alwyas run the build job if the workflow was triggered by a pull_request event + # always run the build job if a pull_request event triggered the workflow if: | (github.event_name == 'workflow_dispatch' && github.event.inputs.skip_build == 'false') || (github.event_name == 'pull_request' && needs.get_info.outputs.NEW == 'false') @@ -211,7 +211,8 @@ jobs: deploy: needs: [build, get_info] # Run deploy job only if build job was successful or skipped - if: always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && needs.get_info.result == 'success' + if: | + always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && needs.get_info.outputs.NEW == 'false' runs-on: "ubuntu-latest" env: CODER_IMAGE_TAG: ${{ needs.get_info.outputs.CODER_IMAGE_TAG }} From 9e7cd5723e0d2feadb1e51884e8a44f7646207ff Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 3 Aug 2023 18:40:11 +0300 Subject: [PATCH 02/12] fix typo --- .github/workflows/pr-cleanup.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml index 1ec7e4a73154f..510c8f4299361 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -70,4 +70,4 @@ jobs: if: ${{ github.event.pull_request.merged == true }} run: | set -euxo pipefail - kuebctl delete certificate "pr${{ steps.pr_number.outputs.PR_NUMBER }}-tls" -n pr-deployment-certs || echo "certificate not found" + kubectl delete certificate "pr${{ steps.pr_number.outputs.PR_NUMBER }}-tls" -n pr-deployment-certs || echo "certificate not found" From c071059ac1c59b3edf2709ed0d27674e613b296b Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 3 Aug 2023 18:53:12 +0300 Subject: [PATCH 03/12] Update pr-deploy.yaml --- .github/workflows/pr-deploy.yaml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 956d0ff6157ff..59ce85fc97488 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -99,10 +99,11 @@ jobs: issue-number: ${{ steps.pr_info.outputs.PR_NUMBER }} comment-author: "github-actions[bot]" body-includes: ":rocket:" - direction: last - + direction: last + - name: Comment on PR id: comment_id + if: github.event_name == 'workflow_dispatch' || steps.check_deployment.outputs.NEW == 'false' uses: peter-evans/create-or-update-comment@v3 with: comment-id: ${{ steps.fc.outputs.comment-id }} @@ -116,12 +117,14 @@ jobs: reactions-edit-mode: replace - name: Checkout + if: github.event_name == 'workflow_dispatch' || steps.check_deployment.outputs.NEW == 'false' uses: actions/checkout@v3 with: ref: ${{ steps.pr_info.outputs.PR_BRANCH }} fetch-depth: 0 - name: Check changed files + if: github.event_name == 'workflow_dispatch' || steps.check_deployment.outputs.NEW == 'false' uses: dorny/paths-filter@v2 id: filter with: @@ -145,6 +148,7 @@ jobs: - "scripts/**/*[^D][^o][^c][^k][^e][^r][^f][^i][^l][^e][.][b][^a][^s][^e]*" - name: Print number of changed files + if: github.event_name == 'workflow_dispatch' || steps.check_deployment.outputs.NEW == 'false' run: | set -euxo pipefail echo "Total number of changed files: ${{ steps.filter.outputs.all_count }}" @@ -157,7 +161,7 @@ jobs: # always run the build job if a pull_request event triggered the workflow if: | (github.event_name == 'workflow_dispatch' && github.event.inputs.skip_build == 'false') || - (github.event_name == 'pull_request' && needs.get_info.outputs.NEW == 'false') + (github.event_name == 'pull_request' && needs.get_info.result == 'success' && needs.get_info.outputs.NEW == 'false') runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }} env: DOCKER_CLI_EXPERIMENTAL: "enabled" From 2285dfe8251b82cddbdba3db43416357579acab8 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 3 Aug 2023 18:54:19 +0300 Subject: [PATCH 04/12] Update pr-deploy.yaml --- .github/workflows/pr-deploy.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 59ce85fc97488..fa4cf2fd7a58e 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -94,6 +94,7 @@ jobs: - name: Find Comment uses: peter-evans/find-comment@v2 + if: github.event_name == 'workflow_dispatch' || steps.check_deployment.outputs.NEW == 'false' id: fc with: issue-number: ${{ steps.pr_info.outputs.PR_NUMBER }} From 618574ccda7e7e2f474661ae64fc78d2e3c9b7d0 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 3 Aug 2023 18:54:58 +0300 Subject: [PATCH 05/12] Update pr-deploy.yaml --- .github/workflows/pr-deploy.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index fa4cf2fd7a58e..c7ec273d209b6 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -100,8 +100,8 @@ jobs: issue-number: ${{ steps.pr_info.outputs.PR_NUMBER }} comment-author: "github-actions[bot]" body-includes: ":rocket:" - direction: last - + direction: last + - name: Comment on PR id: comment_id if: github.event_name == 'workflow_dispatch' || steps.check_deployment.outputs.NEW == 'false' From 9cb947a1c8b6eca1aee59ef50acfc9e1916f16ff Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 3 Aug 2023 18:55:53 +0300 Subject: [PATCH 06/12] Update pr-deploy.yaml --- .github/workflows/pr-deploy.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index c7ec273d209b6..ab1f940ec967a 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -216,8 +216,7 @@ jobs: deploy: needs: [build, get_info] # Run deploy job only if build job was successful or skipped - if: | - always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && needs.get_info.outputs.NEW == 'false' + if: always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && needs.get_info.outputs.NEW == 'false' runs-on: "ubuntu-latest" env: CODER_IMAGE_TAG: ${{ needs.get_info.outputs.CODER_IMAGE_TAG }} From fc4e495f64c3acd42ec4f4cdf6c00b1563ce4aa7 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 3 Aug 2023 18:57:52 +0300 Subject: [PATCH 07/12] Update pr-deploy.yaml --- .github/workflows/pr-deploy.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index ab1f940ec967a..ee4c252d83451 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -216,7 +216,9 @@ jobs: deploy: needs: [build, get_info] # Run deploy job only if build job was successful or skipped - if: always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && needs.get_info.outputs.NEW == 'false' + if: | + always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && + (github.event_name == 'workflow_dispatch' || steps.check_deployment.outputs.NEW == 'false') runs-on: "ubuntu-latest" env: CODER_IMAGE_TAG: ${{ needs.get_info.outputs.CODER_IMAGE_TAG }} From c632da6457eb5b13ebefbf446ded0dce0169b152 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 3 Aug 2023 19:00:37 +0300 Subject: [PATCH 08/12] Update pr-deploy.yaml --- .github/workflows/pr-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index ee4c252d83451..fc01231dfd059 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -218,7 +218,7 @@ jobs: # Run deploy job only if build job was successful or skipped if: | always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && - (github.event_name == 'workflow_dispatch' || steps.check_deployment.outputs.NEW == 'false') + (github.event_name == 'workflow_dispatch' || needs.get_info.outputs.NEW == 'false') runs-on: "ubuntu-latest" env: CODER_IMAGE_TAG: ${{ needs.get_info.outputs.CODER_IMAGE_TAG }} From 6a448a5352f54fae7518849abbbe47cbff0e31fc Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 3 Aug 2023 19:01:58 +0300 Subject: [PATCH 09/12] Update pr-deploy.yaml --- .github/workflows/pr-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index fc01231dfd059..8b1100ca7321d 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -87,7 +87,7 @@ jobs: echo "Deployment already exists. Skipping deployment." new=false else - echo "Deployment doesn't exist. Creating a new one." + echo "Deployment doesn't exist." new=true fi echo "new=$new" >> $GITHUB_OUTPUT From 400b5ff9fa057914139dcf47cdd40f44c0719078 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 3 Aug 2023 19:07:31 +0300 Subject: [PATCH 10/12] build at least once --- .github/workflows/pr-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 8b1100ca7321d..dd3c8f5b291cf 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -46,7 +46,7 @@ jobs: CODER_BASE_IMAGE_TAG: ${{ steps.set_tags.outputs.CODER_BASE_IMAGE_TAG }} CODER_IMAGE_TAG: ${{ steps.set_tags.outputs.CODER_IMAGE_TAG }} NEW: ${{ steps.check_deployment.outputs.new }} - BUILD: ${{ steps.filter.outputs.all_count > steps.filter.outputs.ignored_count }} + BUILD: ${{ steps.filter.outputs.all_count > steps.filter.outputs.ignored_count || steps.check_deployment.outputs.new }} runs-on: "ubuntu-latest" steps: From 6ee650a128ebc564c9e47cb290e7cc78a4ab2581 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 3 Aug 2023 19:19:10 +0300 Subject: [PATCH 11/12] wait for certificate --- .github/workflows/pr-deploy.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index dd3c8f5b291cf..cde3141bbe6f0 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -294,12 +294,17 @@ jobs: echo "Certificate exists. Skipping certificate creation." fi echo "Copy certificate from pr-deployment-certs to pr${{ env.PR_NUMBER }} namespace" + until kubectl get secret pr${{ env.PR_NUMBER }}-tls -n pr-deployment-certs &> /dev/null + do + echo "Waiting for secret pr${{ env.PR_NUMBER }}-tls to be created..." + sleep 5 + done ( kubectl get secret pr${{ env.PR_NUMBER }}-tls -n pr-deployment-certs -o json | jq 'del(.metadata.namespace,.metadata.creationTimestamp,.metadata.resourceVersion,.metadata.selfLink,.metadata.uid,.metadata.managedFields)' | kubectl -n pr${{ env.PR_NUMBER }} apply -f - ) - + - name: Set up PostgreSQL database if: needs.get_info.outputs.NEW == 'true' run: | From 42a153b340e50843f7dc2f2d847a866f19a49e7d Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 3 Aug 2023 19:21:37 +0300 Subject: [PATCH 12/12] Update pr-deploy.yaml --- .github/workflows/pr-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index cde3141bbe6f0..adc0e2d25c376 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -304,7 +304,7 @@ jobs: jq 'del(.metadata.namespace,.metadata.creationTimestamp,.metadata.resourceVersion,.metadata.selfLink,.metadata.uid,.metadata.managedFields)' | kubectl -n pr${{ env.PR_NUMBER }} apply -f - ) - + - name: Set up PostgreSQL database if: needs.get_info.outputs.NEW == 'true' run: |