Deploy to production #87
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 production | |
permissions: | |
id-token: write | |
contents: read | |
on: workflow_dispatch | |
jobs: | |
deploy: | |
name: Deploy to production | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-region: eu-west-2 | |
role-to-assume: arn:aws:iam::430723991443:role/github-actions-deployer-role | |
- name: Log in to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Fill in the new image ID in the Amazon ECS task definition | |
id: task-def | |
uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
with: | |
task-definition: .aws/task-definition-prod.json | |
container-name: ${{ github.event.repository.name }} | |
image: ${{ steps.login-ecr.outputs.registry }}/${{ github.event.repository.name }}:stable | |
- name: Deploy Amazon ECS task definition | |
id: ecs-deploy | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
with: | |
task-definition: ${{ steps.task-def.outputs.task-definition }} | |
service: ${{ github.event.repository.name }} | |
cluster: revalidation-prod | |
wait-for-service-stability: true | |
- name: Verify ECS deployment | |
run: | | |
CURRENT_TASK_DEF_ARN=$(aws ecs describe-services --cluster revalidation-prod --service ${{ github.event.repository.name }} --query services[0].deployments[0].taskDefinition | jq -r ".") | |
NEW_TASK_DEF_ARN=${{ steps.ecs-deploy.outputs.task-definition-arn }} | |
echo "Current task arn: $CURRENT_TASK_DEF_ARN" | |
echo "New task arn: $NEW_TASK_DEF_ARN" | |
if [ "$CURRENT_TASK_DEF_ARN" != "$NEW_TASK_DEF_ARN" ]; then | |
echo "Deployment failed." | |
exit 1 | |
fi | |
- name: Slack Notification success | |
if: success() | |
uses: rtCamp/[email protected] | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_TITLE: 'tis-revalidation-recommendation has been deployed through the pipeline' | |
- name: Slack Notification failure | |
if: failure() | |
uses: rtCamp/[email protected] | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_TITLE: "tis-revalidation-recommendation build has failed in the pipeline" | |
SLACK_COLOR: "#fc1303" |