From 2520ae93934c3c523191bfed3c57cfd89292aee1 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Mon, 15 Jan 2024 17:28:36 -1000 Subject: [PATCH 01/35] WIP --- .../app/bundles/comments/rescript/CommentForm/CommentForm.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/app/bundles/comments/rescript/CommentForm/CommentForm.res b/client/app/bundles/comments/rescript/CommentForm/CommentForm.res index db964269..c075452d 100644 --- a/client/app/bundles/comments/rescript/CommentForm/CommentForm.res +++ b/client/app/bundles/comments/rescript/CommentForm/CommentForm.res @@ -90,7 +90,7 @@ let make = (~fetchData) => { } let forms: array = [ - {formName: "Horizontal Form", formType: Horizontal}, + {formName: "Horizontal Form XXXX", formType: Horizontal}, {formName: "Inline Form", formType: Inline}, {formName: "Stacked Form", formType: Stacked}, ] From 3243e05538955bd9d884889f805fc5eb47a51856 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Mon, 15 Jan 2024 22:29:33 -1000 Subject: [PATCH 02/35] WIP --- .../deploy-to-control-plane-review.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index 99ca9b90..0e90542b 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -6,6 +6,14 @@ name: Deploy Review App to Control Plane on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: +# inputs: +# pr_number: +# description: 'Pull request number' +# required: false +# Triggers the workflow on pull request events +# pull_request: +# branches: +# - main # or the branch you want to trigger the workflow issue_comment: types: [created, edited] @@ -23,7 +31,16 @@ jobs: - name: Check out the repo uses: actions/checkout@v2 + - name: Extract PR number from branch name + run: | + PR_NUMBER=$(echo ${GITHUB_REF#refs/heads/pr-}) + if [ -z "$PR_NUMBER" ]; then + echo "PR_NUMBER is not set. Aborting." + exit 1 + fi + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV + - uses: ./.github/actions/deploy-to-control-plane with: - app_name: qa-react-webpack-rails-tutorial-pr-${{ github.event.pull_request.number }} + app_name: qa-react-webpack-rails-tutorial-pr-${{ env.PR_NUMBER }} org: ${{ secrets.CPLN_ORG_STAGING }} From e4093409c85d1cfe41a4e60bd5b7b9ed7a79924b Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Mon, 15 Jan 2024 22:38:26 -1000 Subject: [PATCH 03/35] WIP --- .github/workflows/deploy-to-control-plane-review.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index 0e90542b..203cba7a 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -31,9 +31,11 @@ jobs: - name: Check out the repo uses: actions/checkout@v2 - - name: Extract PR number from branch name + - name: Get PR number run: | - PR_NUMBER=$(echo ${GITHUB_REF#refs/heads/pr-}) + PR_NUMBER=$(curl --location --request GET 'https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open' \ + --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ + | jq '.[] | select(.head.ref=="'${{ github.ref }}'") | .number') if [ -z "$PR_NUMBER" ]; then echo "PR_NUMBER is not set. Aborting." exit 1 From ed63ba65515943ddab0f7c5029b6ecf873eca033 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Mon, 15 Jan 2024 22:57:44 -1000 Subject: [PATCH 04/35] WIP --- .github/workflows/deploy-to-control-plane-review.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index 203cba7a..9d0a039d 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -31,11 +31,13 @@ jobs: - name: Check out the repo uses: actions/checkout@v2 + - name: Get PR number run: | - PR_NUMBER=$(curl --location --request GET 'https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open' \ - --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ - | jq '.[] | select(.head.ref=="'${{ github.ref }}'") | .number') + API_RESPONSE=$(curl --location --request GET 'https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open' \ + --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}') + echo "API_RESPONSE: $API_RESPONSE" + PR_NUMBER=$(echo $API_RESPONSE | jq '.[] | select(.head.ref=="'${{ github.ref }}'") | .number') if [ -z "$PR_NUMBER" ]; then echo "PR_NUMBER is not set. Aborting." exit 1 From cd2e0eb670bd21837b2e71f358b1b29c04f24c90 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Mon, 15 Jan 2024 23:35:28 -1000 Subject: [PATCH 05/35] WIP --- .github/workflows/deploy-to-control-plane-review.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index 9d0a039d..978720f4 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -34,6 +34,7 @@ jobs: - name: Get PR number run: | + echo "GITHUB_REPOSITORY: '$GITHUB_REPOSITORY'" API_RESPONSE=$(curl --location --request GET 'https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open' \ --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}') echo "API_RESPONSE: $API_RESPONSE" From 391515c818f4312ffbf2833e420cba930d758c2e Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Mon, 15 Jan 2024 23:38:36 -1000 Subject: [PATCH 06/35] WIP --- .github/workflows/deploy-to-control-plane-review.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index 978720f4..1e26dca1 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -31,14 +31,14 @@ jobs: - name: Check out the repo uses: actions/checkout@v2 - - name: Get PR number run: | - echo "GITHUB_REPOSITORY: '$GITHUB_REPOSITORY'" - API_RESPONSE=$(curl --location --request GET 'https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open' \ + echo "GITHUB_REPOSITORY: \"$GITHUB_REPOSITORY\"" + API_RESPONSE=$(curl --location --request GET "https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open" \ --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}') echo "API_RESPONSE: $API_RESPONSE" PR_NUMBER=$(echo $API_RESPONSE | jq '.[] | select(.head.ref=="'${{ github.ref }}'") | .number') + echo "PR_NUMBER: $PR_NUMBER" if [ -z "$PR_NUMBER" ]; then echo "PR_NUMBER is not set. Aborting." exit 1 From 2de81259c8c6e053c217cae66e6726fdf101f149 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Mon, 15 Jan 2024 23:48:12 -1000 Subject: [PATCH 07/35] WIP --- .github/workflows/deploy-to-control-plane-review.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index 1e26dca1..1145ab77 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -34,6 +34,7 @@ jobs: - name: Get PR number run: | echo "GITHUB_REPOSITORY: \"$GITHUB_REPOSITORY\"" + echo "github.ref: \"$GITHUB_REF\"" API_RESPONSE=$(curl --location --request GET "https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open" \ --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}') echo "API_RESPONSE: $API_RESPONSE" From a3b9d3c00f13fb8d14b5e4b47c38d6d4e2df2a33 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Mon, 15 Jan 2024 23:55:29 -1000 Subject: [PATCH 08/35] WIP --- .github/workflows/deploy-to-control-plane-review.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index 1145ab77..bf1ebbd6 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -34,11 +34,13 @@ jobs: - name: Get PR number run: | echo "GITHUB_REPOSITORY: \"$GITHUB_REPOSITORY\"" - echo "github.ref: \"$GITHUB_REF\"" + REF=${{ github.ref }} + REF=${REF#refs/heads/} # Remove 'refs/heads/' prefix + echo "REF: \"$REF\"" API_RESPONSE=$(curl --location --request GET "https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open" \ --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}') echo "API_RESPONSE: $API_RESPONSE" - PR_NUMBER=$(echo $API_RESPONSE | jq '.[] | select(.head.ref=="'${{ github.ref }}'") | .number') + PR_NUMBER=$(echo $API_RESPONSE | jq '.[] | select(.head.ref=="'$REF'") | .number') echo "PR_NUMBER: $PR_NUMBER" if [ -z "$PR_NUMBER" ]; then echo "PR_NUMBER is not set. Aborting." From 5ffc36565d95160e20b7d948fead35f68c3b75dd Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sun, 21 Jan 2024 21:40:54 -1000 Subject: [PATCH 09/35] =?UTF-8?q?provision=20the=20app=CB=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .controlplane/readme.md | 2 +- .github/actions/deploy-to-control-plane/action.yml | 10 +++++++++- .github/workflows/deploy-to-control-plane-review.yml | 7 ++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.controlplane/readme.md b/.controlplane/readme.md index 5588cfa2..cfab19a8 100644 --- a/.controlplane/readme.md +++ b/.controlplane/readme.md @@ -74,7 +74,7 @@ export APP_NAME=react-webpack-rails-tutorial # Provision all infrastructure on Control Plane. # app react-webpack-rails-tutorial will be created per definition in .controlplane/controlplane.yml -cpflow apply-template gvc postgres redis rails daily-task -a $APP_NAME +cpflow setup-app -a $APP_NAME # Build and push docker image to Control Plane repository # Note, may take many minutes. Be patient. diff --git a/.github/actions/deploy-to-control-plane/action.yml b/.github/actions/deploy-to-control-plane/action.yml index 9d4e5090..6ba1d373 100644 --- a/.github/actions/deploy-to-control-plane/action.yml +++ b/.github/actions/deploy-to-control-plane/action.yml @@ -38,7 +38,6 @@ runs: shell: bash run: | cpln profile update default - # cpln profile update default --token ${CPLN_TOKEN} # Caching step - uses: actions/cache@v2 @@ -49,6 +48,15 @@ runs: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile', '**/package.json', '**/yarn.lock') }} ${{ runner.os }}-docker- + - name: cpflow setup-app + shell: bash + run: | + if ! cpflow exists -a ${{ inputs.app_name }} ; then + cpflow setup-app -a ${{ inputs.app_name }} + fi + # Provision all infrastructure on Control Plane. + # app react-webpack-rails-tutorial will be created per definition in .controlplane/controlplane.yml + - name: cpflow build-image shell: bash run: | diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index bf1ebbd6..7355f1c9 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -48,7 +48,12 @@ jobs: fi echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV + - name: Get App Name + run: | + echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ env.PR_NUMBER }}" >> $GITHUB_ENV + echo "App Name: ${{ env.APP_NAME }}" + - uses: ./.github/actions/deploy-to-control-plane with: - app_name: qa-react-webpack-rails-tutorial-pr-${{ env.PR_NUMBER }} + app_name: ${{ env.APP_NAME }} org: ${{ secrets.CPLN_ORG_STAGING }} From 84d7b9f2569b5f7838764f69ed88c4ac5e80d874 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sun, 21 Jan 2024 22:06:30 -1000 Subject: [PATCH 10/35] WIP --- .github/workflows/deploy-to-control-plane-review.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index 7355f1c9..02650aa5 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -50,6 +50,7 @@ jobs: - name: Get App Name run: | + echo "PR_NUMBER: ${{ env.PR_NUMBER }}" echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ env.PR_NUMBER }}" >> $GITHUB_ENV echo "App Name: ${{ env.APP_NAME }}" From 1174ee7153bcf17cd8d299e5f907c20c4c865462 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sun, 21 Jan 2024 22:11:42 -1000 Subject: [PATCH 11/35] WIP --- .controlplane/controlplane.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.controlplane/controlplane.yml b/.controlplane/controlplane.yml index 49a0ee45..0da371d9 100644 --- a/.controlplane/controlplane.yml +++ b/.controlplane/controlplane.yml @@ -56,5 +56,11 @@ apps: # `cpflow setup gvc postgres redis rails -a qa-react-webpack-rails-tutorial-pr-1234` qa-react-webpack-rails-tutorial: <<: *common + setup_app_templates: + - daily-task + - postgres + - gvc + - redis + - rails # Prefix is used to identify these "qa" apps. prefix: true From b3e36777d809aab3981235e695108d3c8b2f0062 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Fri, 22 Mar 2024 19:27:34 -1000 Subject: [PATCH 12/35] Updates for deployment --- .controlplane/templates/daily-task.yml | 3 +-- .controlplane/templates/gvc.yml | 10 +++++----- .controlplane/templates/postgres.yml | 5 +---- .controlplane/templates/rails.yml | 2 +- .../actions/deploy-to-control-plane/action.yml | 18 ++++-------------- 5 files changed, 12 insertions(+), 26 deletions(-) diff --git a/.controlplane/templates/daily-task.yml b/.controlplane/templates/daily-task.yml index 9fdd8fa4..1137801d 100644 --- a/.controlplane/templates/daily-task.yml +++ b/.controlplane/templates/daily-task.yml @@ -20,7 +20,7 @@ spec: - rake - daily inheritEnv: true - image: "/org/APP_ORG/image/APP_IMAGE" + image: {{APP_IMAGE_LINK}} defaultOptions: autoscaling: minScale: 1 @@ -30,4 +30,3 @@ spec: external: outboundAllowCIDR: - 0.0.0.0/0 - identityLink: /org/APP_ORG/gvc/APP_GVC/identity/postgres-poc-identity diff --git a/.controlplane/templates/gvc.yml b/.controlplane/templates/gvc.yml index 93028630..86abdb61 100644 --- a/.controlplane/templates/gvc.yml +++ b/.controlplane/templates/gvc.yml @@ -1,15 +1,15 @@ # Template setup of the GVC, roughly corresponding to a Heroku app kind: gvc -name: APP_GVC +name: {{APP_NAME}} spec: # For using templates for test apps, put ENV values here, stored in git repo. # Production apps will have values configured manually after app creation. env: - name: DATABASE_URL - # Password does not matter because host postgres.APP_GVC.cpln.local can only be accessed + # Password does not matter because host postgres.{{APP_NAME}}.cpln.local can only be accessed # locally within CPLN GVC, and postgres running on a CPLN workload is something only for a # test app that lacks persistence. - value: 'postgres://the_user:the_password@postgres.APP_GVC.cpln.local:5432/APP_GVC' + value: 'postgres://the_user:the_password@postgres.{{APP_NAME}}.cpln.local:5432/{{APP_NAME}}' - name: RAILS_ENV value: production - name: NODE_ENV @@ -18,8 +18,8 @@ spec: value: 'true' - name: REDIS_URL # No password for GVC local Redis. See comment above for postgres. - value: 'redis://redis.APP_GVC.cpln.local:6379' + value: 'redis://redis.{{APP_NAME}}.cpln.local:6379' # Part of standard configuration staticPlacement: locationLinks: - - /org/APP_ORG/location/APP_LOCATION + - {{APP_LOCATION_LINK}} diff --git a/.controlplane/templates/postgres.yml b/.controlplane/templates/postgres.yml index 7291e37d..77e3497b 100644 --- a/.controlplane/templates/postgres.yml +++ b/.controlplane/templates/postgres.yml @@ -106,7 +106,7 @@ bindings: # - use # - view principalLinks: - - //gvc/APP_GVC/identity/postgres-poc-identity + - //gvc/{{APP_NAME}}/identity/postgres-poc-identity targetKind: secret targetLinks: - //secret/postgres-poc-credentials @@ -139,9 +139,6 @@ spec: args: - "-c" - "cat /usr/local/bin/cpln-entrypoint.sh >> ./cpln-entrypoint.sh && chmod u+x ./cpln-entrypoint.sh && ./cpln-entrypoint.sh postgres" - #command: "cpln-entrypoint.sh" - #args: - # - "postgres" ports: - number: 5432 protocol: tcp diff --git a/.controlplane/templates/rails.yml b/.controlplane/templates/rails.yml index 728b5a12..e559b8fe 100644 --- a/.controlplane/templates/rails.yml +++ b/.controlplane/templates/rails.yml @@ -14,7 +14,7 @@ spec: value: debug # Inherit other ENV values from GVC inheritEnv: true - image: '/org/APP_ORG/image/APP_IMAGE' + image: {{APP_IMAGE_LINK}} # 512 corresponds to a standard 1x dyno type memory: 512Mi ports: diff --git a/.github/actions/deploy-to-control-plane/action.yml b/.github/actions/deploy-to-control-plane/action.yml index 6ba1d373..59fe6a34 100644 --- a/.github/actions/deploy-to-control-plane/action.yml +++ b/.github/actions/deploy-to-control-plane/action.yml @@ -4,7 +4,6 @@ name: Deploy-To-Control-Plane description: 'Deploys both to staging and to review apps' inputs: - # The name of the app to deploy app_name: description: 'The name of the app to deploy' required: true @@ -28,6 +27,7 @@ runs: sudo npm install -g @controlplane/cli@3.1.0 cpln --version gem install cpflow -v 4.0.0 + cpflow --version - name: Set Short SHA id: vars @@ -56,23 +56,13 @@ runs: fi # Provision all infrastructure on Control Plane. # app react-webpack-rails-tutorial will be created per definition in .controlplane/controlplane.yml - - name: cpflow build-image shell: bash run: | cpln image docker-login - cpflow build-image -a ${{ inputs.app_name }} --commit ${{steps.vars.outputs.sha_short}} --org ${{inputs.org}} - # --cache /tmp/.docker-cache - - - name: Run release script - shell: bash - run: | - # Run database migrations (or other release tasks) with the latest image, - # while the app is still running on the previous image. - # This is analogous to the release phase. - cpflow run './.controlplane/release_script.sh' -a ${{ inputs.app_name }} --image latest - + BUILDKIT_PROGRESS=plain cpflow build-image -a ${{ inputs.app_name }} --commit ${{steps.vars.outputs.sha_short}} --org ${{inputs.org}} + # --cache /tmp/.docker-cache - name: Deploy to Control Plane shell: bash run: | - cpflow deploy-image -a ${{ inputs.app_name }} --org ${{inputs.org}} + cpflow deploy-image -a ${{ inputs.app_name }} --run-release-phase --org ${{inputs.org}} From e57dfd82183b44871b01a89fc105598205d52eb7 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Fri, 22 Mar 2024 19:38:15 -1000 Subject: [PATCH 13/35] Updates for deployment --- .controlplane/controlplane.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.controlplane/controlplane.yml b/.controlplane/controlplane.yml index 0da371d9..d61c21c3 100644 --- a/.controlplane/controlplane.yml +++ b/.controlplane/controlplane.yml @@ -34,6 +34,9 @@ aliases: # Configure the workload name used when maintenance mode is on (defaults to "maintenance"). maintenance_workload: maintenance + # Configure the script to run when releasing an app., either with deploy-image or promote-app-from-upstream + release_script: release_script.sh + apps: react-webpack-rails-tutorial: # Simulate Production Version @@ -47,7 +50,6 @@ apps: upstream: react-webpack-rails-tutorial-staging - release_script: release_script.sh react-webpack-rails-tutorial-staging: <<: *common From 3a45bf81cd11808ec045e3f5956e9b6794a20594 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Fri, 22 Mar 2024 19:59:09 -1000 Subject: [PATCH 14/35] Updates for deployment --- .github/actions/deploy-to-control-plane/action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/actions/deploy-to-control-plane/action.yml b/.github/actions/deploy-to-control-plane/action.yml index 59fe6a34..533ebc81 100644 --- a/.github/actions/deploy-to-control-plane/action.yml +++ b/.github/actions/deploy-to-control-plane/action.yml @@ -60,7 +60,9 @@ runs: shell: bash run: | cpln image docker-login - BUILDKIT_PROGRESS=plain cpflow build-image -a ${{ inputs.app_name }} --commit ${{steps.vars.outputs.sha_short}} --org ${{inputs.org}} + # Use BUILDKIT_PROGRESS=plain to get more verbose logging of the build + # BUILDKIT_PROGRESS=plain cpflow build-image -a ${{ inputs.app_name }} --commit ${{steps.vars.outputs.sha_short}} --org ${{inputs.org}} + cpflow build-image -a ${{ inputs.app_name }} --commit ${{steps.vars.outputs.sha_short}} --org ${{inputs.org}} # --cache /tmp/.docker-cache - name: Deploy to Control Plane shell: bash From 1e70e76955d856aeaaa2a54d5968d5a54bb05576 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Fri, 22 Mar 2024 20:13:46 -1000 Subject: [PATCH 15/35] Updates for deployment --- .github/actions/deploy-to-control-plane/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/deploy-to-control-plane/action.yml b/.github/actions/deploy-to-control-plane/action.yml index 533ebc81..df887c8e 100644 --- a/.github/actions/deploy-to-control-plane/action.yml +++ b/.github/actions/deploy-to-control-plane/action.yml @@ -19,7 +19,7 @@ runs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: '3.2' # Specify your Ruby version here + ruby-version: '3.3.3' # Specify your Ruby version here - name: Install Control Plane CLI shell: bash From 22d168e3e2f4d1894b8a12daa7c7456909e05da0 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Fri, 22 Mar 2024 20:30:58 -1000 Subject: [PATCH 16/35] Updates for deployment --- .controlplane/controlplane.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.controlplane/controlplane.yml b/.controlplane/controlplane.yml index d61c21c3..503a6c93 100644 --- a/.controlplane/controlplane.yml +++ b/.controlplane/controlplane.yml @@ -58,11 +58,12 @@ apps: # `cpflow setup gvc postgres redis rails -a qa-react-webpack-rails-tutorial-pr-1234` qa-react-webpack-rails-tutorial: <<: *common + # Order matters! setup_app_templates: - - daily-task - - postgres - gvc + - postgres - redis + - daily-task - rails # Prefix is used to identify these "qa" apps. prefix: true From 3bb050c842decd5bba1055f168f430e6b7136960 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sat, 23 Mar 2024 21:44:35 -1000 Subject: [PATCH 17/35] Updates for deployment --- .controlplane/controlplane.yml | 5 +++++ .controlplane/templates/daily-task.yml | 2 ++ .controlplane/templates/gvc.yml | 6 ++++++ .controlplane/templates/rails.yml | 2 ++ .controlplane/templates/secrets-policy.yml | 4 ++++ .controlplane/templates/secrets.yml | 23 ++++++++++++++++++++++ 6 files changed, 42 insertions(+) create mode 100644 .controlplane/templates/secrets-policy.yml create mode 100644 .controlplane/templates/secrets.yml diff --git a/.controlplane/controlplane.yml b/.controlplane/controlplane.yml index 503a6c93..650d1148 100644 --- a/.controlplane/controlplane.yml +++ b/.controlplane/controlplane.yml @@ -60,9 +60,14 @@ apps: <<: *common # Order matters! setup_app_templates: + # GVC template contains the identity - gvc + + # Resources - postgres - redis + + # Workloads, like Dynos types on Heroku - daily-task - rails # Prefix is used to identify these "qa" apps. diff --git a/.controlplane/templates/daily-task.yml b/.controlplane/templates/daily-task.yml index 1137801d..f6b8dd9f 100644 --- a/.controlplane/templates/daily-task.yml +++ b/.controlplane/templates/daily-task.yml @@ -30,3 +30,5 @@ spec: external: outboundAllowCIDR: - 0.0.0.0/0 + # Identity is used for binding workload to secrets + identityLink: {{APP_IDENTITY_LINK}} diff --git a/.controlplane/templates/gvc.yml b/.controlplane/templates/gvc.yml index 86abdb61..ea51f2b1 100644 --- a/.controlplane/templates/gvc.yml +++ b/.controlplane/templates/gvc.yml @@ -23,3 +23,9 @@ spec: staticPlacement: locationLinks: - {{APP_LOCATION_LINK}} + +--- + +# Identity is needed to access secrets +kind: identity +name: {{APP_IDENTITY}} diff --git a/.controlplane/templates/rails.yml b/.controlplane/templates/rails.yml index e559b8fe..9641165b 100644 --- a/.controlplane/templates/rails.yml +++ b/.controlplane/templates/rails.yml @@ -34,3 +34,5 @@ spec: # Could configure outbound for more security outboundAllowCIDR: - 0.0.0.0/0 + # Identity is used for binding workload to secrets + identityLink: {{APP_IDENTITY_LINK}} diff --git a/.controlplane/templates/secrets-policy.yml b/.controlplane/templates/secrets-policy.yml new file mode 100644 index 00000000..35bdd886 --- /dev/null +++ b/.controlplane/templates/secrets-policy.yml @@ -0,0 +1,4 @@ +# Policy is needed to allow identities to access secrets +kind: policy +name: {{APP_SECRETS_POLICY}} +targetKind: secret diff --git a/.controlplane/templates/secrets.yml b/.controlplane/templates/secrets.yml new file mode 100644 index 00000000..6616376d --- /dev/null +++ b/.controlplane/templates/secrets.yml @@ -0,0 +1,23 @@ +# Org level secrets are used to store sensitive information that is +# shared across multiple apps in the same organization. This is +# useful for storing things like API keys, database credentials, and +# other sensitive information that is shared across multiple apps +# in the same organization. + +# This is how you apply this once (not during CI) +# cpl apply-template secrets -a qa-react-webpack-rails-tutorial --org shakacode-open-source-examples-staging + +kind: secret +name: {{APP_SECRETS}} +type: dictionary +data: + SOME_ENV: "123456" + +--- + +# Policy is needed to allow identities to access secrets +kind: policy +name: {{APP_SECRETS_POLICY}} +targetKind: secret +targetLinks: + - //secret/{{APP_SECRETS}} From 00645546848c4b5552e9fccc4d7e9091452ecc18 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sat, 23 Mar 2024 22:05:27 -1000 Subject: [PATCH 18/35] Updates for deployment --- .github/actions/deploy-to-control-plane/action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/deploy-to-control-plane/action.yml b/.github/actions/deploy-to-control-plane/action.yml index df887c8e..9eaffa5b 100644 --- a/.github/actions/deploy-to-control-plane/action.yml +++ b/.github/actions/deploy-to-control-plane/action.yml @@ -67,4 +67,5 @@ runs: - name: Deploy to Control Plane shell: bash run: | - cpflow deploy-image -a ${{ inputs.app_name }} --run-release-phase --org ${{inputs.org}} + echo "Deploying to Control Plane" + cpflow deploy-image -a ${{ inputs.app_name }} --run-release-phase --org ${{inputs.org}} --verbose From 69ce25e5f954686c9e30faa43172f7d55245fab6 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sun, 24 Mar 2024 22:18:27 -1000 Subject: [PATCH 19/35] test error handling --- .controlplane/controlplane.yml | 2 +- .controlplane/release_script.sh | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.controlplane/controlplane.yml b/.controlplane/controlplane.yml index 650d1148..857d9eda 100644 --- a/.controlplane/controlplane.yml +++ b/.controlplane/controlplane.yml @@ -14,7 +14,7 @@ aliases: # Production apps will use a different org than staging for security. # Change this value to your org name # or set ENV CPLN_ORG to your org name as that will override whatever is used here for all cpflow commands - # cpln_org: shakacode-open-source-examples + cpln_org: shakacode-open-source-examples-staging # Example apps use only location. CPLN offers the ability to use multiple locations. default_location: aws-us-east-2 diff --git a/.controlplane/release_script.sh b/.controlplane/release_script.sh index 2d9e1c59..ff9616eb 100755 --- a/.controlplane/release_script.sh +++ b/.controlplane/release_script.sh @@ -1,8 +1,25 @@ #!/bin/bash -e -echo 'Running release_script.sh per controlplane.yml' -echo 'Run DB migrations' -./bin/rails db:prepare +log() { + echo "[`date +%Y-%m-%d:%H:%M:%S`]: $1" +} -echo 'Completed release_script.sh per controlplane.yml' +error_exit() { + log "$1" 1>&2 + exit 1 +} + +# Test error! +error_exit + +log 'Running release_script.sh per controlplane.yml' + +if [ -x ./bin/rails ]; then + log 'Run DB migrations' + ./bin/rails db:prepare || error_exit "Failed to run DB migrations" +else + error_exit "./bin/rails does not exist or is not executable" +fi + +log 'Completed release_script.sh per controlplane.yml' From 3c2344c395341ccc36201f70cffd03214c9c38da Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Fri, 5 Apr 2024 10:48:05 -1000 Subject: [PATCH 20/35] Updates for deployment --- .controlplane/templates/{gvc.yml => app.yml} | 0 .controlplane/templates/{secrets.yml => org.yml} | 0 .controlplane/templates/secrets-policy.yml | 4 ---- 3 files changed, 4 deletions(-) rename .controlplane/templates/{gvc.yml => app.yml} (100%) rename .controlplane/templates/{secrets.yml => org.yml} (100%) delete mode 100644 .controlplane/templates/secrets-policy.yml diff --git a/.controlplane/templates/gvc.yml b/.controlplane/templates/app.yml similarity index 100% rename from .controlplane/templates/gvc.yml rename to .controlplane/templates/app.yml diff --git a/.controlplane/templates/secrets.yml b/.controlplane/templates/org.yml similarity index 100% rename from .controlplane/templates/secrets.yml rename to .controlplane/templates/org.yml diff --git a/.controlplane/templates/secrets-policy.yml b/.controlplane/templates/secrets-policy.yml deleted file mode 100644 index 35bdd886..00000000 --- a/.controlplane/templates/secrets-policy.yml +++ /dev/null @@ -1,4 +0,0 @@ -# Policy is needed to allow identities to access secrets -kind: policy -name: {{APP_SECRETS_POLICY}} -targetKind: secret From b050d7efd220561fe98a67f4d9ecf6a5b0acba10 Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Wed, 21 Aug 2024 12:45:14 +0300 Subject: [PATCH 21/35] chore: remove error test --- .controlplane/release_script.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/.controlplane/release_script.sh b/.controlplane/release_script.sh index ff9616eb..fe2ab785 100755 --- a/.controlplane/release_script.sh +++ b/.controlplane/release_script.sh @@ -10,9 +10,6 @@ error_exit() { exit 1 } -# Test error! -error_exit - log 'Running release_script.sh per controlplane.yml' if [ -x ./bin/rails ]; then From 872d2d27938d84826f2325eb5b32f8f4c00d3033 Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Wed, 21 Aug 2024 13:21:58 +0300 Subject: [PATCH 22/35] refactor: rename job to deploy-to-control-plane-review --- .github/workflows/deploy-to-control-plane-review.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index 02650aa5..fd57daa5 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -23,7 +23,7 @@ env: CPLN_TOKEN: ${{secrets.CPLN_TOKEN_STAGING}} jobs: - deploy-to-control-plane-staging: + deploy-to-control-plane-review: if: ${{ github.event_name != 'issue_comment' || (github.event.comment.body == '/deploy-review-app' && github.event.issue.pull_request) }} runs-on: ubuntu-latest From 7aac4ffde0bf0a6704115c7408af188c9313c6e8 Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Wed, 21 Aug 2024 13:23:48 +0300 Subject: [PATCH 23/35] feat: trigger deploying to control-plane review on opening a PR --- .../deploy-to-control-plane-review.yml | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index fd57daa5..c72a1a29 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -6,21 +6,27 @@ name: Deploy Review App to Control Plane on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: + # inputs: + # pr_number: + # description: 'Pull request number' + # required: false # inputs: # pr_number: # description: 'Pull request number' # required: false -# Triggers the workflow on pull request events -# pull_request: -# branches: -# - main # or the branch you want to trigger the workflow issue_comment: types: [created, edited] + # Triggers the workflow on pull request events + pull_request: + branches: + - master + # Convert the GitHub secret variables to environment variables for use by the Control Plane CLI env: CPLN_ORG: ${{secrets.CPLN_ORG_STAGING}} CPLN_TOKEN: ${{secrets.CPLN_TOKEN_STAGING}} + PR_NUMBER: ${{github.event.number}} jobs: deploy-to-control-plane-review: @@ -34,13 +40,15 @@ jobs: - name: Get PR number run: | echo "GITHUB_REPOSITORY: \"$GITHUB_REPOSITORY\"" - REF=${{ github.ref }} - REF=${REF#refs/heads/} # Remove 'refs/heads/' prefix - echo "REF: \"$REF\"" - API_RESPONSE=$(curl --location --request GET "https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open" \ - --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}') - echo "API_RESPONSE: $API_RESPONSE" - PR_NUMBER=$(echo $API_RESPONSE | jq '.[] | select(.head.ref=="'$REF'") | .number') + if [ -z "$PR_NUMBER" ]; then + echo "PR_NUMBER is not in the trigger event. Fetching PR number from open PRs." + REF=${{ github.ref }} + REF=${REF#refs/heads/} # Remove 'refs/heads/' prefix + echo "REF: \"$REF\"" + API_RESPONSE=$(curl --location --request GET "https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open" \ + --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}') + PR_NUMBER=$(echo $API_RESPONSE | jq '.[] | select(.head.ref=="'$REF'") | .number') + fi echo "PR_NUMBER: $PR_NUMBER" if [ -z "$PR_NUMBER" ]; then echo "PR_NUMBER is not set. Aborting." @@ -57,4 +65,4 @@ jobs: - uses: ./.github/actions/deploy-to-control-plane with: app_name: ${{ env.APP_NAME }} - org: ${{ secrets.CPLN_ORG_STAGING }} + org: ${{ env.CPLN_ORG }} From 13fd8e6844dec0278f1d5a1333d676e095b62951 Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Wed, 21 Aug 2024 14:22:43 +0300 Subject: [PATCH 24/35] feat: change setup_app_templates: from gvc to app --- .controlplane/controlplane.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.controlplane/controlplane.yml b/.controlplane/controlplane.yml index 857d9eda..4944a31d 100644 --- a/.controlplane/controlplane.yml +++ b/.controlplane/controlplane.yml @@ -61,7 +61,7 @@ apps: # Order matters! setup_app_templates: # GVC template contains the identity - - gvc + - app # Resources - postgres From ff07fdd171d0204f4a6a5505b1fd3a018493f8fe Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Wed, 21 Aug 2024 15:01:52 +0300 Subject: [PATCH 25/35] refactor: delete unneeded code --- .github/workflows/deploy-to-control-plane-review.yml | 8 -------- .../bundles/comments/rescript/CommentForm/CommentForm.res | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index c72a1a29..869a3cd6 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -6,14 +6,6 @@ name: Deploy Review App to Control Plane on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: - # inputs: - # pr_number: - # description: 'Pull request number' - # required: false -# inputs: -# pr_number: -# description: 'Pull request number' -# required: false issue_comment: types: [created, edited] diff --git a/client/app/bundles/comments/rescript/CommentForm/CommentForm.res b/client/app/bundles/comments/rescript/CommentForm/CommentForm.res index c075452d..db964269 100644 --- a/client/app/bundles/comments/rescript/CommentForm/CommentForm.res +++ b/client/app/bundles/comments/rescript/CommentForm/CommentForm.res @@ -90,7 +90,7 @@ let make = (~fetchData) => { } let forms: array = [ - {formName: "Horizontal Form XXXX", formType: Horizontal}, + {formName: "Horizontal Form", formType: Horizontal}, {formName: "Inline Form", formType: Inline}, {formName: "Stacked Form", formType: Stacked}, ] From 885074d4a241423a64f17ff5a5b4885a0411ca59 Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Sun, 25 Aug 2024 16:15:58 +0300 Subject: [PATCH 26/35] fix: typo --- .github/actions/deploy-to-control-plane/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/deploy-to-control-plane/action.yml b/.github/actions/deploy-to-control-plane/action.yml index 9eaffa5b..7105204c 100644 --- a/.github/actions/deploy-to-control-plane/action.yml +++ b/.github/actions/deploy-to-control-plane/action.yml @@ -34,7 +34,7 @@ runs: shell: bash run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" - - name: cpflow profile + - name: cpln profile shell: bash run: | cpln profile update default From 0decfa7ab4f487716c6093b4773c34418eff750b Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Mon, 26 Aug 2024 11:05:47 +0300 Subject: [PATCH 27/35] fix: styling --- .controlplane/templates/app.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.controlplane/templates/app.yml b/.controlplane/templates/app.yml index ea51f2b1..4ef5b8d0 100644 --- a/.controlplane/templates/app.yml +++ b/.controlplane/templates/app.yml @@ -1,6 +1,6 @@ # Template setup of the GVC, roughly corresponding to a Heroku app kind: gvc -name: {{APP_NAME}} +name: { { APP_NAME } } spec: # For using templates for test apps, put ENV values here, stored in git repo. # Production apps will have values configured manually after app creation. @@ -22,10 +22,9 @@ spec: # Part of standard configuration staticPlacement: locationLinks: - - {{APP_LOCATION_LINK}} + - { { APP_LOCATION_LINK } } --- - # Identity is needed to access secrets kind: identity -name: {{APP_IDENTITY}} +name: { { APP_IDENTITY } } From d66fa389d7614215ba5cff3fd300b8473b470918 Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Mon, 26 Aug 2024 11:06:43 +0300 Subject: [PATCH 28/35] feat: add a comment on opening PRs as an instruction for deploying review apps --- .../workflows/add-comment-on-pr-creation.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/add-comment-on-pr-creation.yml diff --git a/.github/workflows/add-comment-on-pr-creation.yml b/.github/workflows/add-comment-on-pr-creation.yml new file mode 100644 index 00000000..36b47f59 --- /dev/null +++ b/.github/workflows/add-comment-on-pr-creation.yml @@ -0,0 +1,19 @@ +name: Add helper Comment on PR creation + +on: + pull_request: + types: [opened] + +jobs: + comment-on-pr: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v6 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: "Hi 👋 To deploy a review app, please comment `/deploy-review-app`" + }) From 1f119f112439df6bfa7ca4ab9c19548c6aeb5d18 Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Mon, 26 Aug 2024 11:07:29 +0300 Subject: [PATCH 29/35] feat: trigger review-app deployment on commenting "/deploy-review-app" --- .../workflows/deploy-to-control-plane-review.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index 869a3cd6..ba7d5dea 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -9,16 +9,22 @@ on: issue_comment: types: [created, edited] - # Triggers the workflow on pull request events - pull_request: - branches: - - master + # Uncomment these lines to trigger the workflow on pull request events + # pull_request: + # branches: + # - master + + # deploy on comment "/deploy-review-app" + issue_comment: + types: [created, edited] # Convert the GitHub secret variables to environment variables for use by the Control Plane CLI env: CPLN_ORG: ${{secrets.CPLN_ORG_STAGING}} CPLN_TOKEN: ${{secrets.CPLN_TOKEN_STAGING}} - PR_NUMBER: ${{github.event.number}} + # Uncomment this line to use the PR number from the pull requests trigger event (that trigger is commented) + # PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }} + PR_NUMBER: ${{ github.event.issue.number }} jobs: deploy-to-control-plane-review: From ec4031cca3a45650cf39ab7a582d7d7679883303 Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Mon, 26 Aug 2024 11:20:40 +0300 Subject: [PATCH 30/35] feat: Add Github confirmation comment upon starting to deploy --- .github/workflows/deploy-to-control-plane-review.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index ba7d5dea..3f871803 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -60,6 +60,18 @@ jobs: echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ env.PR_NUMBER }}" >> $GITHUB_ENV echo "App Name: ${{ env.APP_NAME }}" + - name: Add GitHub Comment + if: ${{ github.event_name == 'issue_comment' }} + uses: actions/github-script@v4 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: "We started working on your review-app deployment. You can track progress in the "Actions" Tab [here](https://github.com/shakacode/react-webpack-rails-tutorial/actions/workflows/deploy-to-control-plane-review.yml) on Github." + }) + - uses: ./.github/actions/deploy-to-control-plane with: app_name: ${{ env.APP_NAME }} From f883d848da1ebff193a2c518cee6ee8bd051f10d Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Mon, 26 Aug 2024 12:01:37 +0300 Subject: [PATCH 31/35] fix: deprecated cpflow option --- .controlplane/controlplane.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.controlplane/controlplane.yml b/.controlplane/controlplane.yml index 4944a31d..af198fba 100644 --- a/.controlplane/controlplane.yml +++ b/.controlplane/controlplane.yml @@ -50,7 +50,6 @@ apps: upstream: react-webpack-rails-tutorial-staging - react-webpack-rails-tutorial-staging: <<: *common # QA Apps are like Heroku review apps, but the use `prefix` so you can run a commmand like @@ -70,5 +69,5 @@ apps: # Workloads, like Dynos types on Heroku - daily-task - rails - # Prefix is used to identify these "qa" apps. - prefix: true + # match_if_app_name_starts_with is used to identify these "qa" apps. + match_if_app_name_starts_with: true From 28b1eb574dbcd1b3241291d8817677fa84b924d9 Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Mon, 26 Aug 2024 12:02:23 +0300 Subject: [PATCH 32/35] feat: move confirmation comment to first thing in the review app workflow --- .../deploy-to-control-plane-review.yml | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index 3f871803..961b8827 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -35,6 +35,18 @@ jobs: - name: Check out the repo uses: actions/checkout@v2 + - name: Add GitHub Comment + if: ${{ github.event_name == 'issue_comment' }} + uses: actions/github-script@v4 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: "We started working on your review-app deployment. You can track progress in the "Actions" Tab [here](https://github.com/shakacode/react-webpack-rails-tutorial/actions/workflows/deploy-to-control-plane-review.yml) on Github." + }) + - name: Get PR number run: | echo "GITHUB_REPOSITORY: \"$GITHUB_REPOSITORY\"" @@ -60,18 +72,6 @@ jobs: echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ env.PR_NUMBER }}" >> $GITHUB_ENV echo "App Name: ${{ env.APP_NAME }}" - - name: Add GitHub Comment - if: ${{ github.event_name == 'issue_comment' }} - uses: actions/github-script@v4 - with: - script: | - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: "We started working on your review-app deployment. You can track progress in the "Actions" Tab [here](https://github.com/shakacode/react-webpack-rails-tutorial/actions/workflows/deploy-to-control-plane-review.yml) on Github." - }) - - uses: ./.github/actions/deploy-to-control-plane with: app_name: ${{ env.APP_NAME }} From 664248b7967dbb41b4f63261895de2b69abe349e Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Mon, 26 Aug 2024 13:47:33 +0300 Subject: [PATCH 33/35] feat: get correct checkout ref in issue_comment event --- .../workflows/deploy-to-control-plane-review.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index 961b8827..faa42871 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -32,8 +32,18 @@ jobs: runs-on: ubuntu-latest steps: - - name: Check out the repo - uses: actions/checkout@v2 + - name: Get PR HEAD Ref + if: ${{ github.event_name == 'issue_comment' }} + id: getRef + run: echo "PR_REF=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefName | jq -r '.headRefName')" >> $GITHUB_OUTPUT + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout source code from Github + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ steps.getRef.outputs.PR_REF || github.ref }} - name: Add GitHub Comment if: ${{ github.event_name == 'issue_comment' }} @@ -48,6 +58,7 @@ jobs: }) - name: Get PR number + if: ${{ github.event_name != 'issue_comment' }} run: | echo "GITHUB_REPOSITORY: \"$GITHUB_REPOSITORY\"" if [ -z "$PR_NUMBER" ]; then From bb7089a6f9ae8a51db82bd5821547ccc15381402 Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Mon, 26 Aug 2024 13:49:30 +0300 Subject: [PATCH 34/35] fix: typo --- .github/workflows/deploy-to-control-plane-review.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index faa42871..e501d046 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -6,8 +6,6 @@ name: Deploy Review App to Control Plane on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: - issue_comment: - types: [created, edited] # Uncomment these lines to trigger the workflow on pull request events # pull_request: From 551545b35459e1f3a460f816771cdcf3be98eab9 Mon Sep 17 00:00:00 2001 From: Ramez Weissa Date: Mon, 26 Aug 2024 14:00:09 +0300 Subject: [PATCH 35/35] fix: coderabbit suggestions --- .github/workflows/add-comment-on-pr-creation.yml | 3 ++- .../workflows/deploy-to-control-plane-review.yml | 16 +++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/add-comment-on-pr-creation.yml b/.github/workflows/add-comment-on-pr-creation.yml index 36b47f59..06a30089 100644 --- a/.github/workflows/add-comment-on-pr-creation.yml +++ b/.github/workflows/add-comment-on-pr-creation.yml @@ -8,7 +8,8 @@ jobs: comment-on-pr: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v6 + - name: Add GitHub Comment for review app instructions + uses: actions/github-script@v6 with: script: | github.rest.issues.createComment({ diff --git a/.github/workflows/deploy-to-control-plane-review.yml b/.github/workflows/deploy-to-control-plane-review.yml index e501d046..db8841a9 100644 --- a/.github/workflows/deploy-to-control-plane-review.yml +++ b/.github/workflows/deploy-to-control-plane-review.yml @@ -33,7 +33,7 @@ jobs: - name: Get PR HEAD Ref if: ${{ github.event_name == 'issue_comment' }} id: getRef - run: echo "PR_REF=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefName | jq -r '.headRefName')" >> $GITHUB_OUTPUT + run: echo "PR_REF=$(gh pr view \"$PR_NUMBER\" --repo \"${{ github.repository }}\" --json headRefName | jq -r '.headRefName')" >> $GITHUB_OUTPUT env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -45,7 +45,7 @@ jobs: - name: Add GitHub Comment if: ${{ github.event_name == 'issue_comment' }} - uses: actions/github-script@v4 + uses: actions/github-script@v6 with: script: | github.rest.issues.createComment({ @@ -61,26 +61,24 @@ jobs: echo "GITHUB_REPOSITORY: \"$GITHUB_REPOSITORY\"" if [ -z "$PR_NUMBER" ]; then echo "PR_NUMBER is not in the trigger event. Fetching PR number from open PRs." - REF=${{ github.ref }} + REF="${{ github.ref }}" REF=${REF#refs/heads/} # Remove 'refs/heads/' prefix echo "REF: \"$REF\"" - API_RESPONSE=$(curl --location --request GET "https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open" \ + API_RESPONSE=$(curl --location --request GET "https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls?state=open" \ --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}') - PR_NUMBER=$(echo $API_RESPONSE | jq '.[] | select(.head.ref=="'$REF'") | .number') + PR_NUMBER=$(echo "$API_RESPONSE" | jq '.[] | select(.head.ref=="'$REF'") | .number') fi echo "PR_NUMBER: $PR_NUMBER" if [ -z "$PR_NUMBER" ]; then echo "PR_NUMBER is not set. Aborting." exit 1 fi - echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV - + echo "PR_NUMBER=\"$PR_NUMBER\"" >> $GITHUB_ENV - name: Get App Name run: | echo "PR_NUMBER: ${{ env.PR_NUMBER }}" - echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ env.PR_NUMBER }}" >> $GITHUB_ENV + echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ env.PR_NUMBER }}" >> "$GITHUB_ENV" echo "App Name: ${{ env.APP_NAME }}" - - uses: ./.github/actions/deploy-to-control-plane with: app_name: ${{ env.APP_NAME }}