-
Notifications
You must be signed in to change notification settings - Fork 2
409 lines (327 loc) · 14.2 KB
/
api-build-and-push.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
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
name: "api-build-and-push"
on:
workflow_dispatch:
push:
branches:
- emerald-stage
paths-ignore:
- database/**
- package.json
- package-lock.json
- CHANGELOG.md
- .conventional-changelog.mjs
- .release-it.json
- postman/**
- localdb/**
- postgres/**
- crunchydb/**
jobs:
build-backend:
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.400'
- uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget
- name: Setup Tools
uses: ./.github/actions/setup-tools
- name: Build backend
run: |
pwd
dotnet build ./server/server.sln
- name: Test backend
run: dotnet test ./server/server.sln --no-build
# # SonarQube integration for backend
# - name: SonarQube Scan Backend
# uses: sonarsource/sonarcloud-github-action@v2
# env:
# SONAR_HOST_URL: https://sonarcloud.io
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_TEST }}
build-frontend:
runs-on: ubuntu-22.04
timeout-minutes: 10
permissions:
contents: read
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Angular CLI
run: |
cd ./frontend
npm install -g @angular/cli
- name: Install project dependencies
run: |
cd ./frontend
npm install
- name: Build frontend
run: |
cd ./frontend
ng build --configuration=production
- name: Run frontend tests
run: |
cd ./frontend
ng test --watch=false --progress=false --browsers=ChromeHeadless --code-coverage --source-map=false
continue-on-error: true
# # SonarQube integration frontend
# - name: SonarQube Scan
# uses: sonarsource/sonarcloud-github-action@v2
# env:
# SONAR_HOST_URL: https://sonarcloud.io
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_TEST }}
docker-build-backend:
needs: [build-backend]
runs-on: ubuntu-22.04
timeout-minutes: 10
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Setup Tools
uses: ./.github/actions/setup-tools
- name: Build Docker image
run: cd server && docker build -t strdss-backend -f Dockerfile .
- name: Tag Docker image
run: docker tag strdss-backend artifacts.developer.gov.bc.ca/sf4a-strdss/server:dev-6cd0e88
- name: Push Docker image to Artifactory
run: |
docker login artifacts.developer.gov.bc.ca -u ${{ secrets.JFROG_USERNAME }} -p ${{ secrets.JFROG_PASSWORD }}
docker push artifacts.developer.gov.bc.ca/sf4a-strdss/server:dev-6cd0e88
# Update API Specification in the service registry - RBA skip for initial implmentation
# - name: Publish API Specification
# if: steps.helm.outcome == 'success'
# run: |
# set -e # Exit on error
# IMAGE="${{ steps.meta.outputs.tags || steps.meta-test.outputs.tags || steps.meta-prod.outputs.tags }} "
# IMAGE_TAG=$(echo "$IMAGE" | awk -F':' '{print $NF}')
# echo $IMAGE_TAG
# # Get access token from auth endpoint
# export TOKEN=$(curl -X POST \
# ${{ secrets.AUTH_TOKEN_ENDPOINT }} \
# -H 'Content-Type: application/x-www-form-urlencoded' \
# -d grant_type=client_credentials \
# -d client_id=${{ secrets.REGISTRY_CLIENT_ID }} \
# -d client_secret=${{ secrets.REGISTRY_CLIENT_SECRET }} | jq -r '.access_token')
# echo "Access Token: $TOKEN"
# http_response=$(curl -s -o response.txt -w "%{http_code}" -X POST \
# -H "Authorization: Bearer $TOKEN" \
# -H "Content-type: application/json; artifactType=OPENAPI" \
# -H "Authorization: Bearer $TOKEN" \
# -H "X-Registry-ArtifactId: justin-claim" \
# -d @CustomClaimApiSpec.json \
# ${{ secrets.SERVICE_REGISTRY_HOST_URL }}/apis/registry/v2/groups/JUSTIN/artifacts?ifExists=UPDATE)
# if [ $http_response != "200" ]; then
# echo "Error: Failed to publish artifacts"
# echo "Server returned:"
# cat response.txt
# exit 1
# else
# echo "Server returned:"
# cat response.txt
# fi
# working-directory: ${{env.working-directory}}
docker-build-frontend:
needs: [build-frontend]
runs-on: ubuntu-22.04
timeout-minutes: 10
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Setup Tools
uses: ./.github/actions/setup-tools
- name: Render style_nonce
id: render_style_nonce
run: echo "::set-output name=style_nonce::$(echo -n ${{ github.sha }} | base64)"
- name: Build Docker image
run: cd frontend && docker build -t strdss-frontend -f Dockerfile .
- name: Tag Docker image
run: docker tag strdss-frontend artifacts.developer.gov.bc.ca/sf4a-strdss/frontend:dev-6cd0e88
- name: Push Docker image to Artifactory
run: |
docker login artifacts.developer.gov.bc.ca -u ${{ secrets.JFROG_USERNAME }} -p ${{ secrets.JFROG_PASSWORD }}
docker push artifacts.developer.gov.bc.ca/sf4a-strdss/frontend:dev-6cd0e88
package-h-chart-webapi-core:
needs: [docker-build-backend]
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- name: Checkout ArgoCD Repo
id: gitops
# if: steps.publish.outcome == 'success'
uses: actions/checkout@v4
with:
repository: bcgov-c/tenant-gitops-b0471a
ref: develop
token: ${{ secrets.GITOPS }} # `GITOPS` is a secret that contains your PAT
path: gitops
- name: Update Helm Values and Commit Webapi-core
id: helm
# if: steps.gitops.outcome == 'success' # Only run if the previous step (publish) was successful
run: |
pwd
ls -ARl gitops/
# Navigate to the directory containing your Helm values file for the environment develop -> DEV, test -> test and
#cd gitops
cd gitops/charts/webapi-core
IMAGE="${{ steps.meta.outputs.tags || steps.meta-test.outputs.tags || steps.meta-prod.outputs.tags }} "
IMAGE_TAG=$(echo "$IMAGE" | awk -F':' '{print $NF}')
echo "Image Tag:"
echo $IMAGE_TAG
# Update the Helm values file with the new image tag or (SHA)
DATETIME=$(date +'%Y-%m-%d %H:%M:%S') # Get current date and time
# check if branch is dev update dev_values with sed if branch is test update test value if branch is main update prod values
if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
echo "This is the main branch"
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/prod_values.yaml
elif [[ "$GITHUB_REF" == "refs/heads/emerald" ]]; then
echo "This is the emerald branch"
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/dev_values.yaml
elif [[ "$GITHUB_REF" == "refs/heads/test" ]]; then
echo "This is the test branch"
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/test_values.yaml
else
echo updating dev values for CIs
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/dev_values.yaml
fi
# Commit and push the changes
git config --global user.email "[email protected]"
git config --global user.name "Rick Anderson"
git add ../../deploy/dev_values.yaml
git add ../../deploy/prod_values.yaml
git add ../../deploy/test_values.yaml
pwd
# Repackage Helm Chart
cd ../gitops/charts
helm package ../../webapi-core/
git add .
git commit -m "Update image tag to $IMAGE_TAG on $DATETIME"
git push origin develop # Update the branch name as needed
package-h-chart-react-baseapp:
needs: [docker-build-frontend]
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- name: Checkout ArgoCD Repo
id: gitops
# if: steps.publish.outcome == 'success'
uses: actions/checkout@v4
with:
repository: bcgov-c/tenant-gitops-b0471a
ref: develop
token: ${{ secrets.GITOPS }} # `GITOPS` is a secret that contains your PAT
path: gitops
- name: Update Helm Values and Commit Webapi-core
id: helm
# if: steps.gitops.outcome == 'success' # Only run if the previous step (publish) was successful
run: |
pwd
ls -ARl gitops/
# Navigate to the directory containing your Helm values file for the environment develop -> DEV, test -> test and
#cd gitops
cd gitops/charts/react-baseapp
IMAGE="${{ steps.meta.outputs.tags || steps.meta-test.outputs.tags || steps.meta-prod.outputs.tags }} "
IMAGE_TAG=$(echo "$IMAGE" | awk -F':' '{print $NF}')
echo "Image Tag:"
echo $IMAGE_TAG
# Update the Helm values file with the new image tag or (SHA)
DATETIME=$(date +'%Y-%m-%d %H:%M:%S') # Get current date and time
# check if branch is dev update dev_values with sed if branch is test update test value if branch is main update prod values
if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
echo "This is the main branch"
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/prod_values.yaml
elif [[ "$GITHUB_REF" == "refs/heads/emerald" ]]; then
echo "This is the emerald branch"
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/dev_values.yaml
elif [[ "$GITHUB_REF" == "refs/heads/test" ]]; then
echo "This is the test branch"
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/test_values.yaml
else
echo updating dev values for CIs
sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/dev_values.yaml
fi
# Commit and push the changes
git config --global user.email "[email protected]"
git config --global user.name "Rick Anderson"
git add ../../deploy/dev_values.yaml
git add ../../deploy/prod_values.yaml
git add ../../deploy/test_values.yaml
pwd
# Repackage Helm Chart
cd ../gitops/charts
helm package ../../react-baseapp/
git add .
git commit -m "Update image tag to $IMAGE_TAG on $DATETIME"
git push origin develop # Update the branch name as needed
# package-h-chart-database:
#needs: [docker-build-frontend]
# runs-on: ubuntu-22.04
# timeout-minutes: 10
# steps:
# - name: Checkout ArgoCD Repo
# id: gitops
# if: steps.publish.outcome == 'success'
# uses: actions/checkout@v4
# with:
# repository: bcgov-c/tenant-gitops-b0471a
# ref: develop
# token: ${{ secrets.GITOPS }} # `GITOPS` is a secret that contains your PAT
# path: gitops
# - name: Update Helm Values and Commit database
# id: helm
# if: steps.gitops.outcome == 'success' # Only run if the previous step (publish) was successful
# run: |
# pwd
# ls -ARl gitops/
# Navigate to the directory containing your Helm values file for the environment develop -> DEV, test -> test and
#cd gitops
# cd gitops/charts/database
# IMAGE="${{ steps.meta.outputs.tags || steps.meta-test.outputs.tags || steps.meta-prod.outputs.tags }} "
# IMAGE_TAG=$(echo "$IMAGE" | awk -F':' '{print $NF}')
# echo "Image Tag:"
# echo $IMAGE_TAG
# # Update the Helm values file with the new image tag or (SHA)
# DATETIME=$(date +'%Y-%m-%d %H:%M:%S') # Get current date and time
# check if branch is dev update dev_values with sed if branch is test update test value if branch is main update prod values
# if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
# echo "This is the main branch"
# sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/prod_values.yaml
# elif [[ "$GITHUB_REF" == "refs/heads/emerald" ]]; then
# echo "This is the emerald branch"
# sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/dev_values.yaml
# elif [[ "$GITHUB_REF" == "refs/heads/test" ]]; then
# echo "This is the test branch"
# sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/test_values.yaml
# else
# echo updating dev values for CIs
# sed -i "s/tag: .*/tag: $IMAGE_TAG # Image Updated on $DATETIME/" ../../deploy/dev_values.yaml
# fi
# Commit and push the changes
# git config --global user.email "[email protected]"
# git config --global user.name "Rick Anderson"
# git add ../../deploy/dev_values.yaml
# git add ../../deploy/prod_values.yaml
# git add ../../deploy/test_values.yaml
# pwd
# Repackage Helm Chart
# cd ../gitops/charts
# helm package ../../database/
# git add .
# ls -s
# git commit -m "Update image tag to $IMAGE_TAG on $DATETIME"
# git push origin develop # Update the branch name as needed