-
Notifications
You must be signed in to change notification settings - Fork 2
292 lines (243 loc) · 8.47 KB
/
main.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
name: Main - Attests to https://app.kosli.com
on:
push:
env:
KOSLI_DRY_RUN: ${{ vars.KOSLI_DRY_RUN }} # false
KOSLI_HOST: ${{ vars.KOSLI_HOST }} # https://app.kosli.com
KOSLI_ORG: ${{ vars.KOSLI_ORG }} # cyber-dojo
KOSLI_FLOW: ${{ vars.KOSLI_FLOW }} # languages-start-points-ci
KOSLI_API_TOKEN: ${{ secrets.KOSLI_API_TOKEN }}
KOSLI_TRAIL: ${{ github.sha }}
SERVICE_NAME: ${{ github.event.repository.name }} # languages-start-points
jobs:
setup:
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.variables.outputs.image_tag }}
image_name: ${{ steps.variables.outputs.image_name }}
steps:
- uses: actions/checkout@v4
- name: Set outputs
id: variables
run: |
IMAGE_TAG=${GITHUB_SHA:0:7}
echo "image_tag=${IMAGE_TAG}" >> ${GITHUB_OUTPUT}
echo "image_name=cyberdojo/${{ env.SERVICE_NAME }}:${IMAGE_TAG}" >> ${GITHUB_OUTPUT}
pull-request:
if: ${{ github.ref == 'refs/heads/main' }}
needs: []
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
pull-requests: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Kosli CLI
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}
- name: Attest pull-request evidence to Kosli
run:
kosli attest pullrequest github
--github-token=${{ secrets.GITHUB_TOKEN }}
--name=pull-request
snyk-code-scan:
needs: []
runs-on: ubuntu-latest
env:
SARIF_FILENAME: snyk.code.scan.json
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Snyk
uses: snyk/actions/setup@master
- name: Run Snyk code scan
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
run:
snyk code test
--sarif
--sarif-file-output="${SARIF_FILENAME}"
--policy-path=.snyk
.
- name: Setup Kosli CLI
if: ${{ github.ref == 'refs/heads/main' && (success() || failure()) }}
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}
- name: Attest evidence to Kosli
if: ${{ github.ref == 'refs/heads/main' && (success() || failure()) }}
run:
kosli attest snyk
--name=languages-start-points.snyk-code-scan
--scan-results="${SARIF_FILENAME}"
build-image:
needs: [setup]
runs-on: ubuntu-latest
env:
IMAGE_NAME: ${{ needs.setup.outputs.image_name }}
outputs:
kosli_fingerprint: ${{ steps.variables.outputs.kosli_fingerprint }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Build image
run: |
git fetch origin main:main || true
make image
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Push image to Dockerhub registry
run:
docker push "${IMAGE_NAME}"
- name: Setup Kosli CLI
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}
- name: Attest image provenance to Kosli
if: ${{ github.ref == 'refs/heads/main' }}
run:
kosli attest artifact "${IMAGE_NAME}"
--artifact-type=docker
--name=languages-start-points
--trail="${GITHUB_SHA}"
- name: Make artifact fingerprint available to following jobs
id: variables
run: |
FINGERPRINT=$(kosli fingerprint "${IMAGE_NAME}" --artifact-type=docker)
echo "kosli_fingerprint=${FINGERPRINT}" >> ${GITHUB_OUTPUT}
snyk-container-scan:
needs: [setup, build-image]
runs-on: ubuntu-latest
env:
SARIF_FILENAME: snyk.container.scan.json
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Snyk
uses: snyk/actions/setup@master
- name: Run Snyk container scan
env:
IMAGE_NAME: ${{ needs.setup.outputs.image_name }}
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
run:
snyk container test ${IMAGE_NAME}
--sarif
--sarif-file-output="${SARIF_FILENAME}"
--policy-path=.snyk
- name: Setup Kosli CLI
if: ${{ github.ref == 'refs/heads/main' && (success() || failure()) }}
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}
- name: Attest evidence to Kosli
if: ${{ github.ref == 'refs/heads/main' && (success() || failure()) }}
env:
KOSLI_FINGERPRINT: ${{ needs.build-image.outputs.kosli_fingerprint }}
run:
kosli attest snyk
--name=languages-start-points.snyk-container-scan
--scan-results="${SARIF_FILENAME}"
sdlc-control-gate:
if: ${{ github.ref == 'refs/heads/main' }}
needs: [setup, build-image, pull-request, snyk-container-scan, snyk-code-scan]
runs-on: ubuntu-latest
steps:
- name: Setup Kosli CLI
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}
- name: Kosli SDLC gate to short-circuit the workflow
env:
IMAGE_NAME: ${{ needs.setup.outputs.image_name }}
KOSLI_FINGERPRINT: ${{ needs.build-image.outputs.kosli_fingerprint }}
run:
kosli assert artifact ${IMAGE_NAME}
approve-deployment-to-beta:
needs: [setup, build-image, sdlc-control-gate]
runs-on: ubuntu-latest
environment:
name: staging
url: https://beta.cyber-dojo.org
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Kosli CLI
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}
- name: Attest approval of deployment to Kosli
env:
IMAGE_NAME: ${{ needs.setup.outputs.image_name }}
KOSLI_FINGERPRINT: ${{ needs.build-image.outputs.kosli_fingerprint }}
KOSLI_ENVIRONMENT: aws-beta
run:
kosli report approval ${IMAGE_NAME}
--approver="${{ github.actor }}"
deploy-to-beta:
needs: [setup, approve-deployment-to-beta]
uses: ./.github/workflows/sub_deploy_to_beta.yml
with:
IMAGE_TAG: ${{ needs.setup.outputs.image_tag }}
secrets:
KOSLI_API_TOKEN: ${{ secrets.KOSLI_API_TOKEN }}
approve-deployment-to-prod:
needs: [setup, build-image, deploy-to-beta]
runs-on: ubuntu-latest
environment:
name: production
url: https://cyber-dojo.org
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Kosli CLI
uses: kosli-dev/setup-cli-action@v2
with:
version: ${{ vars.KOSLI_CLI_VERSION }}
- name: Attest approval of deployment to Kosli
env:
IMAGE_NAME: ${{ needs.setup.outputs.image_name }}
KOSLI_FINGERPRINT: ${{ needs.build-image.outputs.kosli_fingerprint }}
KOSLI_ENVIRONMENT: aws-prod
run:
kosli report approval ${IMAGE_NAME}
--approver="${{ github.actor }}"
deploy-to-prod:
needs: [setup, approve-deployment-to-prod]
uses: ./.github/workflows/sub_deploy_to_prod.yml
with:
IMAGE_TAG: ${{ needs.setup.outputs.image_tag }}
secrets:
KOSLI_API_TOKEN: ${{ secrets.KOSLI_API_TOKEN }}
# The cyberdojo/versioner refresh-env.sh script
# https://github.com/cyber-dojo/versioner/blob/master/sh/refresh-env.sh
# relies on being able to:
# - get the :latest image
# - extract the SHA env-var embedded inside it
# - use the 1st 7 chars of the SHA as a latest-equivalent tag
push-latest:
needs: [setup, deploy-to-prod]
runs-on: ubuntu-latest
env:
IMAGE_NAME: ${{ needs.setup.outputs.image_name }}
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Tag image to :latest and push to Dockerhub Registry
run: |
docker pull "${IMAGE_NAME}"
docker tag "${IMAGE_NAME}" cyberdojo/${{ env.SERVICE_NAME }}:latest
docker push cyberdojo/${{ env.SERVICE_NAME }}:latest