-
Notifications
You must be signed in to change notification settings - Fork 2
102 lines (85 loc) · 2.95 KB
/
dispatch.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Manually triggered deploy
on:
workflow_dispatch:
inputs:
deploy:
description: 'Deploy to ECS dev'
type: boolean
required: true
default: 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_CLUSTER: development
ECS_TASK_DEFINITION: aws/ecs/taskdef-dev.json
CONTAINER_NAME: intercom-manager
defaults:
run:
shell: bash
jobs:
build:
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:
if: ${{ inputs.deploy }}
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_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: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true