@@ -54,24 +54,124 @@ jobs:
54
54
-t ${{ vars.ECR_URL }}:$SHA .
55
55
56
56
- name : Push to ECR
57
+ run : docker push ${{ vars.ECR_URL }}:$SHA
58
+
59
+ deploy-staging :
60
+ runs-on : ubuntu-latest
61
+ needs : build
62
+ environment : staging
63
+
64
+ permissions :
65
+ id-token : write # This is required for requesting the JWT
66
+ contents : read # This is required for actions/checkout
67
+
68
+ env :
69
+ KUBE_NAMESPACE : ${{ secrets.KUBE_NAMESPACE }}
70
+ KUBE_CERT : ${{ secrets.KUBE_CERT }}
71
+ KUBE_TOKEN : ${{ secrets.KUBE_TOKEN }}
72
+ KUBE_CLUSTER : ${{ secrets.KUBE_CLUSTER }}
73
+
74
+ steps :
75
+ - name : Checkout
76
+ uses : actions/checkout@v4
77
+
78
+ - name : Assume role in Cloud Platform
79
+ uses : aws-actions/configure-aws-credentials@v4
80
+ with :
81
+ role-to-assume : ${{ secrets.ECR_ROLE_TO_ASSUME }}
82
+ aws-region : ${{ vars.ECR_REGION }}
83
+
84
+ - name : Login to container repository
85
+ uses : aws-actions/amazon-ecr-login@v2
86
+ id : login-ecr
87
+
88
+ - name : Store build tag
89
+ id : vars
57
90
run : |
91
+ branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
92
+ short_sha=$(git rev-parse --short $SHA)
93
+ build_tag=$PREFIX-$branch-$short_sha
94
+ echo "build_tag=$build_tag" >> $GITHUB_OUTPUT
95
+
96
+ - name : Tag build and push to ECR
97
+ run : |
98
+ docker pull ${{ vars.ECR_URL }}:$SHA
58
99
docker tag ${{ vars.ECR_URL }}:$SHA ${{ vars.ECR_URL }}:staging.latest
59
- docker tag ${{ vars.ECR_URL }}:$SHA ${{ vars.ECR_URL }}:production.latest
60
- docker push ${{ vars.ECR_URL }}:$SHA
61
100
docker push ${{ vars.ECR_URL }}:staging.latest
62
- docker push ${{ vars.ECR_URL }}:production.latest
63
101
64
- deploy-staging :
102
+ - name : Authenticate to the cluster
103
+ run : |
104
+ echo "${KUBE_CERT}" > ca.crt
105
+ kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER}
106
+ kubectl config set-credentials deploy-user --token=${KUBE_TOKEN}
107
+ kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE}
108
+ kubectl config use-context ${KUBE_CLUSTER}
109
+
110
+ - name : Rollout restart deployment
111
+ run : |
112
+ kubectl set image -n ${KUBE_NAMESPACE} \
113
+ deployment/disclosure-checker-staging \
114
+ webapp="${{ vars.ECR_URL }}:$SHA"
115
+
116
+ - name : Send deploy notification to product Slack channel
117
+ uses : slackapi/slack-github-action@v1.25.0
118
+ with :
119
+ payload : |
120
+ {
121
+ "attachments": [
122
+ {
123
+ "color": "#1d990c",
124
+ "text": "${{ github.actor }} deployed *${{ steps.vars.outputs.build_tag }}* to *Staging*",
125
+ "fields": [
126
+ {
127
+ "title": "Project",
128
+ "value": "Disclosure Checker",
129
+ "short": true
130
+ }
131
+ ],
132
+ "actions": [
133
+ {
134
+ "text": "Visit Job",
135
+ "type": "button",
136
+ "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
137
+ }
138
+ ]
139
+ }
140
+ ]
141
+ }
142
+ env :
143
+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
144
+ SLACK_WEBHOOK_TYPE : INCOMING_WEBHOOK
145
+
146
+ deploy-qa :
65
147
runs-on : ubuntu-latest
66
148
needs : build
149
+ environment : qa
150
+
151
+ permissions :
152
+ id-token : write # This is required for requesting the JWT
153
+ contents : read # This is required for actions/checkout
67
154
68
155
env :
69
156
KUBE_NAMESPACE : ${{ secrets.KUBE_NAMESPACE }}
157
+ KUBE_CERT : ${{ secrets.KUBE_CERT }}
158
+ KUBE_TOKEN : ${{ secrets.KUBE_TOKEN }}
159
+ KUBE_CLUSTER : ${{ secrets.KUBE_CLUSTER }}
70
160
71
161
steps :
72
162
- name : Checkout
73
163
uses : actions/checkout@v4
74
164
165
+ - name : Assume role in Cloud Platform
166
+ uses : aws-actions/configure-aws-credentials@v4
167
+ with :
168
+ role-to-assume : ${{ secrets.ECR_ROLE_TO_ASSUME }}
169
+ aws-region : ${{ vars.ECR_REGION }}
170
+
171
+ - name : Login to container repository
172
+ uses : aws-actions/amazon-ecr-login@v2
173
+ id : login-ecr
174
+
75
175
- name : Store build tag
76
176
id : vars
77
177
run : |
@@ -80,11 +180,13 @@ jobs:
80
180
build_tag=$PREFIX-$branch-$short_sha
81
181
echo "build_tag=$build_tag" >> $GITHUB_OUTPUT
82
182
183
+ - name : Tag build and push to ECR
184
+ run : |
185
+ docker pull ${{ vars.ECR_URL }}:$SHA
186
+ docker tag ${{ vars.ECR_URL }}:$SHA ${{ vars.ECR_URL }}:qa.latest
187
+ docker push ${{ vars.ECR_URL }}:qa.latest
188
+
83
189
- name : Authenticate to the cluster
84
- env :
85
- KUBE_CERT : ${{ secrets.KUBE_CERT }}
86
- KUBE_TOKEN : ${{ secrets.KUBE_TOKEN }}
87
- KUBE_CLUSTER : ${{ secrets.KUBE_CLUSTER }}
88
190
run : |
89
191
echo "${KUBE_CERT}" > ca.crt
90
192
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER}
95
197
- name : Rollout restart deployment
96
198
run : |
97
199
kubectl set image -n ${KUBE_NAMESPACE} \
98
- deployment/disclosure-checker-deployment-staging \
200
+ deployment/disclosure-checker-qa \
99
201
webapp="${{ vars.ECR_URL }}:$SHA"
100
202
101
203
- name : Send deploy notification to product Slack channel
@@ -106,7 +208,7 @@ jobs:
106
208
"attachments": [
107
209
{
108
210
"color": "#1d990c",
109
- "text": "${{ github.actor }} deployed *${{ steps.vars.outputs.build_tag }}* to *Staging *",
211
+ "text": "${{ github.actor }} deployed *${{ steps.vars.outputs.build_tag }}* to *QA *",
110
212
"fields": [
111
213
{
112
214
"title": "Project",
@@ -134,13 +236,30 @@ jobs:
134
236
if : ${{ github.ref == 'refs/heads/main' }}
135
237
environment : production
136
238
239
+ permissions :
240
+ id-token : write # This is required for requesting the JWT
241
+ contents : read # This is required for actions/checkout
242
+
137
243
env :
138
- KUBE_NAMESPACE : ${{ secrets.KUBE_PROD_NAMESPACE }}
244
+ KUBE_NAMESPACE : ${{ secrets.KUBE_NAMESPACE }}
245
+ KUBE_CERT : ${{ secrets.KUBE_CERT }}
246
+ KUBE_TOKEN : ${{ secrets.KUBE_TOKEN }}
247
+ KUBE_CLUSTER : ${{ secrets.KUBE_CLUSTER }}
139
248
140
249
steps :
141
250
- name : Checkout
142
251
uses : actions/checkout@v4
143
252
253
+ - name : Assume role in Cloud Platform
254
+ uses : aws-actions/configure-aws-credentials@v4
255
+ with :
256
+ role-to-assume : ${{ secrets.ECR_ROLE_TO_ASSUME }}
257
+ aws-region : ${{ vars.ECR_REGION }}
258
+
259
+ - name : Login to container repository
260
+ uses : aws-actions/amazon-ecr-login@v2
261
+ id : login-ecr
262
+
144
263
- name : Store build tag
145
264
id : vars
146
265
run : |
@@ -149,11 +268,13 @@ jobs:
149
268
build_tag=$PREFIX-$branch-$short_sha
150
269
echo "build_tag=$build_tag" >> $GITHUB_OUTPUT
151
270
271
+ - name : Tag build and push to ECR
272
+ run : |
273
+ docker pull ${{ vars.ECR_URL }}:$SHA
274
+ docker tag ${{ vars.ECR_URL }}:$SHA ${{ vars.ECR_URL }}:production.latest
275
+ docker push ${{ vars.ECR_URL }}:production.latest
276
+
152
277
- name : Authenticate to the cluster
153
- env :
154
- KUBE_CERT : ${{ secrets.KUBE_PROD_CERT }}
155
- KUBE_TOKEN : ${{ secrets.KUBE_PROD_TOKEN }}
156
- KUBE_CLUSTER : ${{ secrets.KUBE_PROD_CLUSTER }}
157
278
run : |
158
279
echo "${KUBE_CERT}" > ca.crt
159
280
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER}
@@ -164,7 +285,7 @@ jobs:
164
285
- name : Rollout restart deployment
165
286
run : |
166
287
kubectl set image -n ${KUBE_NAMESPACE} \
167
- deployment/disclosure-checker-deployment- production \
288
+ deployment/disclosure-checker-production \
168
289
webapp="${{ vars.ECR_URL }}:$SHA"
169
290
170
291
- name : Send deploy notification to product Slack channel
0 commit comments