Skip to content

Deploy to AWS Staging #2

Deploy to AWS Staging

Deploy to AWS Staging #2

name: Deploy to AWS Staging
on:
workflow_run:
workflows: [ "Run tests" ]
types: [ completed ]
branches: [ main ]
workflow_dispatch:
inputs: { }
jobs:
deploy:
name: Deploy to Staging
runs-on: ubuntu-latest
env:
ECR_REPOSITORY: pya-staging-web
IMAGE_TAG: ${{ github.sha }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: us-east-1
- name: Log in to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build and push Docker image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
docker build -t pya-staging-web:${{env.IMAGE_TAG}} --platform linux/amd64 .
docker push 300423309117.dkr.ecr.us-east-1.amazonaws.com/pya-staging-web:${{env.IMAGE_TAG}}
- name: Update SSM Version Parameter
run: |
echo "tag:$IMAGE_TAG"
aws ssm put-parameter \
--name /pya/staging/web/version \
--value "$IMAGE_TAG" \
--overwrite
- name: Trigger infrastructure deployment
run: |
# Set the required variables
repo_owner="codeforamerica"
repo_name="tax-benefits-backend"
event_type="deploy"
environment="staging"
config="qa"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.STAGING_DEPLOY_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$repo_owner/$repo_name/dispatches \
-d "{\"event_type\": \"$event_type\", \"client_payload\": {\"environment\": \"$environment\", \"config\": \"$config\"}}"