Manually triggered deploy #59
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: Manually triggered deploy | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: 'Environment to deploy to. Version must be specified for production deploy.' | |
type: choice | |
options: | |
- development | |
- production | |
required: true | |
version: | |
description: 'Version to deploy. Required for production deploy. (vX.X.X)' | |
type: string | |
required: false | |
env: | |
AWS_REGION: eu-north-1 | |
ECR_REGISTRY: 590877988961.dkr.ecr.eu-north-1.amazonaws.com | |
ECR_REPOSITORY: intercom-manager | |
ECS_SERVICE: intercom-manager | |
ECS_DEV_TASK_DEFINITION: aws/ecs/taskdef-dev.json | |
ECS_PROD_TASK_DEFINITION: aws/ecs/taskdef-prod.json | |
CONTAINER_NAME: intercom-manager | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
build: | |
if: ${{ inputs.environment == 'development'}} | |
name: Build image and register in ECR | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Configure AWS ECR credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }} | |
flavor: | | |
latest=false | |
tags: type=sha | |
- name: Build docker image and push to Amazon ECR | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
deploy_dev: | |
if: ${{ inputs.environment == 'development'}} | |
name: Deploy to Dev cluster on ECS | |
needs: ['build'] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Configure AWS ECS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.ECS_AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.ECS_AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Checkout source code | |
uses: actions/checkout@v3 | |
- uses: benjlevesque/[email protected] | |
id: short-sha | |
- 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: ${{ env.ECS_DEV_TASK_DEFINITION }} | |
container-name: ${{ env.CONTAINER_NAME }} | |
image: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:sha-${{ steps.short-sha.outputs.sha }} | |
- name: Deploy Amazon ECS task definition | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
with: | |
task-definition: ${{ steps.task-def.outputs.task-definition }} | |
service: ${{ env.ECS_SERVICE }} | |
cluster: development | |
wait-for-service-stability: true | |
deploy_prod: | |
if: ${{ inputs.environment == 'production' && inputs.version }} | |
name: Deploy to Production cluster on ECS | |
runs-on: ubuntu-latest | |
steps: | |
- name: Configure AWS ECS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.ECS_AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.ECS_AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Checkout source code | |
uses: actions/checkout@v3 | |
- uses: benjlevesque/[email protected] | |
id: short-sha | |
- 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: ${{ env.ECS_PROD_TASK_DEFINITION }} | |
container-name: ${{ env.CONTAINER_NAME }} | |
image: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ inputs.version }} | |
- name: Deploy Amazon ECS task definition | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
with: | |
task-definition: ${{ steps.task-def.outputs.task-definition }} | |
service: ${{ env.ECS_SERVICE }} | |
cluster: production | |
wait-for-service-stability: true |