-
Notifications
You must be signed in to change notification settings - Fork 2
302 lines (264 loc) · 10.3 KB
/
Copy pathtest.yml
File metadata and controls
302 lines (264 loc) · 10.3 KB
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
name: 2. Create Tag & Build/Deploy to Test
# This workflow can be triggered manually or by creating a tag starting with 'v'
env:
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
REGISTRY_USER: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ github.token }}
permissions:
packages: write
on:
push:
tags:
- 'v*' # Trigger this workflow only for tags starting with "v"
workflow_dispatch:
inputs:
tag_name:
description: 'Create a tag starting with v0.0.0 (Yr, Sprint, Build)'
required: true
jobs:
tag:
runs-on: ubuntu-latest
name: Create Tag and set Variable
permissions:
contents: write
outputs:
tag: ${{ steps.set_tag_name.outputs.tag }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create Tag (if manually triggered)
if: github.event_name == 'workflow_dispatch'
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git tag ${{ github.event.inputs.tag_name }}
git push origin ${{ github.event.inputs.tag_name }}
- name: Set Tag Name
id: set_tag_name
run: |
if [ "${{ github.event_name }}" == 'workflow_dispatch' ]; then
echo "tag=${{ github.event.inputs.tag_name }}" >> $GITHUB_OUTPUT
else
echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi
- name: Display Tag Name
run: |
echo "Tag Name: ${{ steps.set_tag_name.outputs.tag }}"
build-static:
needs: [tag]
runs-on: ubuntu-latest
name: Build & Push Static Image
environment: test
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
ref: ${{ needs.tag.outputs.tag }}
- name: Log in to the Container registry (GitHub)
uses: docker/login-action@v3
with:
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
- name: Log in to OpenShift Registry
uses: docker/login-action@v3
with:
registry: ${{ vars.OPENSHIFT_IMAGESTREAM_URL }}
username: ${{ secrets.OPENSHIFT_IMAGESTREAM_USERNAME }}
password: ${{ secrets.OPENSHIFT_IMAGESTREAM_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE_REGISTRY }}/drivebc-static
${{ vars.OPENSHIFT_IMAGESTREAM_URL }}drivebc-static
tags: |
type=raw,value=latest
type=raw,value=latest-test
type=sha,format=long
type=raw,value=${{ needs.tag.outputs.tag }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push to both registries
uses: docker/build-push-action@v6
with:
context: .
file: ./compose/frontend/StaticBuild
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: |
${{ steps.meta.outputs.labels }}
app=drivebc
build-args: |
DEBUG_BUILD=true
secrets: |
"FONTAWESOME_PACKAGE_TOKEN=${{ secrets.FONTAWESOME_PACKAGE_TOKEN }}"
build-backend:
needs: [tag]
runs-on: ubuntu-latest
name: Build & Push Backend Image
environment: test
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
ref: ${{ needs.tag.outputs.tag }}
- name: Build Backend
id: build_image
uses: redhat-actions/buildah-build@v2
with:
image: drivebc-django
tags: latest latest-test ${{ github.sha }} ${{ needs.tag.outputs.tag }}
labels: |
app=drivebc
containerfiles: ./compose/backend/Dockerfile
build-args:
DEBUG_BUILD=true
- name: Push to Github Packages
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
# Backup to handle scenarios where Github packages is down. Confluence has documentation on switching the source.
- name: Push to OpenShift ImageStream
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build_image.outputs.image }}
tags: latest latest-test
registry: ${{ vars.OPENSHIFT_IMAGESTREAM_URL }}
username: ${{ secrets.OPENSHIFT_IMAGESTREAM_USERNAME }}
password: ${{ secrets.OPENSHIFT_IMAGESTREAM_TOKEN }}
build-redis:
needs: [tag]
runs-on: ubuntu-latest
name: Build & Push Redis Image
environment: test
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
ref: ${{ needs.tag.outputs.tag }}
- name: Build Redis
id: build_image
uses: redhat-actions/buildah-build@v2
with:
image: drivebc-redis
tags: latest latest-test ${{ github.sha }} ${{ needs.tag.outputs.tag }}
labels: |
app=drivebc
containerfiles: ./compose/redis/Dockerfile
- name: Push to Github Packages
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
# Backup to handle scenarios where Github packages is down. Confluence has documentation on switching the source.
- name: Push to OpenShift ImageStream
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build_image.outputs.image }}
tags: latest latest-test
registry: ${{ vars.OPENSHIFT_IMAGESTREAM_URL }}
username: ${{ secrets.OPENSHIFT_IMAGESTREAM_USERNAME }}
password: ${{ secrets.OPENSHIFT_IMAGESTREAM_TOKEN }}
build-openshiftjobs:
needs: [tag]
runs-on: ubuntu-latest
name: Build & Push OpenShift Jobs Image
environment: test
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
ref: ${{ needs.tag.outputs.tag }}
- name: Build OpenShift Jobs
id: build_image
uses: redhat-actions/buildah-build@v2
with:
image: drivebc-openshiftjobs
tags: latest latest-test ${{ github.sha }} ${{ needs.tag.outputs.tag }}
labels: |
app=drivebc
containerfiles: ./compose/openshiftjobs/DockerFile
- name: Push to Github Packages
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
# Backup to handle scenarios where Github packages is down. Confluence has documentation on switching the source.
- name: Push to OpenShift ImageStream
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build_image.outputs.image }}
tags: latest latest-test
registry: ${{ vars.OPENSHIFT_IMAGESTREAM_URL }}
username: ${{ secrets.OPENSHIFT_IMAGESTREAM_USERNAME }}
password: ${{ secrets.OPENSHIFT_IMAGESTREAM_TOKEN }}
update-openshift-gold:
needs: [tag, build-static, build-backend, build-redis, build-openshiftjobs]
runs-on: ubuntu-latest
name: Deploy Latest Images to OpenShift Gold
environment:
name: test
url: https://test-drivebc.apps.gold.devops.gov.bc.ca
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Install CLI tools from OpenShift Mirror
uses: redhat-actions/openshift-tools-installer@v1
with:
oc: "4"
skip_cache: true
- name: Authenticate and set context
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ vars.OPENSHIFT_GOLD_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_GOLD_TOKEN }}
namespace: ${{ vars.OPENSHIFT_NAMESPACE }}
insecure_skip_tls_verify: false
- name: Helm upgrade on OpenShift Gold Environment
run: |
helm upgrade test-drivebc -f ./infrastructure/main/values-test.yaml ./infrastructure/main --set static.image.tag=${{ needs.tag.outputs.tag }} --set django.image.tag=${{ needs.tag.outputs.tag }} --set tasks.image.tag=${{ needs.tag.outputs.tag }} --set image-consumer.image.tag=${{ needs.tag.outputs.tag }} --set redis.image.tag=${{ needs.tag.outputs.tag }} --set openshiftjobs.image.tag=${{ needs.tag.outputs.tag }}
# I have this run after the push to Gold because I want to make sure that Gold runs the migrations first. Gold DR can't run migrations as DB is read-only
update-openshift-golddr:
needs: [tag, update-openshift-gold]
runs-on: ubuntu-latest
name: Deploy Latest Images to OpenShift GoldDR
environment:
name: test
url: https://test-drivebc.apps.golddr.devops.gov.bc.ca
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Install CLI tools from OpenShift Mirror
uses: redhat-actions/openshift-tools-installer@v1
with:
oc: "4"
skip_cache: true
- name: Authenticate and set context
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ vars.OPENSHIFT_GOLDDR_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_GOLDDR_TOKEN }}
namespace: ${{ vars.OPENSHIFT_NAMESPACE }}
insecure_skip_tls_verify: false
- name: Helm upgrade on OpenShift GoldDR Environment
run: |
helm upgrade test-drivebc -f ./infrastructure/main/values-test.yaml -f ./infrastructure/main/values-test-dr.yaml ./infrastructure/main --set static.image.tag=${{ needs.tag.outputs.tag }} --set django.image.tag=${{ needs.tag.outputs.tag }} --set tasks.image.tag=${{ needs.tag.outputs.tag }} --set image-consumer.image.tag=${{ needs.tag.outputs.tag }} --set redis.image.tag=${{ needs.tag.outputs.tag }} --set openshiftjobs.image.tag=${{ needs.tag.outputs.tag }}
# automatedTests:
# needs: [versionUpdate]
# name: Automated Smoke Test
# uses: bcgov/DriveBC.ca-automated-tests/.github/workflows/playwright.yml@main
# with:
# environment: 'test'
# secrets: inherit