-
Notifications
You must be signed in to change notification settings - Fork 11
Use AWS credentials to deploy review apps #2507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
whi-tw
merged 3 commits into
main
from
whi-tw/allow-github-hosted-runner-deploy-review-apps
Mar 19, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,104 +1,20 @@ | ||
| name: "Review apps: on PR change" | ||
| on: | ||
| pull_request: | ||
| # being explicit about what to trigger on. | ||
| # matches the docs for the default types | ||
| # https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request | ||
| types: [opened, reopened, synchronize] | ||
| jobs: | ||
| update-review-app: | ||
| # this references a codebuild project configured in forms-deploy | ||
| # see: https://docs.aws.amazon.com/codebuild/latest/userguide/action-runner.html | ||
| runs-on: codebuild-review-forms-admin-gha-runner-${{github.run_id}}-${{github.run_attempt}} | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - name: Generate container image URI | ||
| run: | | ||
| echo "CONTAINER_IMAGE_URI=842676007477.dkr.ecr.eu-west-2.amazonaws.com/forms-admin:pr-${{github.event.pull_request.number}}-${{github.event.pull_request.head.sha}}-$(date +%s)" >> "$GITHUB_ENV" | ||
|
|
||
| - name: Checkout code | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| - name: Build container | ||
| run: | | ||
| # Docker credentials are configured in CodeBuild | ||
| # CodeBuild retrieves the credentials from ParameterStore | ||
| echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin | ||
| docker build \ | ||
| --tag "${{env.CONTAINER_IMAGE_URI}}" \ | ||
| . | ||
|
|
||
| - name: Push container | ||
| id: build-container | ||
| run: | | ||
| aws ecr get-login-password --region eu-west-2 \ | ||
| | docker login --username AWS --password-stdin 842676007477.dkr.ecr.eu-west-2.amazonaws.com | ||
|
|
||
| echo "Pushing container image" | ||
| echo "${{env.CONTAINER_IMAGE_URI}}" | ||
|
|
||
| docker push "${CONTAINER_IMAGE_URI}" | ||
|
|
||
| - name: Determine Terraform version | ||
| id: terraform-version | ||
| run: | | ||
| TF_VERSION=$(< .review_apps/.terraform-version) | ||
| printf "TF_VERSION=%s\n" "$TF_VERSION" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - uses: hashicorp/setup-terraform@5e8dbf3c6d9deaf4193ca7a8fb23f2ac83bb6c85 # v4.0.0 | ||
| with: | ||
| terraform_version: ${{steps.terraform-version.outputs.TF_VERSION}} | ||
| concurrency: | ||
| group: "review-apps-pr-${{ github.event.pull_request.number }}" | ||
| cancel-in-progress: false | ||
|
|
||
| - name: Deploy review app | ||
| id: deploy | ||
| run: | | ||
| cd .review_apps/ | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| terraform init -backend-config="key=review-apps/forms-admin/pr-${{github.event.pull_request.number}}.tfstate" | ||
|
|
||
| terraform apply \ | ||
| -var "pull_request_number=${{github.event.pull_request.number}}" \ | ||
| -var "forms_admin_container_image=${{env.CONTAINER_IMAGE_URI}}" \ | ||
| -no-color \ | ||
| -auto-approve | ||
| REVIEW_APP_URL=$(terraform output -raw review_app_url) | ||
| ECS_CLUSTER_ID=$(terraform output -raw review_app_ecs_cluster_id) | ||
| ECS_SERVICE_NAME=$(terraform output -raw review_app_ecs_service_name) | ||
| { | ||
| printf 'REVIEW_APP_URL=%s\n' "$REVIEW_APP_URL" | ||
| printf 'ECS_CLUSTER_ID=%s\n' "$ECS_CLUSTER_ID" | ||
| printf 'ECS_SERVICE_NAME=%s\n' "$ECS_SERVICE_NAME" | ||
| } >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Wait for AWS ECS deployments to finish | ||
| run: | | ||
| aws ecs wait services-stable \ | ||
| --cluster "${{steps.deploy.outputs.ECS_CLUSTER_ID}}" \ | ||
| --services "${{steps.deploy.outputs.ECS_SERVICE_NAME}}" | ||
|
|
||
| - name: Comment on PR | ||
| env: | ||
| COMMENT_MARKER: <!-- review apps on pr change --> | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| cat <<EOF > "${{runner.temp}}/pr-comment.md" | ||
| :tada: A review copy of this PR has been deployed! You can reach it at: ${{steps.deploy.outputs.REVIEW_APP_URL}} | ||
|
|
||
| It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready | ||
| after 5 minutes, there may be something wrong with the ECS task. You will need to go to the integration AWS account | ||
| to debug, or otherwise ask an infrastructure person. | ||
|
|
||
| For the sign in details and more information, [see the review apps wiki page](https://github.com/alphagov/forms-team/wiki/Review-apps). | ||
|
|
||
| $COMMENT_MARKER | ||
| EOF | ||
|
|
||
| old_comment_ids=$(gh api "repos/{owner}/{repo}/issues/${{github.event.pull_request.number}}/comments" --jq "map(select((.user.login == \"github-actions[bot]\") and (.body | endswith(env.COMMENT_MARKER + \"\n\")))) | .[].id") | ||
| for comment_id in $old_comment_ids; do | ||
| gh api -X DELETE "repos/{owner}/{repo}/issues/comments/${comment_id}" | ||
| done | ||
|
|
||
| gh pr comment "${{github.event.pull_request.html_url}}" --body-file "${{runner.temp}}/pr-comment.md" | ||
| jobs: | ||
| update-review-app: | ||
| name: Update review app | ||
| uses: alphagov/forms-deploy/.github/workflows/reusable-review_apps_on_pr_change.yml@main | ||
| with: | ||
| app-name: forms-admin | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,20 @@ | ||
| name: "Review apps: on PR close" | ||
| on: | ||
| pull_request: | ||
| # only run when a PR is closed or merged | ||
| types: [closed] | ||
| env: | ||
| IMAGE_TAG: "842676007477.dkr.ecr.eu-west-2.amazonaws.com/forms-admin:pr-${{github.event.pull_request.number}}-${{github.event.pull_request.head.ref}}" | ||
| jobs: | ||
| delete-review-app: | ||
| # this references a codebuild project configured in forms-deploy | ||
| # see: https://docs.aws.amazon.com/codebuild/latest/userguide/action-runner.html | ||
| runs-on: codebuild-review-forms-admin-gha-runner-${{github.run_id}}-${{github.run_attempt}} | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| - name: Determine Terraform version | ||
| id: terraform-version | ||
| run: | | ||
| TF_VERSION=$(< .review_apps/.terraform-version) | ||
| printf "TF_VERSION=%s\n" "$TF_VERSION" >> "$GITHUB_OUTPUT" | ||
| concurrency: | ||
| group: "review-apps-pr-${{ github.event.pull_request.number }}" | ||
| cancel-in-progress: false | ||
|
|
||
| - uses: hashicorp/setup-terraform@5e8dbf3c6d9deaf4193ca7a8fb23f2ac83bb6c85 # v4.0.0 | ||
| with: | ||
| terraform_version: ${{steps.terraform-version.outputs.TF_VERSION}} | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| - name: Delete review app | ||
| run: | | ||
| cd .review_apps/ | ||
|
|
||
| terraform init -backend-config="key=review-apps/forms-admin/pr-${{github.event.pull_request.number}}.tfstate" | ||
| terraform destroy \ | ||
| -var "pull_request_number=${{github.event.pull_request.number}}" \ | ||
| -var "forms_admin_container_image=${{env.IMAGE_TAG}}" \ | ||
| -no-color \ | ||
| -auto-approve | ||
| jobs: | ||
| delete-review-app: | ||
| name: Delete review app | ||
| uses: alphagov/forms-deploy/.github/workflows/reusable-review_apps_on_pr_close.yml@main | ||
| with: | ||
| app-name: forms-admin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.