Skip to content

Deploy Production

Deploy Production #32

name: Deploy Production
on:
workflow_run:
workflows: ["CI"]
types:
- completed
permissions:
id-token: write
contents: read
jobs:
deploy_production:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'production' }}
name: Deploy Production
runs-on: ubuntu-latest
environment: production
steps:
- name: checkout
uses: actions/checkout@v2
- name: Configure AWS credentials for Production environment account
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: my-library-nyc-app
IMAGE_TAG: ${{ github.sha }}
run: |
DOCKER_BUILDKIT=1 docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:production-latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:production-latest
- name: Force ECS Update
run: |
aws ecs update-service --cluster mylibrarynycapp-production --service mylibrarynycapp-production --force-new-deployment
aws ecs update-service --cluster mylibrarynycapp-production --service mylibrarynycapp-production-delayed-job --force-new-deployment