From 702f54c795109665c090cec0beed3454e73760da Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 21 Jun 2023 10:17:43 +0300 Subject: [PATCH 001/103] add actions --- .github/deploy.yml | 15 ++++++ .github/workflows/deploy.yaml | 91 ++++++++++++++++++++++++++++++++ .github/workflows/prcleanup.yaml | 13 +++++ 3 files changed, 119 insertions(+) create mode 100644 .github/deploy.yml create mode 100644 .github/workflows/deploy.yaml create mode 100644 .github/workflows/prcleanup.yaml diff --git a/.github/deploy.yml b/.github/deploy.yml new file mode 100644 index 0000000000000..259aaac077096 --- /dev/null +++ b/.github/deploy.yml @@ -0,0 +1,15 @@ +# Review environments can be triggered with "/deploy review" inside a pull request. +review: + transient_environment: true + production_environment: false + required_contexts: ["build-coder-preview"] + environment: pr${{ pr }} + description: 'Review' + payload: + release: coder-pr${{ pr }} + namespace: coder-pr${{ pr }} + track: stable + values: + image: + repo: ghcr.io/coder/coder-preview + tag: pr${{ pr }} diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000000000..dd01d25ae4267 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,91 @@ +# .github/workflows/deploy.yml +name: Deploy PR +on: + deployment: + pull_request: + types: ready_for_review + workflow_dispatch: + +env: + # This is the version of the release. It is used to tag the Docker images. + CODER_BASE_IMAGE_TAG: ghcr.io/coder/coder-preview-base:pr${{ github.event.pull_request.number }} + CODER_IMAGE_TAG: ghcr.io/coder/coder-preview:pr${{ github.event.pull_request.number }} + PR_NUMBER: ${{ github.event.pull_request.number }} + +permissions: + packages: write + +jobs: + build: + runs-on: ubuntu-latest + env: + # Necessary for Docker manifest + DOCKER_CLI_EXPERIMENTAL: "enabled" + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: GHCR Login + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create empty base-build-context directory + run: mkdir base-build-context + + - name: Install depot.dev CLI + uses: depot/setup-action@v1 + + # This uses OIDC authentication, so no auth variables are required. + - name: Build base Docker image via depot.dev + uses: depot/build-push-action@v1 + with: + project: wl5hnrrkns + context: base-build-context + file: scripts/Dockerfile.base + platforms: linux/amd64 + pull: true + no-cache: true + push: true + tags: ${{ env.CODER_BASE_IMAGE_TAG }} + + - name: Build Linux amd64 Docker image + run: | + set -euxo pipefail + + # build Docker image + make -j build/coder_${{ env.PR_NUMBER }}_linux_amd64.tag --target ${{ env.CODER_IMAGE_TAG }} + + # push manifest + make -j push/coder_${{ env.PR_NUMBER }}_linux_amd64.tag + env: + CODER_BASE_IMAGE_TAG: ${{ env.CODER_BASE_IMAGE_TAG }} + + + deployment: + needs: build + if: needs.build.result == 'success' + runs-on: "ubuntu-latest" + steps: + - uses: actions/checkout@v3 + + - name: "Create PR namespace" + run: | + set -euxo pipefail + kubectl create namespace "pr${{ env.PR_NUMBER }}" + + - name: "Deploy" + uses: "deliverybot/helm@v1" + with: + release: "pr${{ env.PR_NUMBER }}" + namespace: "pr${{ env.PR_NUMBER }}" + version: "{{ github.sha }}" + chart: "./helm" + token: "${{ secrets.GITHUB_TOKEN }}" + values: | + name: foobar + env: + KUBECONFIG_FILE: "${{ secrets.DELIVERYBOT_KUBECONFIG }}" diff --git a/.github/workflows/prcleanup.yaml b/.github/workflows/prcleanup.yaml new file mode 100644 index 0000000000000..8bbb1cdc67c93 --- /dev/null +++ b/.github/workflows/prcleanup.yaml @@ -0,0 +1,13 @@ +# .github/workflows/pr-cleanup.yml +name: PRCleanup +on: + pull_request: + types: [closed] + +jobs: + pr-close: + runs-on: "ubuntu-latest" + steps: + - name: "Remove PR namespace" + run: | + kubectl delete namespace "pr${{ github.event.pull_request.number }}" From f5f9d1621348b76933f3e4108056e1fd4c54715a Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 21 Jun 2023 10:22:18 +0300 Subject: [PATCH 002/103] rename namespace and release --- .github/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/deploy.yml b/.github/deploy.yml index 259aaac077096..7b0b0720e90a5 100644 --- a/.github/deploy.yml +++ b/.github/deploy.yml @@ -6,8 +6,8 @@ review: environment: pr${{ pr }} description: 'Review' payload: - release: coder-pr${{ pr }} - namespace: coder-pr${{ pr }} + release: pr${{ pr }} + namespace: pr${{ pr }} track: stable values: image: From e9a7b8dc764df22a66580e6dd0c9c6e0f7b74a94 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 21 Jun 2023 10:22:33 +0300 Subject: [PATCH 003/103] specify kubeconfig --- .github/workflows/deploy.yaml | 2 +- .github/workflows/prcleanup.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index dd01d25ae4267..fabe3c512d465 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -75,7 +75,7 @@ jobs: - name: "Create PR namespace" run: | set -euxo pipefail - kubectl create namespace "pr${{ env.PR_NUMBER }}" + kubectl create namespace "pr${{ env.PR_NUMBER }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" - name: "Deploy" uses: "deliverybot/helm@v1" diff --git a/.github/workflows/prcleanup.yaml b/.github/workflows/prcleanup.yaml index 8bbb1cdc67c93..75e89e3eeb659 100644 --- a/.github/workflows/prcleanup.yaml +++ b/.github/workflows/prcleanup.yaml @@ -10,4 +10,4 @@ jobs: steps: - name: "Remove PR namespace" run: | - kubectl delete namespace "pr${{ github.event.pull_request.number }}" + kubectl delete namespace "pr${{ github.event.pull_request.number }}" --kubeconfig "${{ secrets.KUBECONFIG }}" From 1f09be4ef32071643461bee6e69564bed127a99b Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 07:36:36 +0000 Subject: [PATCH 004/103] fix --- .github/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/deploy.yml b/.github/deploy.yml index 7b0b0720e90a5..5d3329e136e87 100644 --- a/.github/deploy.yml +++ b/.github/deploy.yml @@ -2,7 +2,7 @@ review: transient_environment: true production_environment: false - required_contexts: ["build-coder-preview"] + required_contexts: ["ci"] environment: pr${{ pr }} description: 'Review' payload: From 69ab48260b4c122ddd894e2f85d06708925a3ae2 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 07:37:06 +0000 Subject: [PATCH 005/103] make fmt --- .github/deploy.yml | 2 +- .github/workflows/deploy.yaml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/deploy.yml b/.github/deploy.yml index 5d3329e136e87..017c3bf821ce8 100644 --- a/.github/deploy.yml +++ b/.github/deploy.yml @@ -4,7 +4,7 @@ review: production_environment: false required_contexts: ["ci"] environment: pr${{ pr }} - description: 'Review' + description: "Review" payload: release: pr${{ pr }} namespace: pr${{ pr }} diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index fabe3c512d465..50e63af92cb1b 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -64,7 +64,6 @@ jobs: env: CODER_BASE_IMAGE_TAG: ${{ env.CODER_BASE_IMAGE_TAG }} - deployment: needs: build if: needs.build.result == 'success' From e999ee3c1491b1d25f44bb957010702f99fbb57c Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 07:42:54 +0000 Subject: [PATCH 006/103] run on push --- .github/workflows/deploy.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 50e63af92cb1b..64792e1672120 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -5,6 +5,8 @@ on: pull_request: types: ready_for_review workflow_dispatch: + push: + branches-ignore: main env: # This is the version of the release. It is used to tag the Docker images. From 5ac17ab1605bbc446f9444e100db5c69dfb03c36 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 07:43:38 +0000 Subject: [PATCH 007/103] test --- .github/workflows/deploy.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 64792e1672120..27c850d0f3981 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -2,11 +2,11 @@ name: Deploy PR on: deployment: - pull_request: - types: ready_for_review - workflow_dispatch: - push: - branches-ignore: main + # pull_request: + # types: ready_for_review + # workflow_dispatch: + # push: + # branches-ignore: main env: # This is the version of the release. It is used to tag the Docker images. From daeb57eee359a7bee97596cddc796e0dd4db73bf Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 07:52:27 +0000 Subject: [PATCH 008/103] use docker/actions to build --- .github/workflows/deploy.yaml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 27c850d0f3981..3aece62f3c238 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -39,18 +39,14 @@ jobs: run: mkdir base-build-context - name: Install depot.dev CLI - uses: depot/setup-action@v1 + uses: docker/setup-buildx-action@v2 - # This uses OIDC authentication, so no auth variables are required. - name: Build base Docker image via depot.dev - uses: depot/build-push-action@v1 + uses: docker/build-push-action@v4 with: - project: wl5hnrrkns context: base-build-context file: scripts/Dockerfile.base platforms: linux/amd64 - pull: true - no-cache: true push: true tags: ${{ env.CODER_BASE_IMAGE_TAG }} @@ -59,10 +55,10 @@ jobs: set -euxo pipefail # build Docker image - make -j build/coder_${{ env.PR_NUMBER }}_linux_amd64.tag --target ${{ env.CODER_IMAGE_TAG }} + docker buildx build --platform linux/amd64 -t ${{ env.CODER_IMAGE_TAG }} . # push manifest - make -j push/coder_${{ env.PR_NUMBER }}_linux_amd64.tag + docker buildx build --platform linux/amd64 --push -t ${{ env.CODER_IMAGE_TAG }} . env: CODER_BASE_IMAGE_TAG: ${{ env.CODER_BASE_IMAGE_TAG }} From fa54ba1bb57803d888edf2d98156159533806bcf Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 07:52:52 +0000 Subject: [PATCH 009/103] add triggers for testing --- .github/workflows/deploy.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 3aece62f3c238..4aa29bd0ab99e 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -4,9 +4,9 @@ on: deployment: # pull_request: # types: ready_for_review - # workflow_dispatch: - # push: - # branches-ignore: main + workflow_dispatch: + push: + branches-ignore: main env: # This is the version of the release. It is used to tag the Docker images. From 4ef28b519de7058a1ca4b21bc46fbdebd71be070 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 07:57:34 +0000 Subject: [PATCH 010/103] add trigger --- .github/workflows/deploy.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 4aa29bd0ab99e..3af83bc6a556f 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -2,7 +2,8 @@ name: Deploy PR on: deployment: - # pull_request: + pull_request: + types: [opened, synchronize, ready_for_review] # types: ready_for_review workflow_dispatch: push: @@ -38,9 +39,6 @@ jobs: - name: Create empty base-build-context directory run: mkdir base-build-context - - name: Install depot.dev CLI - uses: docker/setup-buildx-action@v2 - - name: Build base Docker image via depot.dev uses: docker/build-push-action@v4 with: From b0f836df549a1f3e79b68769907e009782e88c18 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 08:04:11 +0000 Subject: [PATCH 011/103] skip tests --- .github/workflows/ci.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6ad6f4e27d82b..14321ed2b7464 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -34,7 +34,8 @@ jobs: go: ${{ steps.filter.outputs.go }} ts: ${{ steps.filter.outputs.ts }} k8s: ${{ steps.filter.outputs.k8s }} - ci: ${{ steps.filter.outputs.ci }} + # ci: ${{ steps.filter.outputs.ci }} + ci: false # TODO: remove this before merging steps: - uses: actions/checkout@v3 # For pull requests it's not necessary to checkout the code From 639066a2a64a310b9499f0189d2f9238de0f7703 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 08:18:58 +0000 Subject: [PATCH 012/103] fix --- .github/workflows/deploy.yaml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 3af83bc6a556f..ab95c5d8c329e 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -51,14 +51,8 @@ jobs: - name: Build Linux amd64 Docker image run: | set -euxo pipefail - - # build Docker image - docker buildx build --platform linux/amd64 -t ${{ env.CODER_IMAGE_TAG }} . - - # push manifest - docker buildx build --platform linux/amd64 --push -t ${{ env.CODER_IMAGE_TAG }} . - env: - CODER_BASE_IMAGE_TAG: ${{ env.CODER_BASE_IMAGE_TAG }} + make -j build/coder_${{ env.PR_NUMBER }}_linux_amd64.tag --target ${{ env.CODER_IMAGE_TAG }} + make -j push/build/coder_${{ env.PR_NUMBER }}_linux_amd64.tag deployment: needs: build From 90d7fa4100113a7640fb331ffcd2cdd3545a652a Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 08:19:50 +0000 Subject: [PATCH 013/103] fix fix --- .github/workflows/deploy.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index ab95c5d8c329e..a55091bc15040 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -53,6 +53,8 @@ jobs: set -euxo pipefail make -j build/coder_${{ env.PR_NUMBER }}_linux_amd64.tag --target ${{ env.CODER_IMAGE_TAG }} make -j push/build/coder_${{ env.PR_NUMBER }}_linux_amd64.tag + env: + CODER_BASE_IMAGE_TAG: ${{ env.CODER_BASE_IMAGE_TAG }} deployment: needs: build From 3e17ae4996e80f335ba7f3eaa431b593293634eb Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 08:24:16 +0000 Subject: [PATCH 014/103] skip gen and lint for testing --- .github/workflows/ci.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 14321ed2b7464..bd9607ae70d7d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -95,6 +95,8 @@ jobs: lint: runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }} + needs: changes + if : needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main' # TODO Remove this before merging steps: - name: Checkout uses: actions/checkout@v3 @@ -145,7 +147,8 @@ jobs: timeout-minutes: 8 runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }} needs: changes - if: needs.changes.outputs.docs-only == 'false' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main' + # if: needs.changes.outputs.docs-only == 'false' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main' + if : needs.changes.outputs.ci == 'true' # TODO Remove this before merging steps: - uses: actions/checkout@v3 From ed26c6a02e1b6cd256417eb0eaf59fdef9c0d6bc Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 08:33:51 +0000 Subject: [PATCH 015/103] remove version --- .github/workflows/deploy.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index a55091bc15040..980f58c9ecbdd 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -51,8 +51,8 @@ jobs: - name: Build Linux amd64 Docker image run: | set -euxo pipefail - make -j build/coder_${{ env.PR_NUMBER }}_linux_amd64.tag --target ${{ env.CODER_IMAGE_TAG }} - make -j push/build/coder_${{ env.PR_NUMBER }}_linux_amd64.tag + make -j build/coder_linux_amd64.tag --target ${{ env.CODER_IMAGE_TAG }} + make -j push/build/coder_linux_amd64.tag env: CODER_BASE_IMAGE_TAG: ${{ env.CODER_BASE_IMAGE_TAG }} From b7cc4054233fb6f74ed6d96c16e1e921a17ccd61 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 08:54:09 +0000 Subject: [PATCH 016/103] refactor --- .github/workflows/deploy.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 980f58c9ecbdd..f6f73591109da 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -13,7 +13,7 @@ env: # This is the version of the release. It is used to tag the Docker images. CODER_BASE_IMAGE_TAG: ghcr.io/coder/coder-preview-base:pr${{ github.event.pull_request.number }} CODER_IMAGE_TAG: ghcr.io/coder/coder-preview:pr${{ github.event.pull_request.number }} - PR_NUMBER: ${{ github.event.pull_request.number }} + VERSION: ${{ github.event.pull_request.number }} permissions: packages: write @@ -39,7 +39,7 @@ jobs: - name: Create empty base-build-context directory run: mkdir base-build-context - - name: Build base Docker image via depot.dev + - name: Build base Docker image uses: docker/build-push-action@v4 with: context: base-build-context @@ -51,10 +51,12 @@ jobs: - name: Build Linux amd64 Docker image run: | set -euxo pipefail - make -j build/coder_linux_amd64.tag --target ${{ env.CODER_IMAGE_TAG }} - make -j push/build/coder_linux_amd64.tag + make -j build/coder_linux_amd64 + ./build_docker.sh --arch amd64 --version ${{env.VERSION}} --target ${{env.CODER_IMAGE_TAG }} --push build/coder_linux_amd64 +# env: CODER_BASE_IMAGE_TAG: ${{ env.CODER_BASE_IMAGE_TAG }} + VERSION: ${{ env.VERSION }} deployment: needs: build From 8a06547b44e3b6707c3d81ab57df1199a0bb9cc3 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 08:55:00 +0000 Subject: [PATCH 017/103] remove pr trigger --- .github/workflows/deploy.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index f6f73591109da..299143e274e8f 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -2,8 +2,8 @@ name: Deploy PR on: deployment: - pull_request: - types: [opened, synchronize, ready_for_review] + # pull_request: + # types: [opened, synchronize, ready_for_review] # types: ready_for_review workflow_dispatch: push: From f2ebd7215ffc36a5b81dfbd6bd51cf543f2863b8 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 08:56:48 +0000 Subject: [PATCH 018/103] make fmt --- .github/workflows/ci.yaml | 4 ++-- .github/workflows/deploy.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bd9607ae70d7d..26b6c179fe6e7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -96,7 +96,7 @@ jobs: lint: runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }} needs: changes - if : needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main' # TODO Remove this before merging + if: needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main' # TODO Remove this before merging steps: - name: Checkout uses: actions/checkout@v3 @@ -148,7 +148,7 @@ jobs: runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }} needs: changes # if: needs.changes.outputs.docs-only == 'false' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main' - if : needs.changes.outputs.ci == 'true' # TODO Remove this before merging + if: needs.changes.outputs.ci == 'true' # TODO Remove this before merging steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 299143e274e8f..6998873dcfe81 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -53,7 +53,7 @@ jobs: set -euxo pipefail make -j build/coder_linux_amd64 ./build_docker.sh --arch amd64 --version ${{env.VERSION}} --target ${{env.CODER_IMAGE_TAG }} --push build/coder_linux_amd64 -# + # env: CODER_BASE_IMAGE_TAG: ${{ env.CODER_BASE_IMAGE_TAG }} VERSION: ${{ env.VERSION }} From c4b2fbb65db0d9be4b9074dff8efa177d0e61c7a Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 08:59:06 +0000 Subject: [PATCH 019/103] add pr trigger --- .github/workflows/deploy.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 6998873dcfe81..3d1a2a11e0ea9 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -2,12 +2,12 @@ name: Deploy PR on: deployment: - # pull_request: - # types: [opened, synchronize, ready_for_review] + pull_request: + types: [opened, synchronize, ready_for_review] # types: ready_for_review workflow_dispatch: - push: - branches-ignore: main + # push: + # branches-ignore: main env: # This is the version of the release. It is used to tag the Docker images. From b4b8b5f35c15b5dcd883a7750dc359ffbb927f6d Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 09:02:16 +0000 Subject: [PATCH 020/103] cleanup pr image --- .github/workflows/deploy.yaml | 6 +++--- .github/workflows/prcleanup.yaml | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 3d1a2a11e0ea9..eef0a74bd3363 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -68,13 +68,13 @@ jobs: - name: "Create PR namespace" run: | set -euxo pipefail - kubectl create namespace "pr${{ env.PR_NUMBER }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" + kubectl create namespace "pr${{ env.VERSION }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" - name: "Deploy" uses: "deliverybot/helm@v1" with: - release: "pr${{ env.PR_NUMBER }}" - namespace: "pr${{ env.PR_NUMBER }}" + release: "pr${{ env.VERSION }}" + namespace: "pr${{ env.VERSION }}" version: "{{ github.sha }}" chart: "./helm" token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/prcleanup.yaml b/.github/workflows/prcleanup.yaml index 75e89e3eeb659..cbd136e32b042 100644 --- a/.github/workflows/prcleanup.yaml +++ b/.github/workflows/prcleanup.yaml @@ -10,4 +10,14 @@ jobs: steps: - name: "Remove PR namespace" run: | - kubectl delete namespace "pr${{ github.event.pull_request.number }}" --kubeconfig "${{ secrets.KUBECONFIG }}" + kubectl delete namespace "pr${{ github.event.pull_request.number }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" + + - name: Delete image + uses: bots-house/ghcr-delete-image-action@v1.1.0 + with: + # NOTE: at now only orgs is supported + owner: bots-house + name: some-web-service + # NOTE: using Personal Access Token + token: ${{ secrets.GITHUB_TOKEN }} + tag: pr${{github.event.pull_request.number}} From e70aed2e4b51a1a2677c4813ecde6dd1d33727fa Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 09:05:00 +0000 Subject: [PATCH 021/103] prcleanup --- .github/workflows/prcleanup.yaml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/prcleanup.yaml b/.github/workflows/prcleanup.yaml index cbd136e32b042..d851e904408a1 100644 --- a/.github/workflows/prcleanup.yaml +++ b/.github/workflows/prcleanup.yaml @@ -4,6 +4,9 @@ on: pull_request: types: [closed] +permissions: + packages: write + jobs: pr-close: runs-on: "ubuntu-latest" @@ -12,12 +15,18 @@ jobs: run: | kubectl delete namespace "pr${{ github.event.pull_request.number }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" + - name: Delete base image + uses: bots-house/ghcr-delete-image-action@v1.1.0 + with: + owner: coder + name: coder-preview-base + token: ${{ secrets.GITHUB_TOKEN }} + tag: pr${{github.event.pull_request.number}} + - name: Delete image uses: bots-house/ghcr-delete-image-action@v1.1.0 with: - # NOTE: at now only orgs is supported - owner: bots-house - name: some-web-service - # NOTE: using Personal Access Token + owner: coder + name: coder-preview token: ${{ secrets.GITHUB_TOKEN }} tag: pr${{github.event.pull_request.number}} From a3e89208c0551115e4f47ebc4883b604d626c2d7 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 09:34:37 +0000 Subject: [PATCH 022/103] setup go and node --- .github/workflows/deploy.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index eef0a74bd3363..93edc5d9a83f3 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -28,6 +28,9 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 + - uses: ./.github/actions/setup-go + + - uses: ./.github/actions/setup-node - name: GHCR Login uses: docker/login-action@v2 From c182ff42a4fb23b5f93f271afe4f4ad3d0f76d1a Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 09:44:41 +0000 Subject: [PATCH 023/103] fix version --- .github/workflows/deploy.yaml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 93edc5d9a83f3..39552192f8605 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -13,7 +13,7 @@ env: # This is the version of the release. It is used to tag the Docker images. CODER_BASE_IMAGE_TAG: ghcr.io/coder/coder-preview-base:pr${{ github.event.pull_request.number }} CODER_IMAGE_TAG: ghcr.io/coder/coder-preview:pr${{ github.event.pull_request.number }} - VERSION: ${{ github.event.pull_request.number }} + PR_NUMBER: ${{ github.event.pull_request.number }} permissions: packages: write @@ -55,11 +55,10 @@ jobs: run: | set -euxo pipefail make -j build/coder_linux_amd64 - ./build_docker.sh --arch amd64 --version ${{env.VERSION}} --target ${{env.CODER_IMAGE_TAG }} --push build/coder_linux_amd64 + ./scripts/build_docker.sh --arch amd64 --target ${{env.CODER_IMAGE_TAG }} --push build/coder_linux_amd64 # env: CODER_BASE_IMAGE_TAG: ${{ env.CODER_BASE_IMAGE_TAG }} - VERSION: ${{ env.VERSION }} deployment: needs: build @@ -71,13 +70,13 @@ jobs: - name: "Create PR namespace" run: | set -euxo pipefail - kubectl create namespace "pr${{ env.VERSION }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" + kubectl create namespace "pr${{ env.PR_NUMBER }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" - name: "Deploy" uses: "deliverybot/helm@v1" with: - release: "pr${{ env.VERSION }}" - namespace: "pr${{ env.VERSION }}" + release: "pr${{ env.PR_NUMBER }}" + namespace: "pr${{ env.PR_NUMBER }}" version: "{{ github.sha }}" chart: "./helm" token: "${{ secrets.GITHUB_TOKEN }}" From f9f5a8d9baadc559b8eb37e0693686f3b0cc1b0f Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 09:58:00 +0000 Subject: [PATCH 024/103] gix build path --- .github/workflows/deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 39552192f8605..c4496d39c2d59 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -55,7 +55,7 @@ jobs: run: | set -euxo pipefail make -j build/coder_linux_amd64 - ./scripts/build_docker.sh --arch amd64 --target ${{env.CODER_IMAGE_TAG }} --push build/coder_linux_amd64 + ./scripts/build_docker.sh --arch amd64 --target ${{env.CODER_IMAGE_TAG }} --push build/coder_*_linux_amd64 # env: CODER_BASE_IMAGE_TAG: ${{ env.CODER_BASE_IMAGE_TAG }} From dcef76539925b4956658b2711af68efcae2a21ae Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 10:29:04 +0000 Subject: [PATCH 025/103] use buildjet --- .github/workflows/deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index c4496d39c2d59..4cdf1c62f0f64 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -20,7 +20,7 @@ permissions: jobs: build: - runs-on: ubuntu-latest + runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }} env: # Necessary for Docker manifest DOCKER_CLI_EXPERIMENTAL: "enabled" From aee27e51e9235b4d6871299db82a355b6b7fc59f Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 10:37:49 +0000 Subject: [PATCH 026/103] set concurrency --- .github/workflows/deploy.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 4cdf1c62f0f64..f35bc2e667392 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -18,6 +18,10 @@ env: permissions: packages: write +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + jobs: build: runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }} @@ -42,7 +46,7 @@ jobs: - name: Create empty base-build-context directory run: mkdir base-build-context - - name: Build base Docker image + - name: Build and push base Docker image uses: docker/build-push-action@v4 with: context: base-build-context @@ -51,7 +55,7 @@ jobs: push: true tags: ${{ env.CODER_BASE_IMAGE_TAG }} - - name: Build Linux amd64 Docker image + - name: Build and push Linux amd64 Docker image run: | set -euxo pipefail make -j build/coder_linux_amd64 From 1cbc692ea32ca46318a16ee16b7581c6ee052d66 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 10:42:37 +0000 Subject: [PATCH 027/103] add workflow_dispatch to cleanup --- .github/workflows/deploy.yaml | 1 - .github/workflows/prcleanup.yaml | 14 +++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index f35bc2e667392..776a54fbaab21 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -4,7 +4,6 @@ on: deployment: pull_request: types: [opened, synchronize, ready_for_review] - # types: ready_for_review workflow_dispatch: # push: # branches-ignore: main diff --git a/.github/workflows/prcleanup.yaml b/.github/workflows/prcleanup.yaml index d851e904408a1..019697860a571 100644 --- a/.github/workflows/prcleanup.yaml +++ b/.github/workflows/prcleanup.yaml @@ -3,6 +3,14 @@ name: PRCleanup on: pull_request: types: [closed] + workflow_dispatch: + inputs: + pr_number: + description: "PR number" + required: true + +env: + PR_NUMBER: if(${{ github.event_name == 'workflow_dispatch' }}, ${{ github.event.inputs.pr_number }}, ${{ github.event.pull_request.number }}) permissions: packages: write @@ -13,7 +21,7 @@ jobs: steps: - name: "Remove PR namespace" run: | - kubectl delete namespace "pr${{ github.event.pull_request.number }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" + kubectl delete namespace "pr${{ env.PR_NUMBER }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" - name: Delete base image uses: bots-house/ghcr-delete-image-action@v1.1.0 @@ -21,7 +29,7 @@ jobs: owner: coder name: coder-preview-base token: ${{ secrets.GITHUB_TOKEN }} - tag: pr${{github.event.pull_request.number}} + tag: pr${{ env.PR_NUMBER }} - name: Delete image uses: bots-house/ghcr-delete-image-action@v1.1.0 @@ -29,4 +37,4 @@ jobs: owner: coder name: coder-preview token: ${{ secrets.GITHUB_TOKEN }} - tag: pr${{github.event.pull_request.number}} + tag: pr${{ env.PR_NUMBER }} From ecb3e766bee94e71d4d99a53d4d232f3cf53653b Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 10:56:40 +0000 Subject: [PATCH 028/103] try changing permission --- .github/workflows/deploy.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 776a54fbaab21..4085c771cbb33 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -15,6 +15,7 @@ env: PR_NUMBER: ${{ github.event.pull_request.number }} permissions: + contents: read packages: write concurrency: From d8dfd59e78d8e9b5ff5e7bf4da632f46d75e823b Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 11:01:13 +0000 Subject: [PATCH 029/103] reorder steps --- .github/workflows/prcleanup.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/prcleanup.yaml b/.github/workflows/prcleanup.yaml index 019697860a571..a56a919578bbb 100644 --- a/.github/workflows/prcleanup.yaml +++ b/.github/workflows/prcleanup.yaml @@ -19,10 +19,6 @@ jobs: pr-close: runs-on: "ubuntu-latest" steps: - - name: "Remove PR namespace" - run: | - kubectl delete namespace "pr${{ env.PR_NUMBER }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" - - name: Delete base image uses: bots-house/ghcr-delete-image-action@v1.1.0 with: @@ -38,3 +34,7 @@ jobs: name: coder-preview token: ${{ secrets.GITHUB_TOKEN }} tag: pr${{ env.PR_NUMBER }} + + - name: "Remove PR namespace" + run: | + kubectl delete namespace "pr${{ env.PR_NUMBER }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" From 6d0d73db322d0422b734245f10f0e8e246abe9b4 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 11:01:42 +0000 Subject: [PATCH 030/103] install sqlc --- .github/workflows/deploy.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 4085c771cbb33..7042d9cd28b08 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -36,6 +36,10 @@ jobs: - uses: ./.github/actions/setup-node + - name: Install sqlc + run: | + curl -sSL https://github.com/kyleconroy/sqlc/releases/download/v1.18.0/sqlc_1.18.0_linux_amd64.tar.gz | sudo tar -C /usr/bin -xz sqlc + - name: GHCR Login uses: docker/login-action@v2 with: From 6233443f4125de60f29544c00ba3186fde8e5898 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 11:09:07 +0000 Subject: [PATCH 031/103] make gen --- .github/workflows/deploy.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 7042d9cd28b08..664cc8db48135 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -62,6 +62,8 @@ jobs: - name: Build and push Linux amd64 Docker image run: | set -euxo pipefail + go mod download + make gen/mark-fresh make -j build/coder_linux_amd64 ./scripts/build_docker.sh --arch amd64 --target ${{env.CODER_IMAGE_TAG }} --push build/coder_*_linux_amd64 # From 901e304d24ea85725ff4062f88d95f9f39003dfa Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 11:10:15 +0000 Subject: [PATCH 032/103] fix syntax --- .github/workflows/prcleanup.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/prcleanup.yaml b/.github/workflows/prcleanup.yaml index a56a919578bbb..9331074b0fd72 100644 --- a/.github/workflows/prcleanup.yaml +++ b/.github/workflows/prcleanup.yaml @@ -35,6 +35,6 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} tag: pr${{ env.PR_NUMBER }} - - name: "Remove PR namespace" - run: | + - name: "Remove PR namespace" + run: | kubectl delete namespace "pr${{ env.PR_NUMBER }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" From 49d47956ec64ab10fb3d728b95a8d67ac9266835 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 11:17:17 +0000 Subject: [PATCH 033/103] make fmt --- .github/workflows/prcleanup.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/prcleanup.yaml b/.github/workflows/prcleanup.yaml index 9331074b0fd72..d6a6b2a7191cc 100644 --- a/.github/workflows/prcleanup.yaml +++ b/.github/workflows/prcleanup.yaml @@ -37,4 +37,4 @@ jobs: - name: "Remove PR namespace" run: | - kubectl delete namespace "pr${{ env.PR_NUMBER }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" + kubectl delete namespace "pr${{ env.PR_NUMBER }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" From 56d1b8d5e949ec3f68c122229bf2062ed0bf83a1 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 11:42:15 +0000 Subject: [PATCH 034/103] remove deliverybot --- .github/workflows/deploy.yaml | 40 ++++++++++++++++++++++---------- .github/workflows/prcleanup.yaml | 17 +++++++++++++- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 664cc8db48135..91ee3832d38f1 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -13,6 +13,7 @@ env: CODER_BASE_IMAGE_TAG: ghcr.io/coder/coder-preview-base:pr${{ github.event.pull_request.number }} CODER_IMAGE_TAG: ghcr.io/coder/coder-preview:pr${{ github.event.pull_request.number }} PR_NUMBER: ${{ github.event.pull_request.number }} + REPO: ghcr.io/coder/coder-preview permissions: contents: read @@ -77,20 +78,35 @@ jobs: steps: - uses: actions/checkout@v3 + - name: "Set up kubeconfig" + run: | + set -euxo pipefail + mkdir -p ~/.kube + echo "${{ secrets.DELIVERYBOT_KUBECONFIG }}" > ~/.kube/config + export KUBECONFIG=~/.kube/config + - name: "Create PR namespace" run: | set -euxo pipefail - kubectl create namespace "pr${{ env.PR_NUMBER }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" + kubectl create namespace "pr${{ env.PR_NUMBER }}" + + - name: Install Helm + uses: azure/setup-helm@v1 + - name: "Deploy" - uses: "deliverybot/helm@v1" - with: - release: "pr${{ env.PR_NUMBER }}" - namespace: "pr${{ env.PR_NUMBER }}" - version: "{{ github.sha }}" - chart: "./helm" - token: "${{ secrets.GITHUB_TOKEN }}" - values: | - name: foobar - env: - KUBECONFIG_FILE: "${{ secrets.DELIVERYBOT_KUBECONFIG }}" + run: | + helm install ./helm --namespace "pr${{ env.PR_NUMBER }}" --set coder.image.repo=${{ env.REPO}} --set coder.image.tag=${{ env.PR_NUMBER }} --name "pr${{ env.PR_NUMBER }}" --wait + + # - name: "Deploy" + # uses: "deliverybot/helm@v1" + # with: + # release: "pr${{ env.PR_NUMBER }}" + # namespace: "pr${{ env.PR_NUMBER }}" + # version: "{{ github.sha }}" + # chart: "./helm" + # token: "${{ secrets.GITHUB_TOKEN }}" + # values: | + # name: foobar + # env: + # KUBECONFIG_FILE: "${{ secrets.DELIVERYBOT_KUBECONFIG }}" diff --git a/.github/workflows/prcleanup.yaml b/.github/workflows/prcleanup.yaml index d6a6b2a7191cc..ed412706272ba 100644 --- a/.github/workflows/prcleanup.yaml +++ b/.github/workflows/prcleanup.yaml @@ -35,6 +35,21 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} tag: pr${{ env.PR_NUMBER }} + - name: Install helm + uses: azure/setup-helm@v1 + + - name: Set up kubeconfig + run: | + set -euxo pipefail + mkdir -p ~/.kube + echo "${{ secrets.DELIVERYBOT_KUBECONFIG }}" > ~/.kube/config + export KUBECONFIG=~/.kube/config + + - name: Delete helm release + run: | + set -euxo pipefail + helm delete --namespace "pr${{ env.PR_NUMBER }}" "pr${{ env.PR_NUMBER }}" + - name: "Remove PR namespace" run: | - kubectl delete namespace "pr${{ env.PR_NUMBER }}" --kubeconfig "${{ secrets.DELIVERYBOT_KUBECONFIG }}" + kubectl delete namespace "pr${{ env.PR_NUMBER }}" From 6a49c5d5c8b03ac1c62c0a7ff38c13b7a225794e Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 11:56:19 +0000 Subject: [PATCH 035/103] fix helm --- .github/workflows/deploy.yaml | 36 +++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 91ee3832d38f1..66ba2deacfc28 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -2,11 +2,13 @@ name: Deploy PR on: deployment: - pull_request: - types: [opened, synchronize, ready_for_review] + # pull_request: + # types: [opened, synchronize, ready_for_review] workflow_dispatch: # push: # branches-ignore: main + issue_comment: + types: [created, edited] env: # This is the version of the release. It is used to tag the Docker images. @@ -24,7 +26,25 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: + pr_commented: + if: ${{ github.event.issue.pull_request }} && contains(github.event.comment.body, '/review-pr') + runs-on: "ubuntu-latest" + steps: + - name: Get PR number + id: pr_number + run: echo "::set-output name=number::$(echo ${{ github.event.comment.body }} | grep -oP '(?<=/review-pr ).*')" + # Comment on the PR + - name: Create PR comment + run: | + set -euxo pipefail + curl -sSL -X POST \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d '{"body": "Deploying PR ${{ steps.pr_number.outputs.number }}"}' \ + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" + build: + needs: pr_commented runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }} env: # Necessary for Docker manifest @@ -93,10 +113,18 @@ jobs: - name: Install Helm uses: azure/setup-helm@v1 - - name: "Deploy" run: | - helm install ./helm --namespace "pr${{ env.PR_NUMBER }}" --set coder.image.repo=${{ env.REPO}} --set coder.image.tag=${{ env.PR_NUMBER }} --name "pr${{ env.PR_NUMBER }}" --wait + helm install pr${{ env.PR_NUMBER }} ./helm --namespace "pr${{ env.PR_NUMBER }}" --set coder.image.repo=${{ env.REPO}} --set coder.image.tag=${{ env.PR_NUMBER }} --wait + + - name: Comment on PR + run: | + set -euxo pipefail + curl -sSL -X POST \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d '{"body": "Deployed PR ${{ env.PR_NUMBER }} successfully"}' \ + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" # - name: "Deploy" # uses: "deliverybot/helm@v1" From bec08618ab6187f477984f1d9f4ebdaacd7ff1a6 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 12:06:40 +0000 Subject: [PATCH 036/103] refactor and rename --- .../workflows/{deploy.yaml => deploypr.yaml} | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) rename .github/workflows/{deploy.yaml => deploypr.yaml} (74%) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploypr.yaml similarity index 74% rename from .github/workflows/deploy.yaml rename to .github/workflows/deploypr.yaml index 66ba2deacfc28..377e22c3a5b6f 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploypr.yaml @@ -1,4 +1,5 @@ -# .github/workflows/deploy.yml +# .github/workflows/deploypr.yml +# This action will trigger when a PR is opened or updated with a comment containing /review-pr by a member of the org. name: Deploy PR on: deployment: @@ -11,10 +12,6 @@ on: types: [created, edited] env: - # This is the version of the release. It is used to tag the Docker images. - CODER_BASE_IMAGE_TAG: ghcr.io/coder/coder-preview-base:pr${{ github.event.pull_request.number }} - CODER_IMAGE_TAG: ghcr.io/coder/coder-preview:pr${{ github.event.pull_request.number }} - PR_NUMBER: ${{ github.event.pull_request.number }} REPO: ghcr.io/coder/coder-preview permissions: @@ -27,12 +24,29 @@ concurrency: jobs: pr_commented: - if: ${{ github.event.issue.pull_request }} && contains(github.event.comment.body, '/review-pr') + if: ${{ github.event.issue.pull_request }} && contains(github.event.comment.body, '/review-pr') && github.event.comment.author_association == 'MEMBER' + outputs: + number: ${{ steps.pr_number.outputs.number }} + coder_base_image_tag: ${{ steps.set_tags.outputs.CODER_BASE_IMAGE_TAG }} + coder_image_tag: ${{ steps.set_tags.outputs.CODER_IMAGE_TAG }} + runs-on: "ubuntu-latest" steps: - name: Get PR number id: pr_number - run: echo "::set-output name=number::$(echo ${{ github.event.comment.body }} | grep -oP '(?<=/review-pr ).*')" + # get PR number from the html_url + run: | + set -euxo pipefail + echo "::set-output name=number::$(echo ${{ github.event.issue.html_url }} | cut -d'/' -f7)" + + - name: Set required tags + id: set_tags + run: | + set -euxo pipefail + echo "::set-env name=CODER_BASE_IMAGE_TAG::ghcr.io/coder/coder-preview-base:pr${{ steps.pr_number.outputs.number }}" + echo "::set-env name=CODER_IMAGE_TAG::ghcr.io/coder/coder-preview:pr${{ steps.pr_number.outputs.number }}" + echo "::set-env name=REPO::ghcr.io/coder/coder-preview" + # Comment on the PR - name: Create PR comment run: | @@ -49,6 +63,9 @@ jobs: env: # Necessary for Docker manifest DOCKER_CLI_EXPERIMENTAL: "enabled" + CODER_BASE_IMAGE_TAG: ${{ needs.pr_commented.outputs.coder_base_image_tag }} + CODER_IMAGE_TAG: ${{ needs.pr_commented.outputs.coder_image_tag }} + PR_NUMBER: ${{ needs.pr_commented.outputs.number }} steps: - uses: actions/checkout@v3 with: @@ -92,9 +109,12 @@ jobs: CODER_BASE_IMAGE_TAG: ${{ env.CODER_BASE_IMAGE_TAG }} deployment: - needs: build + needs: [build, pr_commented] if: needs.build.result == 'success' runs-on: "ubuntu-latest" + env: + CODER_IMAGE_TAG: ${{ needs.pr_commented.outputs.coder_image_tag }} + PR_NUMBER: ${{ needs.pr_commented.outputs.number }} steps: - uses: actions/checkout@v3 From 8e8c2ae336d212555cf811ffad66829100c76587 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 12:09:16 +0000 Subject: [PATCH 037/103] remove deployment trigger --- .github/workflows/deploypr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 377e22c3a5b6f..0ba9b25c0f37b 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -2,7 +2,7 @@ # This action will trigger when a PR is opened or updated with a comment containing /review-pr by a member of the org. name: Deploy PR on: - deployment: + # deployment: # pull_request: # types: [opened, synchronize, ready_for_review] workflow_dispatch: From 832fa66f2de5c7819136ae33d24665c5bf6f0682 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 12:13:55 +0000 Subject: [PATCH 038/103] refactor --- .github/workflows/deploypr.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 0ba9b25c0f37b..4d50966b5be5b 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -6,8 +6,8 @@ on: # pull_request: # types: [opened, synchronize, ready_for_review] workflow_dispatch: - # push: - # branches-ignore: main + push: + branches-ignore: main issue_comment: types: [created, edited] @@ -45,10 +45,9 @@ jobs: set -euxo pipefail echo "::set-env name=CODER_BASE_IMAGE_TAG::ghcr.io/coder/coder-preview-base:pr${{ steps.pr_number.outputs.number }}" echo "::set-env name=CODER_IMAGE_TAG::ghcr.io/coder/coder-preview:pr${{ steps.pr_number.outputs.number }}" - echo "::set-env name=REPO::ghcr.io/coder/coder-preview" # Comment on the PR - - name: Create PR comment + - name: Comment on PR run: | set -euxo pipefail curl -sSL -X POST \ From 270b639f53e9ad1cb620698a65efe3eb97de37e8 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 12:18:26 +0000 Subject: [PATCH 039/103] refactor --- .github/workflows/deploypr.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 4d50966b5be5b..96adbf0ec134b 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -26,7 +26,7 @@ jobs: pr_commented: if: ${{ github.event.issue.pull_request }} && contains(github.event.comment.body, '/review-pr') && github.event.comment.author_association == 'MEMBER' outputs: - number: ${{ steps.pr_number.outputs.number }} + pr_number: ${{ steps.pr_number.outputs.pr_number }} coder_base_image_tag: ${{ steps.set_tags.outputs.CODER_BASE_IMAGE_TAG }} coder_image_tag: ${{ steps.set_tags.outputs.CODER_IMAGE_TAG }} @@ -37,14 +37,14 @@ jobs: # get PR number from the html_url run: | set -euxo pipefail - echo "::set-output name=number::$(echo ${{ github.event.issue.html_url }} | cut -d'/' -f7)" + echo "{pr_number: $(echo "${{ github.event.issue.pull_request.html_url }}" | grep -oP '(?<=pull\/)\d+')}" > $GITHUB_OUTPUT - name: Set required tags id: set_tags run: | set -euxo pipefail - echo "::set-env name=CODER_BASE_IMAGE_TAG::ghcr.io/coder/coder-preview-base:pr${{ steps.pr_number.outputs.number }}" - echo "::set-env name=CODER_IMAGE_TAG::ghcr.io/coder/coder-preview:pr${{ steps.pr_number.outputs.number }}" + echo "CODER_BASE_IMAGE_TAG=$(echo "${{ github.event.issue.pull_request.html_url }}" | grep -oP '(?<=pull\/)\d+')" > $GITHUB_OUTPUT + echo "CODER_IMAGE_TAG=$(echo "${{ github.event.issue.pull_request.html_url }}" | grep -oP '(?<=pull\/)\d+')" >> $GITHUB_OUTPUT # Comment on the PR - name: Comment on PR From 509f9f456de10c92feeb1f5409bdfcd533c1291d Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 12:22:32 +0000 Subject: [PATCH 040/103] refactor --- .github/workflows/deploypr.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 96adbf0ec134b..58dd2f34ba095 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -27,8 +27,8 @@ jobs: if: ${{ github.event.issue.pull_request }} && contains(github.event.comment.body, '/review-pr') && github.event.comment.author_association == 'MEMBER' outputs: pr_number: ${{ steps.pr_number.outputs.pr_number }} - coder_base_image_tag: ${{ steps.set_tags.outputs.CODER_BASE_IMAGE_TAG }} - coder_image_tag: ${{ steps.set_tags.outputs.CODER_IMAGE_TAG }} + coder_base_image_tag: ${{ steps.set_tags.outputs.CODE_BASE_IMAGE_TAG }} + coder_image_tag: ${{ steps.set_tags.outputs.CODE_IMAGE_TAG }} runs-on: "ubuntu-latest" steps: @@ -37,7 +37,9 @@ jobs: # get PR number from the html_url run: | set -euxo pipefail - echo "{pr_number: $(echo "${{ github.event.issue.pull_request.html_url }}" | grep -oP '(?<=pull\/)\d+')}" > $GITHUB_OUTPUT + PR_NUMBER=$(echo "${{ github.event.issue.pull_request.html_url }}" | grep -oP '(?<=pull\/)\d+') + echo $PR_NUMBER + echo "pr_number=$PR_NUMBER" >> $GITHUB_ENV - name: Set required tags id: set_tags From 23b798308f25b58cdb56a37e450287c2875444dd Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 12:24:29 +0000 Subject: [PATCH 041/103] fix PR_NUMBER --- .github/workflows/deploypr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 58dd2f34ba095..4fae599fe9d3a 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -37,7 +37,7 @@ jobs: # get PR number from the html_url run: | set -euxo pipefail - PR_NUMBER=$(echo "${{ github.event.issue.pull_request.html_url }}" | grep -oP '(?<=pull\/)\d+') + PR_NUMBER=$(echo "${{ github.event.issue.url }}" | awk -F '/' '{print $NF}') echo $PR_NUMBER echo "pr_number=$PR_NUMBER" >> $GITHUB_ENV From 17152138f48f4f123e301af130ecfa0ae08c1a64 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 12:28:23 +0000 Subject: [PATCH 042/103] remove extra triggers --- .github/workflows/deploypr.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 4fae599fe9d3a..df670009af0ae 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -2,12 +2,6 @@ # This action will trigger when a PR is opened or updated with a comment containing /review-pr by a member of the org. name: Deploy PR on: - # deployment: - # pull_request: - # types: [opened, synchronize, ready_for_review] - workflow_dispatch: - push: - branches-ignore: main issue_comment: types: [created, edited] From ccba656c4876126a7d458d51b197ebb9d5ec71e1 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 12:41:26 +0000 Subject: [PATCH 043/103] fix action outputs --- .github/workflows/deploypr.yaml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index df670009af0ae..6b910e26556e3 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -4,6 +4,7 @@ name: Deploy PR on: issue_comment: types: [created, edited] + workflow_dispatch: env: REPO: ghcr.io/coder/coder-preview @@ -18,11 +19,11 @@ concurrency: jobs: pr_commented: - if: ${{ github.event.issue.pull_request }} && contains(github.event.comment.body, '/review-pr') && github.event.comment.author_association == 'MEMBER' + if: ${{ github.event.issue.pull_request }} && contains(github.event.comment.body, '/review-pr') && github.event.comment.author_association == 'MEMBER' || github.event_name == 'workflow_dispatch' outputs: - pr_number: ${{ steps.pr_number.outputs.pr_number }} - coder_base_image_tag: ${{ steps.set_tags.outputs.CODE_BASE_IMAGE_TAG }} - coder_image_tag: ${{ steps.set_tags.outputs.CODE_IMAGE_TAG }} + PR_NUMBER: ${{ steps.pr_number.outputs.PR_NUMBER }} + CODER_BASE_IMAGE_TAG: ${{ steps.set_tags.outputs.CODER_BASE_IMAGE_TAG }} + CODER_IMAGE_TAG: ${{ steps.set_tags.outputs.CODER_IMAGE_TAG }} runs-on: "ubuntu-latest" steps: @@ -33,14 +34,14 @@ jobs: set -euxo pipefail PR_NUMBER=$(echo "${{ github.event.issue.url }}" | awk -F '/' '{print $NF}') echo $PR_NUMBER - echo "pr_number=$PR_NUMBER" >> $GITHUB_ENV + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV - name: Set required tags id: set_tags run: | set -euxo pipefail - echo "CODER_BASE_IMAGE_TAG=$(echo "${{ github.event.issue.pull_request.html_url }}" | grep -oP '(?<=pull\/)\d+')" > $GITHUB_OUTPUT - echo "CODER_IMAGE_TAG=$(echo "${{ github.event.issue.pull_request.html_url }}" | grep -oP '(?<=pull\/)\d+')" >> $GITHUB_OUTPUT + echo "CODER_BASE_IMAGE_TAG=ghcr.io/coder/coder-preview:base-${{ steps.pr_number.outputs.PR_NUMBER }}" >> $GITHUB_ENV + echo "CODER_IMAGE_TAG=ghcr.io/coder/coder-preview:${{ steps.pr_number.outputs.PR_NUMBER }}" >> $GITHUB_ENV # Comment on the PR - name: Comment on PR @@ -49,7 +50,7 @@ jobs: curl -sSL -X POST \ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -H "Accept: application/vnd.github.v3+json" \ - -d '{"body": "Deploying PR ${{ steps.pr_number.outputs.number }}"}' \ + -d '{"body": "Deploying PR ${{ steps.pr_number.outputs.PR_NUMBER }}"}' \ "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" build: @@ -60,7 +61,7 @@ jobs: DOCKER_CLI_EXPERIMENTAL: "enabled" CODER_BASE_IMAGE_TAG: ${{ needs.pr_commented.outputs.coder_base_image_tag }} CODER_IMAGE_TAG: ${{ needs.pr_commented.outputs.coder_image_tag }} - PR_NUMBER: ${{ needs.pr_commented.outputs.number }} + PR_NUMBER: ${{ needs.pr_commented.outputs.pr_number }} steps: - uses: actions/checkout@v3 with: @@ -108,8 +109,8 @@ jobs: if: needs.build.result == 'success' runs-on: "ubuntu-latest" env: - CODER_IMAGE_TAG: ${{ needs.pr_commented.outputs.coder_image_tag }} - PR_NUMBER: ${{ needs.pr_commented.outputs.number }} + CODER_IMAGE_TAG: ${{ needs.pr_commented.outputs.CODER_IMAGE_TAG }} + PR_NUMBER: ${{ needs.pr_commented.outputs.PR_NUMBER }} steps: - uses: actions/checkout@v3 From 019b4603da80aa6f415965c3e6f053823ed86fb7 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 12:44:29 +0000 Subject: [PATCH 044/103] add trigger for testing --- .github/workflows/deploypr.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 6b910e26556e3..7248658c2a377 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -5,6 +5,8 @@ on: issue_comment: types: [created, edited] workflow_dispatch: + push: + branches-ignore: main # TODO: Remove this before merging env: REPO: ghcr.io/coder/coder-preview From 76e4736b1454bdc972f825b678481c949c270fe0 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 12:45:51 +0000 Subject: [PATCH 045/103] fix tag --- .github/workflows/deploypr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 7248658c2a377..c6ca2dfb7c09a 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -42,7 +42,7 @@ jobs: id: set_tags run: | set -euxo pipefail - echo "CODER_BASE_IMAGE_TAG=ghcr.io/coder/coder-preview:base-${{ steps.pr_number.outputs.PR_NUMBER }}" >> $GITHUB_ENV + echo "CODER_BASE_IMAGE_TAG=ghcr.io/coder/coder-preview-base:${{ steps.pr_number.outputs.PR_NUMBER }}" >> $GITHUB_ENV echo "CODER_IMAGE_TAG=ghcr.io/coder/coder-preview:${{ steps.pr_number.outputs.PR_NUMBER }}" >> $GITHUB_ENV # Comment on the PR From 13d568226b55a3e7bb7b6c46f5b9ebcdad258212 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 12:47:08 +0000 Subject: [PATCH 046/103] try again --- .github/workflows/deploypr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index c6ca2dfb7c09a..d27f9b1c7aa9f 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -34,7 +34,7 @@ jobs: # get PR number from the html_url run: | set -euxo pipefail - PR_NUMBER=$(echo "${{ github.event.issue.url }}" | awk -F '/' '{print $NF}') + PR_NUMBER=${{ github.event.issue.number }} echo $PR_NUMBER echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV From c4b96bf0f83f0e50a5752874f5b6efd51e0183c2 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 13:04:30 +0000 Subject: [PATCH 047/103] refactor --- .github/workflows/deploypr.yaml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index d27f9b1c7aa9f..12e0daaf01a82 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -34,16 +34,21 @@ jobs: # get PR number from the html_url run: | set -euxo pipefail - PR_NUMBER=${{ github.event.issue.number }} echo $PR_NUMBER echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV + env: + PR_NUMBER: ${{ github.event.issue.number }} - name: Set required tags id: set_tags run: | set -euxo pipefail - echo "CODER_BASE_IMAGE_TAG=ghcr.io/coder/coder-preview-base:${{ steps.pr_number.outputs.PR_NUMBER }}" >> $GITHUB_ENV - echo "CODER_IMAGE_TAG=ghcr.io/coder/coder-preview:${{ steps.pr_number.outputs.PR_NUMBER }}" >> $GITHUB_ENV + echo "CODER_BASE_IMAGE_TAG=$CODER_BASE_IMAGE_TAG" >> $GITHUB_OUTPUT + echo "CODER_IMAGE_TAG=$CODER_IMAGE_TAG" >> $GITHUB_OUTPUT + env: + PR_NUMBER: ${{ steps.pr_number.outputs.PR_NUMBER }} + CODER_BASE_IMAGE_TAG: ghcr.io/coder/coder-preview-base:${{ env.PR_NUMBER }} + CODER_IMAGE_TAG: ghcr.io/coder/coder-preview:${{ env.PR_NUMBER }} # Comment on the PR - name: Comment on PR From 7ff0e6aa08f7f52633d82d052f654470a56d2171 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 13:04:48 +0000 Subject: [PATCH 048/103] refactor --- .github/workflows/deploypr.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 12e0daaf01a82..cafe6c5d80d49 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -3,7 +3,6 @@ name: Deploy PR on: issue_comment: - types: [created, edited] workflow_dispatch: push: branches-ignore: main # TODO: Remove this before merging From ee4138dd6bd6b0879fd41b3cbec0af6589985820 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 13:12:41 +0000 Subject: [PATCH 049/103] add workflow-dispatch --- .github/workflows/deploypr.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index cafe6c5d80d49..a1a8f6bbaa68f 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -4,8 +4,10 @@ name: Deploy PR on: issue_comment: workflow_dispatch: - push: - branches-ignore: main # TODO: Remove this before merging + inputs: + pr_number: + description: "PR number" + required: true env: REPO: ghcr.io/coder/coder-preview @@ -33,10 +35,12 @@ jobs: # get PR number from the html_url run: | set -euxo pipefail + if [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then + PR_NUMBER=${{ github.event.inputs.pr_number }} + else + PR_NUMBER=${{ github.event.issue.number }} echo $PR_NUMBER echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV - env: - PR_NUMBER: ${{ github.event.issue.number }} - name: Set required tags id: set_tags From ad3386e99caae0732379afa2eaabb445b6e75b83 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 13:19:47 +0000 Subject: [PATCH 050/103] fix syntax --- .github/workflows/deploypr.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index a1a8f6bbaa68f..a0f4f12c494c3 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -39,6 +39,7 @@ jobs: PR_NUMBER=${{ github.event.inputs.pr_number }} else PR_NUMBER=${{ github.event.issue.number }} + fi echo $PR_NUMBER echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV From 8a16f40a44f8cbe6c6c57a3e828397f0b5507838 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 13:20:55 +0000 Subject: [PATCH 051/103] correct tag name --- .github/workflows/deploypr.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index a0f4f12c494c3..e00e08ab163f0 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -51,8 +51,8 @@ jobs: echo "CODER_IMAGE_TAG=$CODER_IMAGE_TAG" >> $GITHUB_OUTPUT env: PR_NUMBER: ${{ steps.pr_number.outputs.PR_NUMBER }} - CODER_BASE_IMAGE_TAG: ghcr.io/coder/coder-preview-base:${{ env.PR_NUMBER }} - CODER_IMAGE_TAG: ghcr.io/coder/coder-preview:${{ env.PR_NUMBER }} + CODER_BASE_IMAGE_TAG: ghcr.io/coder/coder-preview-base:pr${{ env.PR_NUMBER }} + CODER_IMAGE_TAG: ghcr.io/coder/coder-preview:pr${{ env.PR_NUMBER }} # Comment on the PR - name: Comment on PR From 164fcb3f56f3a718d5f7fdbd117b766598970d9a Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 13:22:52 +0000 Subject: [PATCH 052/103] fix! --- .github/workflows/deploypr.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index e00e08ab163f0..8a4a06c93110e 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -50,9 +50,8 @@ jobs: echo "CODER_BASE_IMAGE_TAG=$CODER_BASE_IMAGE_TAG" >> $GITHUB_OUTPUT echo "CODER_IMAGE_TAG=$CODER_IMAGE_TAG" >> $GITHUB_OUTPUT env: - PR_NUMBER: ${{ steps.pr_number.outputs.PR_NUMBER }} - CODER_BASE_IMAGE_TAG: ghcr.io/coder/coder-preview-base:pr${{ env.PR_NUMBER }} - CODER_IMAGE_TAG: ghcr.io/coder/coder-preview:pr${{ env.PR_NUMBER }} + CODER_BASE_IMAGE_TAG: ghcr.io/coder/coder-preview-base:pr${{ steps.pr_number.outputs.PR_NUMBER }} + CODER_IMAGE_TAG: ghcr.io/coder/coder-preview:pr${{ steps.pr_number.outputs.PR_NUMBER }} # Comment on the PR - name: Comment on PR From f8f9ca7014f3696854ec02c1940cc86854180925 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 13:27:36 +0000 Subject: [PATCH 053/103] fix output --- .github/workflows/deploypr.yaml | 2 +- .github/workflows/prcleanup.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 8a4a06c93110e..3fafef26778c5 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -41,7 +41,7 @@ jobs: PR_NUMBER=${{ github.event.issue.number }} fi echo $PR_NUMBER - echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT - name: Set required tags id: set_tags diff --git a/.github/workflows/prcleanup.yaml b/.github/workflows/prcleanup.yaml index ed412706272ba..a9a3131429223 100644 --- a/.github/workflows/prcleanup.yaml +++ b/.github/workflows/prcleanup.yaml @@ -1,5 +1,5 @@ # .github/workflows/pr-cleanup.yml -name: PRCleanup +name: Cleanup PR on: pull_request: types: [closed] From 9358201d6414aeb3248202ba1f0876a072c642f7 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 13:34:25 +0000 Subject: [PATCH 054/103] fix comment path --- .github/workflows/deploypr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 3fafef26778c5..6871c9c59c0b0 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -61,7 +61,7 @@ jobs: -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -H "Accept: application/vnd.github.v3+json" \ -d '{"body": "Deploying PR ${{ steps.pr_number.outputs.PR_NUMBER }}"}' \ - "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" + "https://api.github.com/repos/${{ github.repository }}/issues/${{ steps.pr_number.outputs.PR_NUMBER }}/comments" build: needs: pr_commented From 9a2aba4b5d2f89f23b5aff8056afb11e068578f4 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 13:47:12 +0000 Subject: [PATCH 055/103] fix! comments --- .github/workflows/deploypr.yaml | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 6871c9c59c0b0..b02d7cc8720fb 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -15,6 +15,7 @@ env: permissions: contents: read packages: write + pull-requests: write concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -25,6 +26,7 @@ jobs: if: ${{ github.event.issue.pull_request }} && contains(github.event.comment.body, '/review-pr') && github.event.comment.author_association == 'MEMBER' || github.event_name == 'workflow_dispatch' outputs: PR_NUMBER: ${{ steps.pr_number.outputs.PR_NUMBER }} + COMMENT_ID: ${{ steps.comment_id.outputs.comment-id }} CODER_BASE_IMAGE_TAG: ${{ steps.set_tags.outputs.CODER_BASE_IMAGE_TAG }} CODER_IMAGE_TAG: ${{ steps.set_tags.outputs.CODER_IMAGE_TAG }} @@ -55,13 +57,13 @@ jobs: # Comment on the PR - name: Comment on PR - run: | - set -euxo pipefail - curl -sSL -X POST \ - -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - -d '{"body": "Deploying PR ${{ steps.pr_number.outputs.PR_NUMBER }}"}' \ - "https://api.github.com/repos/${{ github.repository }}/issues/${{ steps.pr_number.outputs.PR_NUMBER }}/comments" + id: comment_id + uses: peter-evans/create-or-update-comment@v3 + with: + issue-number: ${{ steps.pr_number.outputs.PR_NUMBER }} + body: | + :rocket: Deploying PR ${{ steps.pr_number.outputs.PR_NUMBER }} + :warning: This deployment will be deleted when the PR is closed. build: needs: pr_commented @@ -144,13 +146,13 @@ jobs: helm install pr${{ env.PR_NUMBER }} ./helm --namespace "pr${{ env.PR_NUMBER }}" --set coder.image.repo=${{ env.REPO}} --set coder.image.tag=${{ env.PR_NUMBER }} --wait - name: Comment on PR - run: | - set -euxo pipefail - curl -sSL -X POST \ - -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - -d '{"body": "Deployed PR ${{ env.PR_NUMBER }} successfully"}' \ - "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" + uses: peter-evans/create-or-update-comment@v3 + with: + issue-number: ${{ env.PR_NUMBER }} + comment-id: ${{ needs.pr_commented.outputs.COMMENT_ID }} + body: | + :success: Deployed PR ${{ env.PR_NUMBER }} successfully. + :warning: This deployment will be deleted when the PR is closed. # - name: "Deploy" # uses: "deliverybot/helm@v1" From 48f58779e5b80fd8d5daf4c96487f2ac2bff5a76 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 13:48:48 +0000 Subject: [PATCH 056/103] delete namespace if it already exists --- .github/workflows/deploypr.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index b02d7cc8720fb..cc634ab38c607 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -136,6 +136,8 @@ jobs: - name: "Create PR namespace" run: | set -euxo pipefail + # try to delete the namespace, but don't fail if it doesn't exist + kubectl delete namespace "pr${{ env.PR_NUMBER }}" || true kubectl create namespace "pr${{ env.PR_NUMBER }}" - name: Install Helm From 129f21ec028e308a6a0c15c1b6972776f607cc17 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 14:04:38 +0000 Subject: [PATCH 057/103] use correct name for helm install --- .github/workflows/deploypr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index cc634ab38c607..dc4f18c37932e 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -145,7 +145,7 @@ jobs: - name: "Deploy" run: | - helm install pr${{ env.PR_NUMBER }} ./helm --namespace "pr${{ env.PR_NUMBER }}" --set coder.image.repo=${{ env.REPO}} --set coder.image.tag=${{ env.PR_NUMBER }} --wait + helm install pr${{ env.PR_NUMBER }} ./helm --namespace "pr${{ env.PR_NUMBER }}" --set coder.image.repo=${{ env.REPO}} --set coder.image.tag=pr${{ env.PR_NUMBER }} --wait - name: Comment on PR uses: peter-evans/create-or-update-comment@v3 From d360a02ae68b850335b6686c58728f58a72eee7c Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 14:08:40 +0000 Subject: [PATCH 058/103] edit the existing comment instead of creating new --- .github/workflows/deploypr.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index dc4f18c37932e..1bc2f1b5dcef9 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -55,11 +55,21 @@ jobs: CODER_BASE_IMAGE_TAG: ghcr.io/coder/coder-preview-base:pr${{ steps.pr_number.outputs.PR_NUMBER }} CODER_IMAGE_TAG: ghcr.io/coder/coder-preview:pr${{ steps.pr_number.outputs.PR_NUMBER }} - # Comment on the PR + + - name: Find Comment + uses: peter-evans/find-comment@v2 + id: fc + with: + issue-number: ${{ steps.pr_number.outputs.PR_NUMBER }} + comment-author: 'github-actions[bot]' + body-includes: This deployment will be deleted when the PR is closed + + # Comment on the PR - name: Comment on PR id: comment_id uses: peter-evans/create-or-update-comment@v3 with: + comment-id: ${{ steps.fc.outputs.comment-id }} issue-number: ${{ steps.pr_number.outputs.PR_NUMBER }} body: | :rocket: Deploying PR ${{ steps.pr_number.outputs.PR_NUMBER }} From 72d5388047c4651413a8b3f05febc341fe0bc495 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 14:16:00 +0000 Subject: [PATCH 059/103] replace existing comment --- .github/workflows/deploypr.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 1bc2f1b5dcef9..ec6b0f350c9f5 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -34,7 +34,6 @@ jobs: steps: - name: Get PR number id: pr_number - # get PR number from the html_url run: | set -euxo pipefail if [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then @@ -71,6 +70,7 @@ jobs: with: comment-id: ${{ steps.fc.outputs.comment-id }} issue-number: ${{ steps.pr_number.outputs.PR_NUMBER }} + edit-mode: replace body: | :rocket: Deploying PR ${{ steps.pr_number.outputs.PR_NUMBER }} :warning: This deployment will be deleted when the PR is closed. @@ -161,9 +161,10 @@ jobs: uses: peter-evans/create-or-update-comment@v3 with: issue-number: ${{ env.PR_NUMBER }} + edit-mode: replace comment-id: ${{ needs.pr_commented.outputs.COMMENT_ID }} body: | - :success: Deployed PR ${{ env.PR_NUMBER }} successfully. + :heavy_check_mark: Deployed PR ${{ env.PR_NUMBER }} successfully. :warning: This deployment will be deleted when the PR is closed. # - name: "Deploy" From 5e91975c5a02612a45fea516313b1e8bd4f2cf6c Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 14:16:42 +0000 Subject: [PATCH 060/103] add reaction --- .github/workflows/deploypr.yaml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index ec6b0f350c9f5..1d77759c3e78e 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -166,16 +166,4 @@ jobs: body: | :heavy_check_mark: Deployed PR ${{ env.PR_NUMBER }} successfully. :warning: This deployment will be deleted when the PR is closed. - - # - name: "Deploy" - # uses: "deliverybot/helm@v1" - # with: - # release: "pr${{ env.PR_NUMBER }}" - # namespace: "pr${{ env.PR_NUMBER }}" - # version: "{{ github.sha }}" - # chart: "./helm" - # token: "${{ secrets.GITHUB_TOKEN }}" - # values: | - # name: foobar - # env: - # KUBECONFIG_FILE: "${{ secrets.DELIVERYBOT_KUBECONFIG }}" + reactions: '+1' From 761816b27f42020fd118090672195922f9dc3c0f Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 14:17:08 +0000 Subject: [PATCH 061/103] remove deploy/yml --- .github/deploy.yml | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 .github/deploy.yml diff --git a/.github/deploy.yml b/.github/deploy.yml deleted file mode 100644 index 017c3bf821ce8..0000000000000 --- a/.github/deploy.yml +++ /dev/null @@ -1,15 +0,0 @@ -# Review environments can be triggered with "/deploy review" inside a pull request. -review: - transient_environment: true - production_environment: false - required_contexts: ["ci"] - environment: pr${{ pr }} - description: "Review" - payload: - release: pr${{ pr }} - namespace: pr${{ pr }} - track: stable - values: - image: - repo: ghcr.io/coder/coder-preview - tag: pr${{ pr }} From d9a6f440a1aad463f0839e55dfcb8e6e7997637c Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 14:20:03 +0000 Subject: [PATCH 062/103] make fmt --- .github/workflows/deploypr.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 1d77759c3e78e..4d2bb4e01bcee 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -54,13 +54,12 @@ jobs: CODER_BASE_IMAGE_TAG: ghcr.io/coder/coder-preview-base:pr${{ steps.pr_number.outputs.PR_NUMBER }} CODER_IMAGE_TAG: ghcr.io/coder/coder-preview:pr${{ steps.pr_number.outputs.PR_NUMBER }} - - name: Find Comment uses: peter-evans/find-comment@v2 id: fc with: issue-number: ${{ steps.pr_number.outputs.PR_NUMBER }} - comment-author: 'github-actions[bot]' + comment-author: "github-actions[bot]" body-includes: This deployment will be deleted when the PR is closed # Comment on the PR @@ -166,4 +165,4 @@ jobs: body: | :heavy_check_mark: Deployed PR ${{ env.PR_NUMBER }} successfully. :warning: This deployment will be deleted when the PR is closed. - reactions: '+1' + reactions: "+1" From 77a1684255e81f422e3afac4bbc7c5896b16b3d6 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 14:21:51 +0000 Subject: [PATCH 063/103] cancel in-progress runs --- .github/workflows/deploypr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 4d2bb4e01bcee..94e5d828bc437 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -19,7 +19,7 @@ permissions: concurrency: group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} + cancel-in-progress: true jobs: pr_commented: From 188df5014c19cebbf191748247d1bdd1da2aab41 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 14:32:31 +0000 Subject: [PATCH 064/103] use upgrade and --force --- .github/workflows/deploypr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 94e5d828bc437..9e371c9bf234c 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -154,7 +154,7 @@ jobs: - name: "Deploy" run: | - helm install pr${{ env.PR_NUMBER }} ./helm --namespace "pr${{ env.PR_NUMBER }}" --set coder.image.repo=${{ env.REPO}} --set coder.image.tag=pr${{ env.PR_NUMBER }} --wait + helm upgrdae --install pr${{ env.PR_NUMBER }} ./helm --namespace "pr${{ env.PR_NUMBER }}" --set coder.image.repo=${{ env.REPO}} --set coder.image.tag=pr${{ env.PR_NUMBER }} --wait --force - name: Comment on PR uses: peter-evans/create-or-update-comment@v3 From 70ca35ca393c9f0606857efa0cf74262542a88be Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 14:38:51 +0000 Subject: [PATCH 065/103] fix typo --- .github/workflows/deploypr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 9e371c9bf234c..5ae2dfa260e76 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -154,7 +154,7 @@ jobs: - name: "Deploy" run: | - helm upgrdae --install pr${{ env.PR_NUMBER }} ./helm --namespace "pr${{ env.PR_NUMBER }}" --set coder.image.repo=${{ env.REPO}} --set coder.image.tag=pr${{ env.PR_NUMBER }} --wait --force + helm upgrade --install pr${{ env.PR_NUMBER }} ./helm --namespace "pr${{ env.PR_NUMBER }}" --set coder.image.repo=${{ env.REPO}} --set coder.image.tag=pr${{ env.PR_NUMBER }} --wait --force - name: Comment on PR uses: peter-evans/create-or-update-comment@v3 From 59f1530c5cfa8c821b015a1a2e3ac12216636de7 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 15:45:44 +0000 Subject: [PATCH 066/103] fix helm and slack notification --- .github/workflows/deploypr.yaml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 5ae2dfa260e76..650da3084426d 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -154,7 +154,29 @@ jobs: - name: "Deploy" run: | - helm upgrade --install pr${{ env.PR_NUMBER }} ./helm --namespace "pr${{ env.PR_NUMBER }}" --set coder.image.repo=${{ env.REPO}} --set coder.image.tag=pr${{ env.PR_NUMBER }} --wait --force + helm upgrade --install pr${{ env.PR_NUMBER }} ./helm \ + --namespace "pr${{ env.PR_NUMBER }}" \ + --set coder.image.repo=${{ env.REPO}} \ + --set coder.image.tag=pr${{ env.PR_NUMBER }} \ + --set service.type=ClusterIP \ + --set env.CODER_ACCESS_URL="" \ + --force + + - name: "Get deployment URL" + id: deployment_url + run: | + set -euxo pipefail + kubectl rollout status deployment/coder --namespace "pr${{ env.PR_NUMBER }}" + POD_NAME=$(kubectl get pods -n "pr${{ env.PR_NUMBER }} | awk 'NR==2{print $1}') + CODER_ACCESS_URL=(kubectl logs $POD_NAME -n pr8121 | grep "Web UI:" | awk -F ':' '{print $2":"$3}') + echo "CODER_ACCESS_URL=$CODER_ACCESS_URL" >> $GITHUB_OUTPUT + + - name: Send Slack notification + run: | + curl -X POST -H 'Content-type: application/json' -d '{"msg":"Access the the depluyment for ${{ env.PR_NUMBER }} at \n${{env.CODER_ACCESS_URL}}"}' ${{ secrets.DOCS_LINK_SLACK_WEBHOOK }} + echo "Sent Slack notification" + env: + CODER_ACCESS_URL: ${{ steps.deployment_url.outputs.CODER_ACCESS_URL }} - name: Comment on PR uses: peter-evans/create-or-update-comment@v3 From 500c534370870f1b1f21f6c22fa3814cea16d233 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 15:47:21 +0000 Subject: [PATCH 067/103] fix helm --- .github/workflows/deploypr.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 650da3084426d..1883ef4ee2771 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -158,8 +158,9 @@ jobs: --namespace "pr${{ env.PR_NUMBER }}" \ --set coder.image.repo=${{ env.REPO}} \ --set coder.image.tag=pr${{ env.PR_NUMBER }} \ - --set service.type=ClusterIP \ - --set env.CODER_ACCESS_URL="" \ + --set coder.service.type=ClusterIP \ + --set coder.env[0].name=CODER_ACCESS_URL \ + --set coder.env[0].value="" --force - name: "Get deployment URL" From 08497189d8e011e77ac65b2b21361e10530c5123 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 15:47:47 +0000 Subject: [PATCH 068/103] make fmt --- .github/workflows/deploypr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/deploypr.yaml index 1883ef4ee2771..d09f90c79b3b2 100644 --- a/.github/workflows/deploypr.yaml +++ b/.github/workflows/deploypr.yaml @@ -156,7 +156,7 @@ jobs: run: | helm upgrade --install pr${{ env.PR_NUMBER }} ./helm \ --namespace "pr${{ env.PR_NUMBER }}" \ - --set coder.image.repo=${{ env.REPO}} \ + --set coder.image.repo=${{ env.REPO }} \ --set coder.image.tag=pr${{ env.PR_NUMBER }} \ --set coder.service.type=ClusterIP \ --set coder.env[0].name=CODER_ACCESS_URL \ From d6d0c375119d3383ef9aae5d9ed8bf08d75eb0d3 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 15:57:52 +0000 Subject: [PATCH 069/103] rename actions files --- .github/workflows/{prcleanup.yaml => pr-cleanup.yaml} | 0 .github/workflows/{deploypr.yaml => pr-deploy.yaml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{prcleanup.yaml => pr-cleanup.yaml} (100%) rename .github/workflows/{deploypr.yaml => pr-deploy.yaml} (100%) diff --git a/.github/workflows/prcleanup.yaml b/.github/workflows/pr-cleanup.yaml similarity index 100% rename from .github/workflows/prcleanup.yaml rename to .github/workflows/pr-cleanup.yaml diff --git a/.github/workflows/deploypr.yaml b/.github/workflows/pr-deploy.yaml similarity index 100% rename from .github/workflows/deploypr.yaml rename to .github/workflows/pr-deploy.yaml From 864200d3ae4e3589923afce00fe70c68b11d5800 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 16:08:05 +0000 Subject: [PATCH 070/103] fix typo --- .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 d09f90c79b3b2..67173d49ffaf3 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -160,7 +160,7 @@ jobs: --set coder.image.tag=pr${{ env.PR_NUMBER }} \ --set coder.service.type=ClusterIP \ --set coder.env[0].name=CODER_ACCESS_URL \ - --set coder.env[0].value="" + --set coder.env[0].value="" \ --force - name: "Get deployment URL" From edb6c69226f106aa9a8ad41f52763648d86af447 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 16:10:03 +0000 Subject: [PATCH 071/103] fix bash synatax --- .github/workflows/pr-deploy.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 67173d49ffaf3..0ce632a89e0d2 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -174,8 +174,9 @@ jobs: - name: Send Slack notification run: | - curl -X POST -H 'Content-type: application/json' -d '{"msg":"Access the the depluyment for ${{ env.PR_NUMBER }} at \n${{env.CODER_ACCESS_URL}}"}' ${{ secrets.DOCS_LINK_SLACK_WEBHOOK }} + curl -X POST -H 'Content-type: application/json' -d '{"msg":"PR: ${{ env.PR_NUMBER }} deployed at \n${{env.CODER_ACCESS_URL}}"}' ${{ secrets.DOCS_LINK_SLACK_WEBHOOK }} echo "Sent Slack notification" + # TODO: Update Slack webhook to PR_DEPLOYMENTS_SLACK_WEBHOOK env: CODER_ACCESS_URL: ${{ steps.deployment_url.outputs.CODER_ACCESS_URL }} From 15b3395c7fe2f4079699e4a622d8f1c93f13fab6 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 16:18:09 +0000 Subject: [PATCH 072/103] register workflows --- .github/workflows/pr-cleanup.yaml | 2 +- .github/workflows/pr-deploy.yaml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml index a9a3131429223..fe2356f23e57d 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -2,7 +2,7 @@ name: Cleanup PR on: pull_request: - types: [closed] + # types: [closed] workflow_dispatch: inputs: pr_number: diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 0ce632a89e0d2..81c1acf6097ba 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -8,6 +8,7 @@ on: pr_number: description: "PR number" required: true + pull_request: env: REPO: ghcr.io/coder/coder-preview From 71fd390b4a3f78e2b1920ed047e707803bc82463 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 16:18:48 +0000 Subject: [PATCH 073/103] register workflows --- .github/workflows/pr-cleanup.yaml | 3 ++- .github/workflows/pr-deploy.yaml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml index fe2356f23e57d..4013d0bd8371f 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -1,8 +1,9 @@ # .github/workflows/pr-cleanup.yml name: Cleanup PR on: + push: pull_request: - # types: [closed] + types: [closed] workflow_dispatch: inputs: pr_number: diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 81c1acf6097ba..cd5517cb8e508 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -8,7 +8,7 @@ on: pr_number: description: "PR number" required: true - pull_request: + push: env: REPO: ghcr.io/coder/coder-preview From f9f409059b30ec89d30ae62a9f06ec8ffb6432da Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 16:19:05 +0000 Subject: [PATCH 074/103] remove push trigger --- .github/workflows/pr-cleanup.yaml | 1 - .github/workflows/pr-deploy.yaml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml index 4013d0bd8371f..a9a3131429223 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -1,7 +1,6 @@ # .github/workflows/pr-cleanup.yml name: Cleanup PR on: - push: pull_request: types: [closed] workflow_dispatch: diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index cd5517cb8e508..0ce632a89e0d2 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -8,7 +8,6 @@ on: pr_number: description: "PR number" required: true - push: env: REPO: ghcr.io/coder/coder-preview From 0d2747212ebcd2a8536c9cd0a42be219a3544657 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 16:33:56 +0000 Subject: [PATCH 075/103] upgrade helm --- .github/workflows/pr-cleanup.yaml | 2 +- .github/workflows/pr-deploy.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml index a9a3131429223..5ca37bb4ff371 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -36,7 +36,7 @@ jobs: tag: pr${{ env.PR_NUMBER }} - name: Install helm - uses: azure/setup-helm@v1 + uses: azure/setup-helm@v3 - name: Set up kubeconfig run: | diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 0ce632a89e0d2..125f5d5128b31 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -150,7 +150,7 @@ jobs: kubectl create namespace "pr${{ env.PR_NUMBER }}" - name: Install Helm - uses: azure/setup-helm@v1 + uses: azure/setup-helm@v3 - name: "Deploy" run: | From 6293bb6190a2cf39a10d7176e10706afb929a0e5 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 16:35:18 +0000 Subject: [PATCH 076/103] handle errors --- .github/workflows/pr-cleanup.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml index 5ca37bb4ff371..b6eb64f8d91be 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -48,8 +48,8 @@ jobs: - name: Delete helm release run: | set -euxo pipefail - helm delete --namespace "pr${{ env.PR_NUMBER }}" "pr${{ env.PR_NUMBER }}" + helm delete --namespace "pr${{ env.PR_NUMBER }}" "pr${{ env.PR_NUMBER }}" || echo "helm release not found" - name: "Remove PR namespace" run: | - kubectl delete namespace "pr${{ env.PR_NUMBER }}" + kubectl delete namespace "pr${{ env.PR_NUMBER }}" || echo "namespace not found" From cbbc54318783b0f1dba899ed43019307b937a5e3 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 16:44:53 +0000 Subject: [PATCH 077/103] fix bash --- .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 125f5d5128b31..3bf87b7758367 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -168,8 +168,8 @@ jobs: run: | set -euxo pipefail kubectl rollout status deployment/coder --namespace "pr${{ env.PR_NUMBER }}" - POD_NAME=$(kubectl get pods -n "pr${{ env.PR_NUMBER }} | awk 'NR==2{print $1}') - CODER_ACCESS_URL=(kubectl logs $POD_NAME -n pr8121 | grep "Web UI:" | awk -F ':' '{print $2":"$3}') + POD_NAME=$(kubectl get pods -n "pr${{ env.PR_NUMBER }}" | awk 'NR==2{print $1}') + CODER_ACESSS_URL=`kubectl logs $POD_NAME -n pr8121 | grep "Web UI:" | awk -F ':' '{print $2":"$3}'` echo "CODER_ACCESS_URL=$CODER_ACCESS_URL" >> $GITHUB_OUTPUT - name: Send Slack notification From 84723c20948c8ca7db3d48cce956429a45dcede4 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 16:46:24 +0000 Subject: [PATCH 078/103] update Slack channel --- .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 3bf87b7758367..8e38680079fdf 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -174,9 +174,8 @@ jobs: - name: Send Slack notification run: | - curl -X POST -H 'Content-type: application/json' -d '{"msg":"PR: ${{ env.PR_NUMBER }} deployed at \n${{env.CODER_ACCESS_URL}}"}' ${{ secrets.DOCS_LINK_SLACK_WEBHOOK }} + curl -X POST -H 'Content-type: application/json' -d '{"msg":"PR: ${{ env.PR_NUMBER }} deployed at \n${{env.CODER_ACCESS_URL}}"}' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }} echo "Sent Slack notification" - # TODO: Update Slack webhook to PR_DEPLOYMENTS_SLACK_WEBHOOK env: CODER_ACCESS_URL: ${{ steps.deployment_url.outputs.CODER_ACCESS_URL }} From f54996fdd333ef8aca6c33541060774ea751f519 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 16:55:08 +0000 Subject: [PATCH 079/103] fix typo --- .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 8e38680079fdf..b02f6adc538fb 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -169,7 +169,7 @@ jobs: set -euxo pipefail kubectl rollout status deployment/coder --namespace "pr${{ env.PR_NUMBER }}" POD_NAME=$(kubectl get pods -n "pr${{ env.PR_NUMBER }}" | awk 'NR==2{print $1}') - CODER_ACESSS_URL=`kubectl logs $POD_NAME -n pr8121 | grep "Web UI:" | awk -F ':' '{print $2":"$3}'` + CODER_ACCESS_URL=`kubectl logs $POD_NAME -n pr8121 | grep "Web UI:" | awk -F ':' '{print $2":"$3}'` echo "CODER_ACCESS_URL=$CODER_ACCESS_URL" >> $GITHUB_OUTPUT - name: Send Slack notification From b44dbd771a018d8af422d437ca15e108deed0939 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 17:01:47 +0000 Subject: [PATCH 080/103] change trigger word --- .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 b02f6adc538fb..efd2e378d11e2 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -23,7 +23,7 @@ concurrency: jobs: pr_commented: - if: ${{ github.event.issue.pull_request }} && contains(github.event.comment.body, '/review-pr') && github.event.comment.author_association == 'MEMBER' || github.event_name == 'workflow_dispatch' + if: ${{ github.event.issue.pull_request }} && contains(github.event.comment.body, '/deploy-pr') && github.event.comment.author_association == 'MEMBER' || github.event_name == 'workflow_dispatch' outputs: PR_NUMBER: ${{ steps.pr_number.outputs.PR_NUMBER }} COMMENT_ID: ${{ steps.comment_id.outputs.comment-id }} From 6e521a23f435fb06d9119a7d0b3f79811e82683f Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 21 Jun 2023 17:12:56 +0000 Subject: [PATCH 081/103] fix cleanup --- .github/workflows/pr-cleanup.yaml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml index b6eb64f8d91be..d44c25963e642 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -9,9 +9,6 @@ on: description: "PR number" required: true -env: - PR_NUMBER: if(${{ github.event_name == 'workflow_dispatch' }}, ${{ github.event.inputs.pr_number }}, ${{ github.event.pull_request.number }}) - permissions: packages: write @@ -19,13 +16,21 @@ jobs: pr-close: runs-on: "ubuntu-latest" steps: + - name: Get PR number + id: pr_number + run: | + if [ -z "${{ github.event.pull_request.number }}" ]; then + echo "PR_NUMBER=${{ github.event.inputs.pr_number }}" >> $GITHUB_OUTPUT + else + echo "PR_NUMBER=${{ github.event.inputs.pr_number }}" >> $GITHUB_OUTPUT + fi - name: Delete base image uses: bots-house/ghcr-delete-image-action@v1.1.0 with: owner: coder name: coder-preview-base token: ${{ secrets.GITHUB_TOKEN }} - tag: pr${{ env.PR_NUMBER }} + tag: pr${{ steps.pr_number.outputs.PR_NUMBER }} - name: Delete image uses: bots-house/ghcr-delete-image-action@v1.1.0 @@ -33,7 +38,7 @@ jobs: owner: coder name: coder-preview token: ${{ secrets.GITHUB_TOKEN }} - tag: pr${{ env.PR_NUMBER }} + tag: pr${{ steps.pr_number.outputs.PR_NUMBER }} - name: Install helm uses: azure/setup-helm@v3 @@ -48,8 +53,8 @@ jobs: - name: Delete helm release run: | set -euxo pipefail - helm delete --namespace "pr${{ env.PR_NUMBER }}" "pr${{ env.PR_NUMBER }}" || echo "helm release not found" + helm delete --namespace "pr${{ steps.pr_number.outputs.PR_NUMBER }}" "pr${{ steps.pr_number.outputs.PR_NUMBER }}" || echo "helm release not found" - name: "Remove PR namespace" run: | - kubectl delete namespace "pr${{ env.PR_NUMBER }}" || echo "namespace not found" + kubectl delete namespace "pr${{ steps.pr_number.outputs.PR_NUMBER }}" || echo "namespace not found" From 0c5a9d33a62fb349a9ce58240683ca8ad17f70e6 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 04:29:11 +0000 Subject: [PATCH 082/103] update comments --- .github/workflows/pr-cleanup.yaml | 1 - .github/workflows/pr-deploy.yaml | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml index d44c25963e642..52ffe7afa20a8 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -1,4 +1,3 @@ -# .github/workflows/pr-cleanup.yml name: Cleanup PR on: pull_request: diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index efd2e378d11e2..3b74e02721ef0 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -1,5 +1,4 @@ -# .github/workflows/deploypr.yml -# This action will trigger when a PR is opened or updated with a comment containing /review-pr by a member of the org. +# This action will trigger when a PR is commentted containing /review-pr by a member of the org. name: Deploy PR on: issue_comment: From b0469dc4a96701d64bc1a2cd1bbdfb0145afbd9a Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 05:10:31 +0000 Subject: [PATCH 083/103] do not build the base-image everytime --- .github/workflows/pr-cleanup.yaml | 3 +++ .github/workflows/pr-deploy.yaml | 33 +++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml index 52ffe7afa20a8..3fcfa304b28f7 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -31,7 +31,10 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} tag: pr${{ steps.pr_number.outputs.PR_NUMBER }} + # PR base image will mostly not exist and previous step will fail + # so we ignore the error and continue - name: Delete image + if: always() uses: bots-house/ghcr-delete-image-action@v1.1.0 with: owner: coder diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 3b74e02721ef0..91a8414496945 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -25,23 +25,26 @@ jobs: if: ${{ github.event.issue.pull_request }} && contains(github.event.comment.body, '/deploy-pr') && github.event.comment.author_association == 'MEMBER' || github.event_name == 'workflow_dispatch' outputs: PR_NUMBER: ${{ steps.pr_number.outputs.PR_NUMBER }} + PR_TITLE: ${{ steps.pr_number.outputs.PR_TITLE }} COMMENT_ID: ${{ steps.comment_id.outputs.comment-id }} CODER_BASE_IMAGE_TAG: ${{ steps.set_tags.outputs.CODER_BASE_IMAGE_TAG }} CODER_IMAGE_TAG: ${{ steps.set_tags.outputs.CODER_IMAGE_TAG }} runs-on: "ubuntu-latest" steps: - - name: Get PR number + - name: Get PR number and title id: pr_number run: | set -euxo pipefail if [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then PR_NUMBER=${{ github.event.inputs.pr_number }} + PR_TITLE=$(curl -sSL -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/coder/coder/pulls/$PR_NUMBER | jq -r '.title') else PR_NUMBER=${{ github.event.issue.number }} + PR_TITLE=${{ github.event.issue.title }} fi - echo $PR_NUMBER echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT + echo "PR_TITLE=$PR_TITLE" >> $GITHUB_OUTPUT - name: Set required tags id: set_tags @@ -61,7 +64,6 @@ jobs: comment-author: "github-actions[bot]" body-includes: This deployment will be deleted when the PR is closed - # Comment on the PR - name: Comment on PR id: comment_id uses: peter-evans/create-or-update-comment@v3 @@ -77,15 +79,14 @@ jobs: needs: pr_commented runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }} env: - # Necessary for Docker manifest DOCKER_CLI_EXPERIMENTAL: "enabled" - CODER_BASE_IMAGE_TAG: ${{ needs.pr_commented.outputs.coder_base_image_tag }} CODER_IMAGE_TAG: ${{ needs.pr_commented.outputs.coder_image_tag }} PR_NUMBER: ${{ needs.pr_commented.outputs.pr_number }} steps: - uses: actions/checkout@v3 with: fetch-depth: 0 + - uses: ./.github/actions/setup-go - uses: ./.github/actions/setup-node @@ -101,17 +102,29 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Check if the contents of Dockerfile.base have changed + id: check_base_dockerfile + run: | + set -euxo pipefail + if [[ $(git diff --name-only HEAD^ HEAD | grep Dockerfile.base) ]]; then + echo "changed=true" >> $GITHUB_OUTPUT + else + echo "changed=false" >> $GITHUB_OUTPUT + fi + - name: Create empty base-build-context directory + if: steps.check_base_dockerfile.outputs.changed == 'true' run: mkdir base-build-context - name: Build and push base Docker image + if: steps.check_base_dockerfile.outputs.changed == 'true' uses: docker/build-push-action@v4 with: context: base-build-context file: scripts/Dockerfile.base platforms: linux/amd64 push: true - tags: ${{ env.CODER_BASE_IMAGE_TAG }} + tags: ${{ needs.pr_commented.outputs.coder_base_image_tag }} - name: Build and push Linux amd64 Docker image run: | @@ -120,9 +133,8 @@ jobs: make gen/mark-fresh make -j build/coder_linux_amd64 ./scripts/build_docker.sh --arch amd64 --target ${{env.CODER_IMAGE_TAG }} --push build/coder_*_linux_amd64 - # env: - CODER_BASE_IMAGE_TAG: ${{ env.CODER_BASE_IMAGE_TAG }} + CODER_BASE_IMAGE_TAG: ${{ steps.check_base_dockerfile.outputs.changed == 'true' && needs.pr_commented.outputs.coder_base_image_tag || 'ghcr.io/coder/coder-base:latest' }} deployment: needs: [build, pr_commented] @@ -131,6 +143,7 @@ jobs: env: CODER_IMAGE_TAG: ${{ needs.pr_commented.outputs.CODER_IMAGE_TAG }} PR_NUMBER: ${{ needs.pr_commented.outputs.PR_NUMBER }} + PR_TITLE: ${{ needs.pr_commented.outputs.PR_TITLE }} steps: - uses: actions/checkout@v3 @@ -168,12 +181,12 @@ jobs: set -euxo pipefail kubectl rollout status deployment/coder --namespace "pr${{ env.PR_NUMBER }}" POD_NAME=$(kubectl get pods -n "pr${{ env.PR_NUMBER }}" | awk 'NR==2{print $1}') - CODER_ACCESS_URL=`kubectl logs $POD_NAME -n pr8121 | grep "Web UI:" | awk -F ':' '{print $2":"$3}'` + CODER_ACCESS_URL=`kubectl logs $POD_NAME -n "pr${{ env.PR_NUMBER }}" | grep "Web UI:" | awk -F ':' '{print $2":"$3}' | awk '{$1=$1};1'` echo "CODER_ACCESS_URL=$CODER_ACCESS_URL" >> $GITHUB_OUTPUT - name: Send Slack notification run: | - curl -X POST -H 'Content-type: application/json' -d '{"msg":"PR: ${{ env.PR_NUMBER }} deployed at \n${{env.CODER_ACCESS_URL}}"}' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }} + curl -X POST -H 'Content-type: application/json' -d '{"msg":"${{ env.PR_TITLE }}\ndeployed at\n${{env.CODER_ACCESS_URL}}"}' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }} echo "Sent Slack notification" env: CODER_ACCESS_URL: ${{ steps.deployment_url.outputs.CODER_ACCESS_URL }} From d24ad7f05c93bf23b1f5da48751f516dbc09b100 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 05:17:11 +0000 Subject: [PATCH 084/103] run cleanup jobs always --- .github/workflows/pr-cleanup.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml index 3fcfa304b28f7..7e6eb93d0f787 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -46,6 +46,7 @@ jobs: uses: azure/setup-helm@v3 - name: Set up kubeconfig + if: always() run: | set -euxo pipefail mkdir -p ~/.kube @@ -53,10 +54,12 @@ jobs: export KUBECONFIG=~/.kube/config - name: Delete helm release + if: always() run: | set -euxo pipefail helm delete --namespace "pr${{ steps.pr_number.outputs.PR_NUMBER }}" "pr${{ steps.pr_number.outputs.PR_NUMBER }}" || echo "helm release not found" - name: "Remove PR namespace" + if: always() run: | kubectl delete namespace "pr${{ steps.pr_number.outputs.PR_NUMBER }}" || echo "namespace not found" From 76d5d59a6f26ea9f26d0cd8cc6fc056ea3fe9200 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 05:28:41 +0000 Subject: [PATCH 085/103] compute diff with `main` --- .github/workflows/pr-deploy.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 91a8414496945..68def96543533 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -106,7 +106,7 @@ jobs: id: check_base_dockerfile run: | set -euxo pipefail - if [[ $(git diff --name-only HEAD^ HEAD | grep Dockerfile.base) ]]; then + if [[ $(git diff --name-only main...HEAD | grep Dockerfile.base) ]]; then echo "changed=true" >> $GITHUB_OUTPUT else echo "changed=false" >> $GITHUB_OUTPUT @@ -136,7 +136,7 @@ jobs: env: CODER_BASE_IMAGE_TAG: ${{ steps.check_base_dockerfile.outputs.changed == 'true' && needs.pr_commented.outputs.coder_base_image_tag || 'ghcr.io/coder/coder-base:latest' }} - deployment: + deploy: needs: [build, pr_commented] if: needs.build.result == 'success' runs-on: "ubuntu-latest" @@ -164,7 +164,7 @@ jobs: - name: Install Helm uses: azure/setup-helm@v3 - - name: "Deploy" + - name: "Install Helm chart" run: | helm upgrade --install pr${{ env.PR_NUMBER }} ./helm \ --namespace "pr${{ env.PR_NUMBER }}" \ From 66ea3504ce39f43330ca14c62a9335cc892f5bd6 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 05:46:26 +0000 Subject: [PATCH 086/103] add PR URL to slack notification --- .github/workflows/pr-deploy.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 68def96543533..c3b8c3cdb29e4 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -26,6 +26,7 @@ jobs: outputs: PR_NUMBER: ${{ steps.pr_number.outputs.PR_NUMBER }} PR_TITLE: ${{ steps.pr_number.outputs.PR_TITLE }} + PR_URL: ${{ steps.pr_number.outputs.PR_URL }} COMMENT_ID: ${{ steps.comment_id.outputs.comment-id }} CODER_BASE_IMAGE_TAG: ${{ steps.set_tags.outputs.CODER_BASE_IMAGE_TAG }} CODER_IMAGE_TAG: ${{ steps.set_tags.outputs.CODER_IMAGE_TAG }} @@ -43,6 +44,7 @@ jobs: PR_NUMBER=${{ github.event.issue.number }} PR_TITLE=${{ github.event.issue.title }} fi + echo "PR_URL="https://github.com/coder/coder/pull/$PR_NUMBER" >> $GITHUB_OUTPUT echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT echo "PR_TITLE=$PR_TITLE" >> $GITHUB_OUTPUT @@ -144,6 +146,7 @@ jobs: CODER_IMAGE_TAG: ${{ needs.pr_commented.outputs.CODER_IMAGE_TAG }} PR_NUMBER: ${{ needs.pr_commented.outputs.PR_NUMBER }} PR_TITLE: ${{ needs.pr_commented.outputs.PR_TITLE }} + PR_URL: ${{ needs.pr_commented.outputs.PR_URL }} steps: - uses: actions/checkout@v3 @@ -186,7 +189,13 @@ jobs: - name: Send Slack notification run: | - curl -X POST -H 'Content-type: application/json' -d '{"msg":"${{ env.PR_TITLE }}\ndeployed at\n${{env.CODER_ACCESS_URL}}"}' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }} + curl -X POST -H 'Content-type: application/json' \ + -d '{ \ + "pr_number": "'${{ env.PR_NUMBER }}'", \ + "pr_url": "'${{ env.PR_URL }}'", \ + "pr_title": "'${{ env.PR_TITLE }}'", \ + "pr_access_url": "'${{ env.CODER_ACCESS_URL }}'" \ + }' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }} echo "Sent Slack notification" env: CODER_ACCESS_URL: ${{ steps.deployment_url.outputs.CODER_ACCESS_URL }} From 65768ac15f5708741af326317f9be8a3ededee4b Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 05:48:23 +0000 Subject: [PATCH 087/103] typo! --- .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 c3b8c3cdb29e4..55c42c6cddb84 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -44,7 +44,7 @@ jobs: PR_NUMBER=${{ github.event.issue.number }} PR_TITLE=${{ github.event.issue.title }} fi - echo "PR_URL="https://github.com/coder/coder/pull/$PR_NUMBER" >> $GITHUB_OUTPUT + echo "PR_URL=https://github.com/coder/coder/pull/$PR_NUMBER" >> $GITHUB_OUTPUT echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT echo "PR_TITLE=$PR_TITLE" >> $GITHUB_OUTPUT From e38d5af383ebfd1bbbc25b4b1e1125589f1f9697 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 06:37:45 +0000 Subject: [PATCH 088/103] remove preview-base-image and optimize build --- .github/workflows/pr-deploy.yaml | 38 +++++++++----------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 55c42c6cddb84..feaa4263b4706 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -104,39 +104,21 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Check if the contents of Dockerfile.base have changed - id: check_base_dockerfile - run: | - set -euxo pipefail - if [[ $(git diff --name-only main...HEAD | grep Dockerfile.base) ]]; then - echo "changed=true" >> $GITHUB_OUTPUT - else - echo "changed=false" >> $GITHUB_OUTPUT - fi - - - name: Create empty base-build-context directory - if: steps.check_base_dockerfile.outputs.changed == 'true' - run: mkdir base-build-context - - - name: Build and push base Docker image - if: steps.check_base_dockerfile.outputs.changed == 'true' - uses: docker/build-push-action@v4 - with: - context: base-build-context - file: scripts/Dockerfile.base - platforms: linux/amd64 - push: true - tags: ${{ needs.pr_commented.outputs.coder_base_image_tag }} - - name: Build and push Linux amd64 Docker image run: | set -euxo pipefail go mod download make gen/mark-fresh - make -j build/coder_linux_amd64 - ./scripts/build_docker.sh --arch amd64 --target ${{env.CODER_IMAGE_TAG }} --push build/coder_*_linux_amd64 - env: - CODER_BASE_IMAGE_TAG: ${{ steps.check_base_dockerfile.outputs.changed == 'true' && needs.pr_commented.outputs.coder_base_image_tag || 'ghcr.io/coder/coder-base:latest' }} + export DOCKER_IMAGE_NO_PREREQUISITES=true + version="$(./scripts/version.sh)" + image_job="build/coder_${version}_linux_amd64.tag" + export CODER_IMAGE_BUILD_BASE_TAG="$(CODER_IMAGE_BASE=coder-base ./scripts/image_tag.sh --version "$version")" + ./scripts/build_docker.sh \ + --arch amd64 \ + --target ${{ env.CODER_IMAGE_TAG }} \ + --version $version \ + --push \ + $image_job deploy: needs: [build, pr_commented] From 941fa3c26a8587cea99f215e9d0e13f8b24034df Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 06:56:48 +0000 Subject: [PATCH 089/103] fix build target --- .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 feaa4263b4706..bdc1bd0b37bce 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -111,14 +111,14 @@ jobs: make gen/mark-fresh export DOCKER_IMAGE_NO_PREREQUISITES=true version="$(./scripts/version.sh)" - image_job="build/coder_${version}_linux_amd64.tag" export CODER_IMAGE_BUILD_BASE_TAG="$(CODER_IMAGE_BASE=coder-base ./scripts/image_tag.sh --version "$version")" + make -j build/coder_linux_amd64 ./scripts/build_docker.sh \ --arch amd64 \ --target ${{ env.CODER_IMAGE_TAG }} \ --version $version \ --push \ - $image_job + build/coder_linux_amd64 deploy: needs: [build, pr_commented] From 97442697ad728eed5ef4ae464cdfde22f2b6b9f1 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 07:21:33 +0000 Subject: [PATCH 090/103] hide ACCESS_URL from logs --- .github/workflows/pr-deploy.yaml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index bdc1bd0b37bce..8ba30d8fe667d 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -171,16 +171,14 @@ jobs: - name: Send Slack notification run: | - curl -X POST -H 'Content-type: application/json' \ - -d '{ \ - "pr_number": "'${{ env.PR_NUMBER }}'", \ - "pr_url": "'${{ env.PR_URL }}'", \ - "pr_title": "'${{ env.PR_TITLE }}'", \ - "pr_access_url": "'${{ env.CODER_ACCESS_URL }}'" \ + curl -sS -X POST -H 'Content-type: application/json' \ + -d '{ + "pr_number": "'${{ env.PR_NUMBER }}'", + "pr_url": "'${{ env.PR_URL }}'", + "pr_title": "'${{ env.PR_TITLE }}'", + "pr_access_url": "'${{ steps.deployment_url.outputs.CODER_ACCESS_URL }}'" }' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }} - echo "Sent Slack notification" - env: - CODER_ACCESS_URL: ${{ steps.deployment_url.outputs.CODER_ACCESS_URL }} + echo "Slack notification sent" - name: Comment on PR uses: peter-evans/create-or-update-comment@v3 From d7a7af1834c88fdf48209d444caa8b93d06a50e3 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 07:34:17 +0000 Subject: [PATCH 091/103] format slack message --- .github/workflows/pr-deploy.yaml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 8ba30d8fe667d..b3fafa5440c8d 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -173,11 +173,10 @@ jobs: run: | curl -sS -X POST -H 'Content-type: application/json' \ -d '{ - "pr_number": "'${{ env.PR_NUMBER }}'", - "pr_url": "'${{ env.PR_URL }}'", - "pr_title": "'${{ env.PR_TITLE }}'", - "pr_access_url": "'${{ steps.deployment_url.outputs.CODER_ACCESS_URL }}'" - }' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }} + "pr_number": "'"${{ env.PR_NUMBER }}"'", + "pr_url": "'"${{ env.PR_URL }}"'", + "pr_title": "'"${{ env.PR_TITLE }}"'", + "pr_access_url": "'"${{ steps.deployment_url.outputs.CODER_ACCESS_URL }}"'" }' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }} echo "Slack notification sent" - name: Comment on PR From 3e68f6ed46248a9aec403359f7acb98a8d14a429 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 07:34:42 +0000 Subject: [PATCH 092/103] hide errors too --- .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 b3fafa5440c8d..3c4010d674693 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -171,7 +171,7 @@ jobs: - name: Send Slack notification run: | - curl -sS -X POST -H 'Content-type: application/json' \ + curl -s -X POST -H 'Content-type: application/json' \ -d '{ "pr_number": "'"${{ env.PR_NUMBER }}"'", "pr_url": "'"${{ env.PR_URL }}"'", From 137ef1b1e9cb6b1fc3d9724077f3f33aff4b6fbf Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 07:52:21 +0000 Subject: [PATCH 093/103] send output to /dev/null --- .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 3c4010d674693..719d323932f42 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -171,7 +171,7 @@ jobs: - name: Send Slack notification run: | - curl -s -X POST -H 'Content-type: application/json' \ + curl -s -o /dev/null -X POST -H 'Content-type: application/json' \ -d '{ "pr_number": "'"${{ env.PR_NUMBER }}"'", "pr_url": "'"${{ env.PR_URL }}"'", From 58d90fd3ee7459ac50411fef8bb5a90daf5434ef Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 08:07:22 +0000 Subject: [PATCH 094/103] try masking the URL --- .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 719d323932f42..8e89eac4a60c5 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -167,6 +167,7 @@ jobs: kubectl rollout status deployment/coder --namespace "pr${{ env.PR_NUMBER }}" POD_NAME=$(kubectl get pods -n "pr${{ env.PR_NUMBER }}" | awk 'NR==2{print $1}') CODER_ACCESS_URL=`kubectl logs $POD_NAME -n "pr${{ env.PR_NUMBER }}" | grep "Web UI:" | awk -F ':' '{print $2":"$3}' | awk '{$1=$1};1'` + echo "::add-mask::$CODER_ACCESS_URL" echo "CODER_ACCESS_URL=$CODER_ACCESS_URL" >> $GITHUB_OUTPUT - name: Send Slack notification From 81e4b1d3a20b7f0941e06072746ec6b823cb5de8 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 08:09:05 +0000 Subject: [PATCH 095/103] remove base-image cleanup --- .github/workflows/pr-cleanup.yaml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml index 7e6eb93d0f787..c6fa181b73685 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -23,18 +23,8 @@ jobs: else echo "PR_NUMBER=${{ github.event.inputs.pr_number }}" >> $GITHUB_OUTPUT fi - - name: Delete base image - uses: bots-house/ghcr-delete-image-action@v1.1.0 - with: - owner: coder - name: coder-preview-base - token: ${{ secrets.GITHUB_TOKEN }} - tag: pr${{ steps.pr_number.outputs.PR_NUMBER }} - # PR base image will mostly not exist and previous step will fail - # so we ignore the error and continue - name: Delete image - if: always() uses: bots-house/ghcr-delete-image-action@v1.1.0 with: owner: coder From 2ef6e5b7e531bc20480c83311de1db7e7a48615f Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 08:16:32 +0000 Subject: [PATCH 096/103] install helm always --- .github/workflows/pr-cleanup.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml index c6fa181b73685..a48c617411b22 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -33,6 +33,7 @@ jobs: tag: pr${{ steps.pr_number.outputs.PR_NUMBER }} - name: Install helm + if: always() uses: azure/setup-helm@v3 - name: Set up kubeconfig From eaf3912267d138e933d47bccbbdb85582c002590 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Thu, 22 Jun 2023 11:17:37 +0300 Subject: [PATCH 097/103] Discard changes to .github/workflows/ci.yaml --- .github/workflows/ci.yaml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 26b6c179fe6e7..6ad6f4e27d82b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -34,8 +34,7 @@ jobs: go: ${{ steps.filter.outputs.go }} ts: ${{ steps.filter.outputs.ts }} k8s: ${{ steps.filter.outputs.k8s }} - # ci: ${{ steps.filter.outputs.ci }} - ci: false # TODO: remove this before merging + ci: ${{ steps.filter.outputs.ci }} steps: - uses: actions/checkout@v3 # For pull requests it's not necessary to checkout the code @@ -95,8 +94,6 @@ jobs: lint: runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }} - needs: changes - if: needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main' # TODO Remove this before merging steps: - name: Checkout uses: actions/checkout@v3 @@ -147,8 +144,7 @@ jobs: timeout-minutes: 8 runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }} needs: changes - # if: needs.changes.outputs.docs-only == 'false' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main' - if: needs.changes.outputs.ci == 'true' # TODO Remove this before merging + if: needs.changes.outputs.docs-only == 'false' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main' steps: - uses: actions/checkout@v3 From d0ada5804cf0b1dfbd0b6bd535e92c754f43996f Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 09:37:08 +0000 Subject: [PATCH 098/103] use subshell to hide CODER_ACCESS_URL --- .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 8e89eac4a60c5..a9d4a8879ff0c 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -166,7 +166,7 @@ jobs: set -euxo pipefail kubectl rollout status deployment/coder --namespace "pr${{ env.PR_NUMBER }}" POD_NAME=$(kubectl get pods -n "pr${{ env.PR_NUMBER }}" | awk 'NR==2{print $1}') - CODER_ACCESS_URL=`kubectl logs $POD_NAME -n "pr${{ env.PR_NUMBER }}" | grep "Web UI:" | awk -F ':' '{print $2":"$3}' | awk '{$1=$1};1'` + CODER_ACCESS_URL=$(kubectl logs $POD_NAME -n "pr${{ env.PR_NUMBER }}" | grep "Web UI:" | awk -F ':' '{print $2":"$3}' | awk '{$1=$1};1') echo "::add-mask::$CODER_ACCESS_URL" echo "CODER_ACCESS_URL=$CODER_ACCESS_URL" >> $GITHUB_OUTPUT From 8e7d96c06915e65498cdc4e7143a5c3ecf404d3c Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 09:41:37 +0000 Subject: [PATCH 099/103] set up GITHUB_TOKEN for helm --- .github/workflows/pr-cleanup.yaml | 2 ++ .github/workflows/pr-deploy.yaml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml index a48c617411b22..af9af5be8abc8 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -35,6 +35,8 @@ jobs: - name: Install helm if: always() uses: azure/setup-helm@v3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Set up kubeconfig if: always() diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index a9d4a8879ff0c..a8d90dd86a0fe 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -148,6 +148,8 @@ jobs: - name: Install Helm uses: azure/setup-helm@v3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: "Install Helm chart" run: | From 6844cbcdeac63111ae250b4903a2a9d928e045a8 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 09:47:36 +0000 Subject: [PATCH 100/103] fixup! --- .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 a8d90dd86a0fe..c928df4730cfe 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -165,7 +165,7 @@ jobs: - name: "Get deployment URL" id: deployment_url run: | - set -euxo pipefail + set -euo pipefail kubectl rollout status deployment/coder --namespace "pr${{ env.PR_NUMBER }}" POD_NAME=$(kubectl get pods -n "pr${{ env.PR_NUMBER }}" | awk 'NR==2{print $1}') CODER_ACCESS_URL=$(kubectl logs $POD_NAME -n "pr${{ env.PR_NUMBER }}" | grep "Web UI:" | awk -F ':' '{print $2":"$3}' | awk '{$1=$1};1') From 9ed4c0c336fdd16bf4f51c93635f92cf8981155d Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 09:50:41 +0000 Subject: [PATCH 101/103] rename job to cleanup --- .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 af9af5be8abc8..b47fcf252d09d 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -12,7 +12,7 @@ permissions: packages: write jobs: - pr-close: + cleanup: runs-on: "ubuntu-latest" steps: - name: Get PR number From 1a22346d8bbeae912bb05feeeba6b01cd929754e Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 10:09:04 +0000 Subject: [PATCH 102/103] helm is pre-installed --- .github/workflows/pr-cleanup.yaml | 6 ------ .github/workflows/pr-deploy.yaml | 5 ----- 2 files changed, 11 deletions(-) diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml index b47fcf252d09d..3b88a55565a92 100644 --- a/.github/workflows/pr-cleanup.yaml +++ b/.github/workflows/pr-cleanup.yaml @@ -32,12 +32,6 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} tag: pr${{ steps.pr_number.outputs.PR_NUMBER }} - - name: Install helm - if: always() - uses: azure/setup-helm@v3 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Set up kubeconfig if: always() run: | diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index c928df4730cfe..99e6c1b0ba695 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -146,11 +146,6 @@ jobs: kubectl delete namespace "pr${{ env.PR_NUMBER }}" || true kubectl create namespace "pr${{ env.PR_NUMBER }}" - - name: Install Helm - uses: azure/setup-helm@v3 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: "Install Helm chart" run: | helm upgrade --install pr${{ env.PR_NUMBER }} ./helm \ From c03901df655e752c2d691289244793a562d26eaa Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 22 Jun 2023 14:24:47 +0000 Subject: [PATCH 103/103] add link to slack channel. --- .github/workflows/pr-deploy.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 99e6c1b0ba695..8a451de835b88 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -74,7 +74,7 @@ jobs: issue-number: ${{ steps.pr_number.outputs.PR_NUMBER }} edit-mode: replace body: | - :rocket: Deploying PR ${{ steps.pr_number.outputs.PR_NUMBER }} + :rocket: Deploying PR ${{ steps.pr_number.outputs.PR_NUMBER }} ... :warning: This deployment will be deleted when the PR is closed. build: @@ -185,5 +185,6 @@ jobs: comment-id: ${{ needs.pr_commented.outputs.COMMENT_ID }} body: | :heavy_check_mark: Deployed PR ${{ env.PR_NUMBER }} successfully. + :rocket: Access the deployment link [here](https://codercom.slack.com/archives/C05DNE982E8). :warning: This deployment will be deleted when the PR is closed. reactions: "+1"