-
Notifications
You must be signed in to change notification settings - Fork 11
484 lines (480 loc) · 22.4 KB
/
release.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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
name: Docker Image CI Release
on:
push:
branches:
- main
- development
- version-*
- feature-*
- fix/security-fixes
pull_request:
branches:
- main
- development
- version-*
- feature-*
jobs:
Build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- name: Default Environment Variables
run:
export NAME=$(grep CONTAINER_PROJECT_NAME= .env | cut -d '=' -f2);
export REGISTRY=$(grep CONTAINER_REGISTRY_BASE= .env | cut -d '=' -f2);
echo "https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables";
echo "GITHUB_WORKFLOW is $GITHUB_WORKFLOW";
echo "GITHUB_WORKFLOW_REF is $GITHUB_WORKFLOW_REF";
echo "GITHUB_RUN_ATTEMPT is $GITHUB_RUN_ATTEMPT";
echo "GITHUB_REF is $GITHUB_REF";
echo "GITHUB_REF_NAME is $GITHUB_REF_NAME";
echo "GITHUB_REF_PROTECTED is $GITHUB_REF_PROTECTED";
echo "APP_NAME=$NAME" >> $GITHUB_ENV;
export VERSION=$(grep APP_VERSION= .env | cut -d '=' -f2);
export RELEASE=$VERSION.$(date --utc +%y%m%d);
echo "RELEASE=$RELEASE" >> $GITHUB_ENV;
echo "REGISTRY_BASE=$REGISTRY" >> $GITHUB_ENV;
- name: Create vendor folder
run: |
mkdir api/vendor
chmod +777 api/vendor
chmod +777 -R api/public
- name: Setting APP_NAME
run: |
export NAME=$(grep APP_NAME= .env | cut -d '=' -f2)
echo "APP_NAME=$NAME" >> $GITHUB_ENV
- name: Print app name
run: echo "APP_NAME = $APP_NAME"
- name: Setting APP_ENV to dev
run: |
echo "APP_ENV=dev">> $GITHUB_ENV
echo "set APP_ENV to dev, see Print definitive APP_ENV"
- name: Setting APP_ENV to prod
if: contains( github.ref, 'main' )
run: |
echo "APP_ENV=prod">> $GITHUB_ENV
echo "settin APP_ENV to prod, see Print definitive APP_ENV"
- name: Setting APP_ENV to version or feature
if: contains( github.ref, 'version-' ) || contains( github.ref, 'feature-')
run: |
GENERAL_TAG=$GITHUB_REF_NAME
export GENERAL_TAG=${GENERAL_TAG//-/}
echo "APP_ENV=$GENERAL_TAG">> $GITHUB_ENV
echo "setting APP_ENV to $GENERAL_TAG, see Print definitive APP_ENV"
- name: Print definitive APP_ENV
run: echo "APP_ENV is now $APP_ENV"
- name: Build Docker Image
run: docker-compose build --build-arg APP_ENV=$APP_ENV
- name: Run docker image
run: docker compose up -d
- name: Taking some sleep (for containers to come up)
run: sleep 10
- name: Check if all containers are running
run: docker ps
- name: Dumping the logs
run: docker-compose logs
- name: Add docker tags
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/development'
run: |
images=$(docker-compose images -q | xargs docker inspect --format='{{ index .RepoTags 0}}' | cut -d':' -f1 | grep $APP_NAME)
for image in $images
do
docker tag "${image}":${APP_ENV} "${image}":"$GITHUB_REF_NAME_$RELEASE"
done
echo 'IMAGES=$images' >> $GITHUB_ENV
- name: Show all images
run: docker images
# Lets save the images
- name: Create PHP Artifact
run: docker save -o php.tar "${REGISTRY_BASE}/${APP_NAME}"-php
- name: Upload PHP artifact
uses: actions/upload-artifact@v2
with:
name: php.tar
path: php.tar
- name: Create NGINX Artifact
run: docker save -o nginx.tar ghcr.io/conductionnl/commonground-gateway-nginx
- name: Upload NGINX artifact
uses: actions/upload-artifact@v2
with:
name: nginx.tar
path: nginx.tar
- name: Create postgres Artifact
run: docker save -o postgres.tar postgres
Dependency-check:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '16'
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: php.tar
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: nginx.tar
- name: Load Docker images from previous workflows
run: docker load --input php.tar && docker load --input nginx.tar
- name: Default Environment Variables
run:
export NAME=$(grep CONTAINER_PROJECT_NAME= .env | cut -d '=' -f2);
export REGISTRY=$(grep CONTAINER_REGISTRY_BASE= .env | cut -d '=' -f2);
echo "https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables";
echo "GITHUB_WORKFLOW is $GITHUB_WORKFLOW";
echo "GITHUB_WORKFLOW_REF is $GITHUB_WORKFLOW_REF";
echo "GITHUB_RUN_ATTEMPT is $GITHUB_RUN_ATTEMPT";
echo "GITHUB_REF is $GITHUB_REF";
echo "GITHUB_REF_NAME is $GITHUB_REF_NAME";
echo "GITHUB_REF_PROTECTED is $GITHUB_REF_PROTECTED";
echo "APP_NAME=$NAME" >> $GITHUB_ENV;
echo "APP_ENV=prod">> $GITHUB_ENV;
export VERSION=$(grep APP_VERSION= .env | cut -d '=' -f2);
export RELEASE=$VERSION.$(date --utc +%y%m%d);
echo "RELEASE=$RELEASE" >> $GITHUB_ENV;
echo "REGISTRY_BASE=$REGISTRY" >> $GITHUB_ENV;
- name: Create vendor folder
run: |
mkdir api/vendor
chmod +777 api/vendor
chmod +777 -R api/public
- name: Print app name
run: echo "APP_NAME = $APP_NAME"
- name: Setting APP_ENV to dev
run: |
echo "APP_ENV=dev">> $GITHUB_ENV
echo "set APP_ENV to dev, see Print definitive APP_ENV"
- name: Setting APP_ENV to prod
if: contains( github.ref, 'main' )
run: |
echo "APP_ENV=prod">> $GITHUB_ENV
echo "settin APP_ENV to prod, see Print definitive APP_ENV"
- name: Setting APP_ENV to version or feature
if: contains( github.ref, 'version-' ) || contains( github.ref, 'feature-')
run: |
GENERAL_TAG=$GITHUB_REF_NAME
export GENERAL_TAG=${GENERAL_TAG//-/}
echo "APP_ENV=$GENERAL_TAG">> $GITHUB_ENV
echo "setting APP_ENV to $GENERAL_TAG, see Print definitive APP_ENV"
- name: Print definitive APP_ENV
run: echo "APP_ENV is now $APP_ENV"
- name: Show all images
run: docker images
- name: Up the images
run: docker compose up -d
- name: Wait for the containers to run
run: sleep 20
- name: Dump logs
run: docker compose logs
- name: Check images with Composer Audit
run: docker compose exec php composer audit
Unit:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '16'
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: php.tar
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: nginx.tar
- name: Default Environment Variables
run:
export NAME=$(grep CONTAINER_PROJECT_NAME= .env | cut -d '=' -f2);
export REGISTRY=$(grep CONTAINER_REGISTRY_BASE= .env | cut -d '=' -f2);
echo "https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables";
echo "GITHUB_WORKFLOW is $GITHUB_WORKFLOW";
echo "GITHUB_WORKFLOW_REF is $GITHUB_WORKFLOW_REF";
echo "GITHUB_RUN_ATTEMPT is $GITHUB_RUN_ATTEMPT";
echo "GITHUB_REF is $GITHUB_REF";
echo "GITHUB_REF_NAME is $GITHUB_REF_NAME";
echo "GITHUB_REF_PROTECTED is $GITHUB_REF_PROTECTED";
echo "APP_NAME=$NAME" >> $GITHUB_ENV;
echo "APP_ENV=prod">> $GITHUB_ENV;
export VERSION=$(grep APP_VERSION= .env | cut -d '=' -f2);
export RELEASE=$VERSION.$(date --utc +%y%m%d);
echo "RELEASE=$RELEASE" >> $GITHUB_ENV;
echo "REGISTRY_BASE=$REGISTRY" >> $GITHUB_ENV;
- name: Create vendor folder
run: |
mkdir api/vendor
chmod +777 api/vendor
chmod +777 -R api/public
- name: Setting APP_ENV to dev
run: |
echo "APP_ENV=dev">> $GITHUB_ENV
echo "set APP_ENV to dev, see Print definitive APP_ENV"
- name: Setting APP_ENV to prod
if: contains( github.ref, 'main' )
run: |
echo "APP_ENV=prod">> $GITHUB_ENV
echo "settin APP_ENV to prod, see Print definitive APP_ENV"
- name: Setting APP_ENV to version or feature
if: contains( github.ref, 'version-' ) || contains( github.ref, 'feature-')
run: |
GENERAL_TAG=$GITHUB_REF_NAME
export GENERAL_TAG=${GENERAL_TAG//-/}
echo "APP_ENV=$GENERAL_TAG">> $GITHUB_ENV
echo "setting APP_ENV to $GENERAL_TAG, see Print definitive APP_ENV"
- name: Print definitive APP_ENV
run: echo "APP_ENV is now $APP_ENV"
- name: Load Docker images from previous workflows
run: docker load --input php.tar && docker load --input nginx.tar
- name: Show all images
run: docker images
- name: Up the images
run: docker compose up -d
- name: Run PHPUnit
run: docker-compose exec -T php bin/phpunit
Fossa:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '16'
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: php.tar
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: nginx.tar
- name: Load Docker images from previous workflows
run: docker load --input php.tar && docker load --input nginx.tar
- name: Show all images
run: docker images
- name: Up the images
run: docker compose up -d
- name: Run Fossa checks
uses: fossas/fossa-action@main # Use a specific version if locking is preferred
with:
api-key: ${{secrets.fossaApiKey}}
container: php
debug: true
- name: Upload results as artifact
uses: actions/upload-artifact@v3
with:
name: 'fossa-results'
path: ./fossa.debug.json.gz
Database:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '16'
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: php.tar
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: nginx.tar
- name: Load Docker images from previous workflows
run: docker load --input php.tar && docker load --input nginx.tar
- name: Default Environment Variables
run:
export NAME=$(grep CONTAINER_PROJECT_NAME= .env | cut -d '=' -f2);
export REGISTRY=$(grep CONTAINER_REGISTRY_BASE= .env | cut -d '=' -f2);
echo "https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables";
echo "GITHUB_WORKFLOW is $GITHUB_WORKFLOW";
echo "GITHUB_WORKFLOW_REF is $GITHUB_WORKFLOW_REF";
echo "GITHUB_RUN_ATTEMPT is $GITHUB_RUN_ATTEMPT";
echo "GITHUB_REF is $GITHUB_REF";
echo "GITHUB_REF_NAME is $GITHUB_REF_NAME";
echo "GITHUB_REF_PROTECTED is $GITHUB_REF_PROTECTED";
echo "APP_NAME=$NAME" >> $GITHUB_ENV;
echo "APP_ENV=prod">> $GITHUB_ENV;
export VERSION=$(grep APP_VERSION= .env | cut -d '=' -f2);
export RELEASE=$VERSION.$(date --utc +%y%m%d);
echo "RELEASE=$RELEASE" >> $GITHUB_ENV;
echo "REGISTRY_BASE=$REGISTRY" >> $GITHUB_ENV;
- name: Create vendor folder
run: |
mkdir api/vendor
chmod +777 api/vendor
chmod +777 -R api/public
- name: Setting APP_ENV to dev
run: |
echo "APP_ENV=dev">> $GITHUB_ENV
echo "set APP_ENV to dev, see Print definitive APP_ENV"
- name: Setting APP_ENV to prod
if: contains( github.ref, 'main' )
run: |
echo "APP_ENV=prod">> $GITHUB_ENV
echo "settin APP_ENV to prod, see Print definitive APP_ENV"
- name: Setting APP_ENV to version or feature
if: contains( github.ref, 'version-' ) || contains( github.ref, 'feature-')
run: |
GENERAL_TAG=$GITHUB_REF_NAME
export GENERAL_TAG=${GENERAL_TAG//-/}
echo "APP_ENV=$GENERAL_TAG">> $GITHUB_ENV
echo "setting APP_ENV to $GENERAL_TAG, see Print definitive APP_ENV"
- name: Print definitive APP_ENV
run: echo "APP_ENV is now $APP_ENV"
- name: Show all images
run: docker images
- name: Up the images
run: docker compose up -d
- name: Wait for the containers to run
run: sleep 20
- name: Dump logs
run: docker compose logs
- name: Database Update
run: docker-compose exec -T php bin/console doctrine:schema:update --force
Snyk:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/node@master
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
Docker-Scout:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '16'
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: php.tar
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: nginx.tar
- name: Default Environment Variables
run:
export NAME=$(grep CONTAINER_PROJECT_NAME= .env | cut -d '=' -f2);
export REGISTRY=$(grep CONTAINER_REGISTRY_BASE= .env | cut -d '=' -f2);
echo "https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables";
echo "GITHUB_WORKFLOW is $GITHUB_WORKFLOW";
echo "GITHUB_WORKFLOW_REF is $GITHUB_WORKFLOW_REF";
echo "GITHUB_RUN_ATTEMPT is $GITHUB_RUN_ATTEMPT";
echo "GITHUB_REF is $GITHUB_REF";
echo "GITHUB_REF_NAME is $GITHUB_REF_NAME";
echo "GITHUB_REF_PROTECTED is $GITHUB_REF_PROTECTED";
echo "APP_NAME=$NAME" >> $GITHUB_ENV;
echo "APP_ENV=prod">> $GITHUB_ENV;
export VERSION=$(grep APP_VERSION= .env | cut -d '=' -f2);
export RELEASE=$VERSION.$(date --utc +%y%m%d);
echo "RELEASE=$RELEASE" >> $GITHUB_ENV;
echo "REGISTRY_BASE=$REGISTRY" >> $GITHUB_ENV;
- name: Create vendor folder
run: |
mkdir api/vendor
chmod +777 api/vendor
chmod +777 -R api/public
- name: Setting APP_ENV to dev
run: |
echo "APP_ENV=dev">> $GITHUB_ENV
echo "set APP_ENV to dev, see Print definitive APP_ENV"
- name: Setting APP_ENV to prod
if: contains( github.ref, 'main' )
run: |
echo "APP_ENV=prod">> $GITHUB_ENV
echo "settin APP_ENV to prod, see Print definitive APP_ENV"
- name: Setting APP_ENV to version or feature
if: contains( github.ref, 'version-' ) || contains( github.ref, 'feature-')
run: |
GENERAL_TAG=$GITHUB_REF_NAME
export GENERAL_TAG=${GENERAL_TAG//-/}
echo "APP_ENV=$GENERAL_TAG">> $GITHUB_ENV
echo "setting APP_ENV to $GENERAL_TAG, see Print definitive APP_ENV"
- name: Print definitive APP_ENV
run: echo "APP_ENV is now $APP_ENV"
- name: Load Docker images from previous workflows
run: docker load --input php.tar && docker load --input nginx.tar
- name: Show docker images
run: docker images
- name: Docker Scout
uses: docker/[email protected]
with:
command: quickview,cves
image: ${{ env.REGISTRY_BASE }}/${{ env.APP_NAME }}-php:${{ env.APP_ENV }}
github-token: ${{ secrets.GITHUB_TOKEN }}
dockerhub-user: ${{ secrets.DOCKER_USER }}
dockerhub-password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
Publish:
needs: [Dependency-check,Database,Docker-Scout]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/development'
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '16'
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: php.tar
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: nginx.tar
- name: Load Docker images from previous workflows
run: docker load --input php.tar && docker load --input nginx.tar
- name: Show all images
run: docker images
- name: Up the images
run: docker compose up -d
- name: Login to Container Registry
id: containerregistry-login
run: |
if [ "${{ secrets.GITHUB_TOKEN }}" != "" ]; then
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $(cut -d'/' -f1 <<< $GITHUB_REPOSITORY) --password-stdin
echo "##[set-output name=success;]true"
else
echo "##[set-output name=success;]false"
fi
- if: steps.containerregistry-login.outputs.success == 'true'
name: Push to Container Registry
run: docker-compose push
- if: steps.containerregistry-login.outputs.success == 'true'
name: Push versioned containers to Container Registry
run: |
images=$(docker-compose images -q | xargs docker inspect --format='{{ index .RepoTags 0}}' | cut -d':' -f1 | grep $APP_NAME)
for image in $images
do
docker push "${image}":"$GITHUB_REF_NAME_$RELEASE"
done
- name: Print release name
if: (success() || failure())
run: echo $RELEASENAME
env:
RELEASENAME: ${{ steps.releasecode.outputs.releasename }}
- name: Create Release
if: contains( github.ref, 'master' ) && steps.kubeconfig.outputs.success == 'true' && ( success() || failure() )
id: create_release
uses: actions/create-release@v1
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ steps.releasecode.outputs.releasename }}
release_name: ${{ steps.releasecode.outputs.releasename }}
draft: false
prerelease: false
- name: Chores
if: (success() || failure())
run: docker-compose down