-
Notifications
You must be signed in to change notification settings - Fork 2
144 lines (121 loc) · 4.55 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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