Deploy demo [ATO-762] #2746
Workflow file for this run
This file contains 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
name: Deploy branch | |
run-name: Deploy demo [${{ github.head_ref || github.ref_name }}] | |
on: | |
pull_request: | |
branches: | |
- main | |
types: | |
- opened | |
- reopened | |
- ready_for_review | |
- synchronize | |
concurrency: deploy-demo-${{ github.head_ref || github.ref_name }} | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
build-frontend-dependencies: | |
if: contains(github.event.head_commit.message, '[deploy]') == true | |
name: Build frontend | |
runs-on: ubuntu-latest | |
environment: | |
name: demo | |
outputs: | |
artifact-name: ${{ steps.build.outputs.artifact-id }} | |
steps: | |
- name: Pull repository | |
id: checkout | |
uses: actions/checkout@v4 | |
- name: Build | |
id: build | |
uses: ./.github/actions/build-frontend | |
with: | |
artifact-name: frontend-build-demo | |
push-frontend-image: | |
if: contains(github.event.head_commit.message, '[deploy]') == true | |
name: Push frontend image | |
needs: build-frontend-dependencies | |
runs-on: ubuntu-latest | |
environment: | |
name: demo | |
url: ${{ steps.push-image.outputs.image-url }} | |
outputs: | |
image-uri: ${{ steps.push-image.outputs.image-uri }} | |
steps: | |
- name: Login to GDS Dev Dynatrace Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: khw46367.live.dynatrace.com | |
username: khw46367 | |
password: ${{ secrets.DYNATRACE_PAAS_TOKEN }} | |
- name: Push Docker image | |
uses: govuk-one-login/github-actions/aws/ecr/build-docker-image@7d56b09b4d2a9a9c6005843d28f31a2333ad1373 # 13/03/2024 | |
id: push-image | |
with: | |
image-version: ${{ github.sha }} | |
aws-role-arn: ${{ vars.DEPLOYMENT_ROLE_ARN }} | |
repository: ${{ vars.FRONTEND_CONTAINER_REPOSITORY_NAME }} | |
image-tags: "${{ github.head_ref || github.ref_name }}" | |
dockerfile: infrastructure/frontend/Dockerfile | |
artifact-name: frontend-build-demo | |
artifact-path: dist | |
build-frontend-infrastructure: | |
if: contains(github.event.head_commit.message, '[deploy]') == true | |
name: Build frontend infrastructure | |
needs: push-frontend-image | |
runs-on: ubuntu-latest | |
environment: | |
name: demo | |
outputs: | |
template: ${{ steps.replace-placeholders.outputs.template }} | |
steps: | |
- name: Pull repository | |
id: checkout | |
uses: actions/checkout@v4 | |
- name: Replace placeholders | |
if: ${{ github.actor != 'dependabot[bot]' }} | |
id: replace-placeholders | |
env: | |
TEMPLATE_FILE: infrastructure/frontend/frontend.template.yml | |
IMAGE_URI: ${{ needs.push-frontend-image.outputs.image-uri }} | |
run: | | |
sam build ${TEMPLATE_FILE:+--template $TEMPLATE_FILE} | |
echo "template=.aws-sam/build/template.yaml" >> "$GITHUB_OUTPUT" | |
if grep -q "CONTAINER-IMAGE-PLACEHOLDER" .aws-sam/build/template.yaml; then | |
echo "Replacing \"CONTAINER-IMAGE-PLACEHOLDER\" with new ECR image ref" | |
sed -i "s|CONTAINER-IMAGE-PLACEHOLDER|$IMAGE_URI|" .aws-sam/build/template.yaml | |
else | |
echo "WARNING!!! Image placeholder text \"CONTAINER-IMAGE-PLACEHOLDER\" not found - uploading template anyway" | |
fi | |
- name: Archive distribution artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: frontend-infrastructure | |
retention-days: 7 | |
path: .aws-sam/build | |
deploy-frontend: | |
if: contains(github.event.head_commit.message, '[deploy]') == true | |
name: Deploy frontend | |
needs: [ build-frontend-infrastructure, deploy-api, deploy-cognito, deploy-dynamodb ] | |
runs-on: ubuntu-latest | |
outputs: | |
stack-name: ${{ steps.deploy.outputs.stack-name }} | |
deployment-url: ${{ steps.get-deployment-url.outputs.url }} | |
environment: | |
name: demo | |
url: ${{ steps.get-deployment-url.outputs.url || steps.deploy.outputs.stack-url }} | |
steps: | |
- name: Get deployment name | |
uses: govuk-one-login/github-actions/beautify-branch-name@7d56b09b4d2a9a9c6005843d28f31a2333ad1373 # 13/03/2024 | |
id: get-deployment-name | |
with: | |
length-limit: 22 | |
prefix: preview | |
verbose: false | |
- name: Deploy stack | |
uses: govuk-one-login/github-actions/sam/deploy-stack@7d56b09b4d2a9a9c6005843d28f31a2333ad1373 # 13/03/2024 | |
id: deploy | |
with: | |
aws-role-arn: ${{ vars.DEPLOYMENT_ROLE_ARN }} | |
sam-deployment-bucket: ${{ vars.DEPLOYMENT_ARTIFACTS_BUCKET }} | |
delete-failed-stack: true | |
disable-rollback: false | |
stack-name-prefix: preview-frontend | |
artifact-name: frontend-infrastructure | |
artifact-path: .aws-sam/build | |
template: ${{ needs.build-frontend-infrastructure.outputs.template }} | |
s3-prefix: sse-preview | |
tags: |- | |
sse:component=frontend | |
sse:stack-type=preview | |
sse:application=self-service | |
sse:deployment-source=github-actions | |
sse:lifecycle=temporary | |
parameters: |- | |
DeploymentName=${{ steps.get-deployment-name.outputs.pretty-branch-name }} | |
- name: Get deployment URL | |
id: get-deployment-url | |
env: | |
NAME: AdminToolURL | |
OUTPUTS: ${{ steps.deploy.outputs.stack-outputs }} | |
run: | | |
url=$(jq --raw-output ".$NAME" <<< "$OUTPUTS") | |
printf "🌐 Deployment URL\n%s" "$url" >> "$GITHUB_STEP_SUMMARY" | |
echo "url=$url" >> "$GITHUB_OUTPUT" | |
build-dynamodb: | |
if: contains(github.event.head_commit.message, '[deploy]') == true | |
name: Build dynamodb | |
runs-on: ubuntu-latest | |
environment: | |
name: demo | |
outputs: | |
artifact-name: ${{ steps.build.outputs.artifact-name }} | |
cache-key: ${{ steps.build.outputs.cache-key }} | |
steps: | |
- name: Build | |
id: build | |
uses: govuk-one-login/github-actions/sam/build-application@6144f39407b01c9b25b39537b3956deca9e32620 # 22/02/2024 | |
with: | |
template: backend/dynamodb/dynamodb.template.yml | |
base-dir: backend/dynamodb | |
source-dir: backend/dynamodb | |
cache-name: backend-dynamodb-infra | |
artifact-name: backend-dynamodb-infrastructure | |
pull-repository: true | |
deploy-dynamodb: | |
if: contains(github.event.head_commit.message, '[deploy]') == true | |
name: Deploy dynamodb | |
needs: build-dynamodb | |
runs-on: ubuntu-latest | |
environment: | |
name: demo | |
url: ${{ steps.deploy.outputs.stack-url }} | |
outputs: | |
stack-name: ${{ steps.build.outputs.stack-name }} | |
stack-url: ${{ steps.build.outputs.stack-url }} | |
steps: | |
- name: Get deployment name | |
uses: govuk-one-login/github-actions/beautify-branch-name@db4b3614f5f863f56a5356052262878ecec83b31 # 22/07/2024 | |
id: get-deployment-name | |
with: | |
length-limit: 22 | |
prefix: preview | |
verbose: false | |
- name: Deploy stack | |
uses: govuk-one-login/github-actions/sam/deploy-stack@db4b3614f5f863f56a5356052262878ecec83b31 # 22/07/2024 | |
id: deploy | |
with: | |
aws-role-arn: ${{ vars.DEPLOYMENT_ROLE_ARN }} | |
sam-deployment-bucket: ${{ vars.DEPLOYMENT_ARTIFACTS_BUCKET }} | |
delete-failed-stack: true | |
disable-rollback: false | |
stack-name-prefix: preview-dynamodb | |
artifact-name: ${{ needs.build-dynamodb.outputs.artifact-name }} | |
artifact-path: .aws-sam/build | |
template: .aws-sam/build/template.yaml | |
cache-name: ${{ needs.build-dynamodb.outputs.cache-key }} | |
s3-prefix: sse-preview | |
tags: |- | |
sse:component=dynamodb | |
sse:stack-type=preview | |
sse:stack-name=preview-dynamodb | |
sse:application=self-service | |
sse:deployment-source=github-actions | |
parameters: |- | |
DeploymentName=${{ steps.get-deployment-name.outputs.pretty-branch-name }} | |
build-cognito: | |
if: contains(github.event.head_commit.message, '[deploy]') == true | |
name: Build cognito | |
runs-on: ubuntu-latest | |
environment: | |
name: demo | |
outputs: | |
artifact-name: ${{ steps.build.outputs.artifact-name }} | |
cache-key: ${{ steps.build.outputs.cache-key }} | |
steps: | |
- name: Build | |
id: build | |
uses: govuk-one-login/github-actions/sam/build-application@6144f39407b01c9b25b39537b3956deca9e32620 # 22/02/2024 | |
with: | |
template: backend/cognito/cognito.template.yml | |
manifest: backend/cognito/package.json | |
base-dir: backend/cognito | |
source-dir: backend/cognito | |
cache-name: backend-cognito-infra | |
artifact-name: backend-cognito-infrastructure | |
pull-repository: true | |
deploy-cognito: | |
if: contains(github.event.head_commit.message, '[deploy]') == true | |
name: Deploy cognito | |
needs: build-cognito | |
runs-on: ubuntu-latest | |
environment: | |
name: demo | |
url: ${{ steps.deploy.outputs.stack-url }} | |
outputs: | |
stack-name: ${{ steps.build.outputs.stack-name }} | |
stack-url: ${{ steps.build.outputs.stack-url }} | |
steps: | |
- name: Get deployment name | |
uses: govuk-one-login/github-actions/beautify-branch-name@db4b3614f5f863f56a5356052262878ecec83b31 # 22/07/2024 | |
id: get-deployment-name | |
with: | |
length-limit: 22 | |
prefix: preview | |
verbose: false | |
- name: Deploy stack | |
uses: govuk-one-login/github-actions/sam/deploy-stack@db4b3614f5f863f56a5356052262878ecec83b31 # 22/07/2024 | |
id: deploy | |
with: | |
aws-role-arn: ${{ vars.DEPLOYMENT_ROLE_ARN }} | |
sam-deployment-bucket: ${{ vars.DEPLOYMENT_ARTIFACTS_BUCKET }} | |
delete-failed-stack: true | |
disable-rollback: false | |
stack-name-prefix: preview-cognito | |
artifact-name: ${{ needs.build-cognito.outputs.artifact-name }} | |
artifact-path: .aws-sam/build | |
template: .aws-sam/build/template.yaml | |
cache-name: ${{ needs.build-cognito.outputs.cache-key }} | |
s3-prefix: sse-preview | |
tags: |- | |
sse:component=cognito | |
sse:stack-type=preview | |
sse:stack-name=preview-cognito | |
sse:application=self-service | |
sse:deployment-source=github-actions | |
parameters: |- | |
DeploymentName=${{ steps.get-deployment-name.outputs.pretty-branch-name }} | |
build-api: | |
if: contains(github.event.head_commit.message, '[deploy]') == true | |
name: Build api | |
runs-on: ubuntu-latest | |
environment: | |
name: demo | |
outputs: | |
artifact-name: ${{ steps.build.outputs.artifact-name }} | |
cache-key: ${{ steps.build.outputs.cache-key }} | |
steps: | |
- name: Build | |
id: build | |
uses: govuk-one-login/github-actions/sam/build-application@6144f39407b01c9b25b39537b3956deca9e32620 # 22/02/2024 | |
with: | |
template: backend/api/api.template.yml | |
manifest: backend/api/package.json | |
base-dir: backend/api | |
source-dir: backend/api | |
additional-artifact-paths: backend/api/state-machines | |
cache-name: backend-api-infra | |
artifact-name: backend-api-infrastructure | |
pull-repository: true | |
deploy-api: | |
if: contains(github.event.head_commit.message, '[deploy]') == true | |
name: Deploy api | |
needs: build-api | |
runs-on: ubuntu-latest | |
environment: | |
name: demo | |
url: ${{ steps.deploy.outputs.stack-url }} | |
outputs: | |
stack-name: ${{ steps.build.outputs.stack-name }} | |
stack-url: ${{ steps.build.outputs.stack-url }} | |
steps: | |
- name: Get deployment name | |
uses: govuk-one-login/github-actions/beautify-branch-name@db4b3614f5f863f56a5356052262878ecec83b31 # 22/07/2024 | |
id: get-deployment-name | |
with: | |
length-limit: 22 | |
prefix: preview | |
verbose: false | |
- name: Deploy stack | |
uses: govuk-one-login/github-actions/sam/deploy-stack@db4b3614f5f863f56a5356052262878ecec83b31 # 22/07/2024 | |
id: deploy | |
with: | |
aws-role-arn: ${{ vars.DEPLOYMENT_ROLE_ARN }} | |
sam-deployment-bucket: ${{ vars.DEPLOYMENT_ARTIFACTS_BUCKET }} | |
delete-failed-stack: true | |
disable-rollback: false | |
stack-name-prefix: preview-api | |
artifact-name: ${{ needs.build-api.outputs.artifact-name }} | |
template: .aws-sam/build/template.yaml | |
cache-name: ${{ needs.build-api.outputs.cache-key }} | |
s3-prefix: sse-preview | |
tags: |- | |
sse:component=api | |
sse:stack-type=preview | |
sse:stack-name=preview-api | |
sse:application=self-service | |
sse:deployment-source=github-actions | |
parameters: |- | |
DeploymentName=${{ steps.get-deployment-name.outputs.pretty-branch-name }} |