Deploy to Staging #1205
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 to Staging | |
on: | |
workflow_run: | |
workflows: ["Staging — Push container to ECR"] | |
types: | |
- completed | |
jobs: | |
unable-to-deploy: | |
if: ${{ github.event.workflow_run.conclusion == 'failure' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Post to Slack | |
run: | | |
json='{"channel":"#forms-deploy-activities", "blocks":[{"type":"section","text":{"type":"mrkdwn","text":":red: Unable to deploy Staging form viewer: <https://github.com/cds-snc/platform-forms-client/actions/workflows/staging-build-push-container.yml|ECR push failed>"}}]}' | |
curl -X POST -H 'Content-type: application/json' --data "$json" ${{ secrets.FORMS_DEV_SLACK_WEBHOOK }} | |
exit 1 | |
deploy-form-viewer-service: | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0 | |
- name: Configure AWS credentials | |
# v1 as of Jan 28 2021 | |
uses: aws-actions/configure-aws-credentials@360ea313a73f8d3b7839fb5db64aecf801ad5fda | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ca-central-1 | |
- name: Login to Amazon ECR | |
id: login-ecr | |
# v1 as of Jan 28 2021 | |
uses: aws-actions/amazon-ecr-login@e20c7e407b9882916b0967c1ea26eeee047fe7fc | |
- name: Get Cluster Name | |
id: cluster | |
run: | | |
echo "##[set-output name=name;]$(aws ecs list-clusters | jq -r '.clusterArns[0]' | cut -f 2 -d "/" )" | |
- name: Download Form Viewer task definition | |
id: download-taskdef-form-viewer | |
run: | | |
aws ecs describe-task-definition --task-definition form-viewer --query taskDefinition > form_viewer.json | |
echo "##[set-output name=container_name;]$(jq -r '.containerDefinitions[0].name' form_viewer.json)" | |
- name: Render image for form viewer service | |
id: taskdef-form-viewer | |
# v1.0.10 | |
uses: aws-actions/amazon-ecs-render-task-definition@02b7050c90d5766ff6f26cacf312523f72e85c01 | |
with: | |
task-definition: form_viewer.json | |
container-name: ${{ steps.download-taskdef-form-viewer.outputs.container_name }} | |
image: ${{ steps.login-ecr.outputs.registry }}/form_viewer_staging:${{ github.event.workflow_run.head_sha }} | |
- name: Render appspec for form viewer service | |
run: | | |
CONTAINER_PORT=`jq '.containerDefinitions[0].portMappings[0].containerPort' form_viewer.json` | |
CONTAINER_NAME=${{ steps.download-taskdef-form-viewer.outputs.container_name }} | |
TASKDEF_ARN=`jq -r '.taskDefinitionArn' form_viewer.json | cut -f 1-6 -d "/"` | |
jq --argjson port "$CONTAINER_PORT" --arg cname "$CONTAINER_NAME" --arg taskdefarn "$TASKDEF_ARN" '.Resources[0].TargetService.Properties.TaskDefinition = $taskdefarn | .Resources[0].TargetService.Properties.LoadBalancerInfo.ContainerName = $cname | .Resources[0].TargetService.Properties.LoadBalancerInfo.ContainerPort = $port' config/infrastructure/aws/appspec-template.json > form-viewer-appspec.json | |
- name: Deploy image for Form Viewer | |
timeout-minutes: 10 | |
# v1.4.11 | |
uses: aws-actions/amazon-ecs-deploy-task-definition@3a7cb4515319f9e83698043836c5ad170b482fb4 | |
with: | |
task-definition: ${{ steps.taskdef-form-viewer.outputs.task-definition }} | |
service: form-viewer | |
cluster: ${{ steps.cluster.outputs.name }} | |
wait-for-service-stability: true | |
codedeploy-appspec: ${{ github.workspace }}/form-viewer-appspec.json | |
- name: Logout of Amazon ECR | |
if: always() | |
run: docker logout ${{ steps.login-ecr.outputs.registry }} |