-
Notifications
You must be signed in to change notification settings - Fork 0
258 lines (225 loc) · 8.42 KB
/
test.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
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
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@v4
- 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@v4
with:
ref: ${{ needs.tag.outputs.tag }}
- name: Build Static
id: build_image
uses: redhat-actions/buildah-build@v2
with:
context: .
layers: true
image: drivebc-static
tags: latest latest-test ${{ github.sha }} ${{ needs.tag.outputs.tag }}
labels: |
app=drivebc
containerfiles: ./compose/frontend/StaticBuild
build-args: |
FONTAWESOME_PACKAGE_TOKEN=${{ secrets.FONTAWESOME_PACKAGE_TOKEN }}
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-backend:
needs: [tag]
runs-on: ubuntu-latest
name: Build & Push Backend Image
environment: test
steps:
- name: Checkout Code
uses: actions/checkout@v4
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@v4
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@v4
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 }}
versionUpdate:
needs: [tag, build-static, build-backend, build-redis, build-openshiftjobs]
runs-on: ubuntu-latest
name: Deploy Latest Images
environment:
name: test
url: https://test-drivebc.apps.gold.devops.gov.bc.ca
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Authenticate and set context
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
namespace: ${{ vars.OPENSHIFT_NAMESPACE }}
insecure_skip_tls_verify: true
- name: Helm upgrade on OpenShift Environment
run: |
helm dependency update ./infrastructure/main
helm upgrade test-drivebc -f ./infrastructure/main/values-test.yaml ./infrastructure/main --set django.image.tag="${{ needs.tag.outputs.tag }}" --set redis.image.tag="${{ needs.tag.outputs.tag }}" --set static.image.tag="${{ needs.tag.outputs.tag }}" --set tasks.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