Skip to content

Deploy to AWS Staging #74

Deploy to AWS Staging

Deploy to AWS Staging #74

name: Deploy to AWS Staging
on:
workflow_run:
workflows: [ "Run Linter and Tests" ]
types: [ completed ]
branches: [ main ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
on-success:
environment: staging
name: Deploy to Staging
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
env:
ECR_REPOSITORY: pya-staging-web
IMAGE_TAG: ${{ github.sha }}
steps:
- run: echo 'The triggering workflow passed'
- run: echo 'Starting the staging deploy'
- 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 300423309117.dkr.ecr.us-east-1.amazonaws.com/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="pya-nonprod"
config="staging.pya.fileyourstatetaxes.org"
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\"}}"
- name: Notify deploy failure on Slack
uses: 8398a7/action-slack@v3
if: failure()
with:
text: "<!subteam^S06P99RGJDS> <@U07QATMB6SW> <@U07Q99GPBK8> <@U07Q39HFLBG> PYA staging deploy ${{ job.status }} :sob:"
status: ${{ job.status }}
fields: message,commit,author,eventName,ref,workflow,job,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: Send Slack notification on failure
uses: 8398a7/action-slack@v3
with:
text: "<!subteam^S06P99RGJDS> <@U07QATMB6SW> <@U07Q99GPBK8> <@U07Q39HFLBG> PYA test suite ${{ github.event.workflow_run.conclusion }} :sob:"
status: ${{ github.event.workflow_run.conclusion }}
fields: message,commit,author,eventName,ref,workflow,job,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}