Skip to content

Deploy to AWS

Deploy to AWS #71

Workflow file for this run

name: Deploy to AWS
on:
workflow_dispatch:
inputs:
environment:
description: The environment to deploy to
required: true
type: environment
default: staging
infra_branch:
description: The branch of the infrastructure repository to deploy
required: true
type: string
default: main
workflow_call:
inputs:
environment:
description: The environment to deploy to
required: true
type: string
default: staging
infra_branch:
description: The branch of the infrastructure repository to deploy
required: true
type: string
default: main
secrets:
AWS_ACCESS_KEY_ID:
AWS_SECRET_ACCESS_KEY:
DEPLOYMENT_APP_ID:
DEPLOYMENT_APP_KEY:
permissions:
contents: read
jobs:
ci:
name: Verify code is valid
permissions:
checks: write
contents: write
uses: ./.github/workflows/ci.yml
deploy:
name: Deploy to ${{ inputs.environment }}
needs: ci
environment: ${{ inputs.environment }}
runs-on: ubuntu-latest
env:
ENVIRONMENT: ${{ inputs.environment }}
ECR_REPOSITORY: work-requirements-self-advocacy-tool-${{ inputs.environment }}-web
IMAGE_TAG: ${{ github.sha }}
INFRA_REPO: work-requirements-self-advocacy-tool-infra
steps:
- name: Check out code
uses: actions/checkout@v6
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v6
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_REGION || 'us-east-1' }}
- name: Log in to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Check if the image exists
id: image_exists
uses: k4kratik/container-image-check-custom-action@v4
with:
type: ecr
container_repo_name: ${{ env.ECR_REPOSITORY }}
image_tag: ${{env.IMAGE_TAG}}
- name: Build and push Docker image
if: ${{ steps.image_exists.outputs.image_exists == 'false' }}
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:${{env.IMAGE_TAG}} --platform linux/amd64 .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:${{env.IMAGE_TAG}}
- name: Update SSM Version Parameter
run: |
echo "tag:$IMAGE_TAG"
aws ssm put-parameter \
--name /work-requirements-self-advocacy-tool/$ENVIRONMENT/web/version \
--value "$IMAGE_TAG" \
--overwrite
- name: Get a deployment token
uses: actions/create-github-app-token@v3
id: token
with:
app-id: ${{ secrets.DEPLOYMENT_APP_ID }}
private-key: ${{ secrets.DEPLOYMENT_APP_KEY }}
owner: codeforamerica
repositories: ${{ env.INFRA_REPO }}
- name: Trigger deployment from work requirements self advocacy infra
uses: codex-/return-dispatch@v3
id: dispatch
with:
token: ${{ steps.token.outputs.token }}
ref: ${{ inputs.infra_branch }}
repo: ${{ env.INFRA_REPO }}
owner: codeforamerica
workflow: 'deploy.yml'
workflow_inputs: |
{
"environment": "${{ env.ENVIRONMENT }}",
"config": "application"
}
- name: Wait on Workflow
uses: lucasssvaz/wait-on-workflow@v1
id: waiter
with:
github-token: ${{ steps.token.outputs.token }}
repository: codeforamerica/${{ env.INFRA_REPO }}
workflow: ${{ steps.dispatch.outputs.run_id }}
- name: Fail unless the workflow succeeded
if: ${{ steps.waiter.outputs.conclusion != 'success' }}
uses: actions/github-script@v8
with:
script: |
core.setFailed('Deployment workflow completed with stats: ${{ steps.waiter.outputs.conclusion }}')