-
Notifications
You must be signed in to change notification settings - Fork 19
210 lines (162 loc) · 7.42 KB
/
buildDeploy.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: Build and deploy docker image
on:
workflow_dispatch: # Allows manual workflow trigger
repository_dispatch: # Allows API workflow trigger
concurrency:
group: dapp
cancel-in-progress: true
# Set global env variables
env:
AWS_REGION: eu-west-2
ECR_REPOSITORY: app-frontend
IMAGE_TAG: ${{ github.event.client_payload.COMMIT_HASH != null && github.event.client_payload.COMMIT_HASH || github.sha }}
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
jobs:
# # Build dapp frontend and push to AWS ECR
buildAndPush:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.4.1
with:
access_token: ${{ github.token }}
- name: Echo Env Vars through Context
run: |
echo "$GITHUB_CONTEXT"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.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: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Checkout relevant branch
run:
git checkout ${{ github.event.client_payload.COMMIT_HASH != null && github.event.client_payload.COMMIT_HASH || github.sha }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push
uses: docker/build-push-action@v3
with:
context: ${{ github.workspace }}
file: ./Dockerfile
push: true
tags: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/app-frontend:${{ env.IMAGE_TAG }}
- uses: sarisia/actions-status-discord@c193626e5ce172002b8161e116aa897de7ab5383
if: always()
with:
webhook: ${{ env.DISCORD_WEBHOOK }}
title: "Build and push"
# Deploy dapp frontend to QA environment
deployQA:
needs: buildAndPush
runs-on: ubuntu-latest
env:
NAMESPACE: dapp
CLUSTER_NAME: qa-cluster
ENVIRONMENT_TAG: qa
REPOSITORY_NAME: app-frontend
steps:
- name: Configure AWS credentials for EKS
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/eks-admin
role-session-name: github-cicd
role-duration-seconds: 1200
aws-region: ${{ env.AWS_REGION }}
- name: Configure AWS EKS
run: |
aws eks --region ${{ env.AWS_REGION }} update-kubeconfig --name ${{ env.CLUSTER_NAME }}
- name: Deploy to Kubernetes cluster
env:
RELEASE_IMAGE: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
run: |
kubectl set image deployment/dapp-${{ env.ENVIRONMENT_TAG }}-network-100 dapp=${{ env.RELEASE_IMAGE }} -n $NAMESPACE
- name: Validate Kubernetes deployment
run: |
kubectl rollout status deployment/dapp-${{ env.ENVIRONMENT_TAG }}-network-100 -n ${{ env.NAMESPACE }}
- uses: sarisia/actions-status-discord@c193626e5ce172002b8161e116aa897de7ab5383
if: always()
with:
webhook: ${{ env.DISCORD_WEBHOOK }}
title: "Deploy to QA"
# Deploy dapp frontend to staging environment and sync production data to staging
deployStaging:
needs: deployQA
environment: 'staging'
runs-on: ubuntu-latest
env:
NAMESPACE: dapp-staging
CLUSTER_NAME: prod-cluster
ENVIRONMENT_TAG: staging
REPOSITORY_NAME: app-frontend
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_PROD }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_PROD }}
aws-region: ${{ env.AWS_REGION }}
- name: Configure AWS EKS
run: |
aws eks --region ${{ env.AWS_REGION }} update-kubeconfig --name ${{ env.CLUSTER_NAME }}
- name: Deploy to Kubernetes cluster
env:
RELEASE_IMAGE: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
run: |
kubectl set image deployment/dapp-${{ env.ENVIRONMENT_TAG }}-network-100 dapp=${{ env.RELEASE_IMAGE }} -n $NAMESPACE
- name: Validate Kubernetes deployment
run: |
kubectl rollout status deployment/dapp-${{ env.ENVIRONMENT_TAG }}-network-100 -n ${{ env.NAMESPACE }}
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@f2696244ec00ed5c659a5cc77f7138ad0302dffb
with:
token: ${{ secrets.COLONY_INFRASTRUCTURE_PROD_TO_STAGING_TOKEN }}
repository: JoinColony/colonyInfrastructure
event-type: data-sync
- uses: sarisia/actions-status-discord@c193626e5ce172002b8161e116aa897de7ab5383
if: always()
with:
webhook: ${{ env.DISCORD_WEBHOOK }}
title: "Deploy to Staging"
# Deploy dapp frontend to production environment
deployProd:
needs: deployStaging
environment: 'prod'
runs-on: ubuntu-latest
env:
NAMESPACE: prod
CLUSTER_NAME: prod-cluster
ENVIRONMENT_TAG: prod
REPOSITORY_NAME: app-frontend
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_PROD }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_PROD }}
aws-region: ${{ env.AWS_REGION }}
- name: Configure AWS EKS
run: |
aws eks --region ${{ env.AWS_REGION }} update-kubeconfig --name ${{ env.CLUSTER_NAME }}
- name: Deploy to Kubernetes cluster
env:
RELEASE_IMAGE: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
run: |
kubectl set image deployment/dapp-${{ env.ENVIRONMENT_TAG }}-network-100 dapp=${{ env.RELEASE_IMAGE }} -n $NAMESPACE
- name: Validate Kubernetes deployment
run: |
kubectl rollout status deployment/dapp-${{ env.ENVIRONMENT_TAG }}-network-100 -n ${{ env.NAMESPACE }}
- uses: sarisia/actions-status-discord@c193626e5ce172002b8161e116aa897de7ab5383
if: always()
with:
webhook: ${{ env.DISCORD_WEBHOOK }}
title: "Deploy to Production"