Skip to content

Production - Deploy #10

Production - Deploy

Production - Deploy #10

Workflow file for this run

name: Production - Deploy
on:
workflow_run:
workflows: ["Production — Docker build and push"]
types:
- completed
env:
AWS_ACCOUNT_ID: ${{ vars.PRODUCTION_AWS_ACCOUNT_ID }}
AWS_REGION: ca-central-1
CLUSTER_NAME: Forms
SERVICE_NAME: forms-api
TASK_DEFINITION_NAME: forms-api
REGISTRY: ${{ vars.PRODUCTION_AWS_ACCOUNT_ID }}.dkr.ecr.ca-central-1.amazonaws.com/forms/api
permissions:
id-token: write
contents: read
jobs:
deploy-forms-api-service:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
- name: Configure AWS credentials using OIDC
uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4.3.1
with:
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/forms-api-apply
role-session-name: ECSDeploy
aws-region: ${{ env.AWS_REGION }}
- name: Download ECS task definition
run: |
aws ecs describe-task-definition \
--task-definition ${{ env.SERVICE_NAME }} \
--query taskDefinition > task-definition.json
- name: Update ECS task image
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@5cb8c74c1b1ecaec4c8ea82eff82c009333509ce # v1.8.0
with:
task-definition: task-definition.json
container-name: ${{ env.SERVICE_NAME }}
image: "${{ env.REGISTRY }}:${{ github.event.workflow_run.head_branch }}"
- name: Create the new ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@4b08990e8909cf36bc2ca95f994312f090c41865 # v2.3.4
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
cluster: ${{ env.CLUSTER_NAME }}
- name: Deploy the new ECS task definition
run: |
aws ecs update-service \
--cluster ${{ env.CLUSTER_NAME }} \
--service ${{ env.SERVICE_NAME }} \
--task-definition ${{ env.TASK_DEFINITION_NAME }} \
--force-new-deployment > /dev/null 2>&1
aws ecs wait services-stable \
--cluster ${{ env.CLUSTER_NAME }} \
--services ${{ env.SERVICE_NAME }}
- name: Report deployment to Sentinel
if: always()
uses: cds-snc/sentinel-forward-data-action@main
with:
input_data: '{"product": "forms", "sha": "${{ github.event.workflow_run.head_branch }}", "version": "${{ github.event.workflow_run.head_branch }}", "repository": "${{ github.repository }}", "environment": "production", "status": "${{ job.status }}"}'
log_type: CDS_Product_Deployment_Data
log_analytics_workspace_id: ${{ secrets.LOG_ANALYTICS_WORKSPACE_ID }}
log_analytics_workspace_key: ${{ secrets.LOG_ANALYTICS_WORKSPACE_KEY }}