-
Notifications
You must be signed in to change notification settings - Fork 91
373 lines (333 loc) · 13.5 KB
/
docker-publish.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
name: Docker Image Build and Release
on:
push:
branches: [master]
pull_request:
branches: [master]
create:
tags:
concurrency: ci-${{ github.ref }}
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
IMAGE_NAME_GHCR: ghcr.io/${{ github.repository }}
IMAGE_NAME_DOCKER: securecompliance/gvm
permissions:
contents: read
packages: write
jobs:
build_test_trivy:
name: Build and Test - Trivy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: PrepareReg Names
run: |
echo IMAGE_REPOSITORY_GHCR=$(echo "ghcr.io/${{ github.repository }}" | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
echo IMAGE_TAG=$(echo ${{ github.ref }} | tr '[:upper:]' '[:lower:]' | awk '{split($0,a,"/"); print a[3]}') >> $GITHUB_ENV
- name: Set tag var
id: vars
run: echo ::set-output name=docker_tag::$(echo ${GITHUB_REF} | cut -d'/' -f3)-${GITHUB_SHA}
- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
# Optional, GitHub token, a Personal Access Token with `public_repo` scope if needed
# Required, if artifact is from a different repo
github_token: ${{secrets.GITHUB_TOKEN}}
# Required, workflow file name or ID
workflow: build-apk.yml
# Optional, will use the branch
branch: master
# Optional, uploaded artifact name,
# will download all artifacts if not specified
# and extract them in respective subdirectories
# https://github.com/actions/download-artifact#download-all-artifacts
name: apk-builds
# Optional, directory where to extract artifact. Defaults to the artifact name (see `name` input)
path: ${{ github.workspace }}/apk-build/
# Optional, defaults to current repo
repo: Secure-Compliance-Solutions-LLC/GVM-APK-build
- name: Build the Docker image
run: docker build . --file Dockerfile --build-arg OPT_PDF=1 --tag ${{ env.IMAGE_REPOSITORY_GHCR }}:${{ github.sha }}
- uses: actions/[email protected]
with:
path: .trivy
key: ${{ runner.os }}-trivy-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-trivy-
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: "${{ env.IMAGE_REPOSITORY_GHCR }}:${{ github.sha }}"
format: "table"
exit-code: "1"
ignore-unfixed: true
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
cache-dir: .trivy
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
if: always()
with:
image-ref: "${{ env.IMAGE_REPOSITORY_GHCR }}:${{ github.sha }}"
format: "template"
template: "@/contrib/sarif.tpl"
output: "trivy-results.sarif"
severity: "CRITICAL,HIGH"
cache-dir: .trivy
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v1
if: always()
with:
sarif_file: "trivy-results.sarif"
- name: Correct Trivy cache permissions
if: always()
run: sudo chown -R $USER:$GROUP .trivy
build_test_anchore:
name: Build and Test - Anchore
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: PrepareReg Names
run: |
echo IMAGE_REPOSITORY_GHCR=$(echo "ghcr.io/${{ github.repository }}" | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
echo IMAGE_TAG=$(echo ${{ github.ref }} | tr '[:upper:]' '[:lower:]' | awk '{split($0,a,"/"); print a[3]}') >> $GITHUB_ENV
- name: Set tag var
id: vars
run: echo ::set-output name=docker_tag::$(echo ${GITHUB_REF} | cut -d'/' -f3)-${GITHUB_SHA}
- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
# Optional, GitHub token, a Personal Access Token with `public_repo` scope if needed
# Required, if artifact is from a different repo
github_token: ${{secrets.GITHUB_TOKEN}}
# Required, workflow file name or ID
workflow: build-apk.yml
# Optional, will use the branch
branch: master
# Optional, uploaded artifact name,
# will download all artifacts if not specified
# and extract them in respective subdirectories
# https://github.com/actions/download-artifact#download-all-artifacts
name: apk-builds
# Optional, directory where to extract artifact. Defaults to the artifact name (see `name` input)
path: ${{ github.workspace }}/apk-build/
# Optional, defaults to current repo
repo: Secure-Compliance-Solutions-LLC/GVM-APK-build
- name: Build the Docker image
run: docker build . --file Dockerfile --build-arg OPT_PDF=1 --tag ${{ env.IMAGE_REPOSITORY_GHCR }}:${{ github.sha }}
- uses: anchore/scan-action@v2
if: always()
id: scan
with:
image: "${{ env.IMAGE_REPOSITORY_GHCR }}:${{ github.sha }}"
acs-report-enable: true
- name: upload Anchore scan SARIF report
if: always()
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
build_release:
name: Build and Release
runs-on: ubuntu-latest
outputs:
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
submodules: recursive
- name: Setup QEMU
uses: docker/setup-qemu-action@v1
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
install: true
- name: Inspect builder
run: |
echo "Name : ${{ steps.buildx.outputs.name }}"
echo "Endpoint : ${{ steps.buildx.outputs.endpoint }}"
echo "Status : ${{ steps.buildx.outputs.status }}"
echo "Flags : ${{ steps.buildx.outputs.flags }}"
echo "Platforms : ${{ steps.buildx.outputs.platforms }}"
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Login to GitHub Container Registry ${{ env.REGISTRY }}
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Relase Prepare for latest Tag
id: releasePreareLatestTag
shell: bash
run: |
if [[ "$GITHUB_EVENT_NAME" == "create" ]] && [[ "$GITHUB_REF" =~ ^refs/tags/v.* ]]; then
echo -n "::set-output name=latest::true"
else
echo -n "::set-output name=latest::false"
fi
- name: Relase Prepare
id: releasePreare
run: |
echo -n "::set-output name=images::"
if [ "${GITHUB_EVENT_NAME}" != "pull_request" ]; then
echo -n "${IMAGE_NAME_DOCKER}"
echo -n ","
fi
echo -n "${IMAGE_NAME_GHCR}"
- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
# Optional, GitHub token, a Personal Access Token with `public_repo` scope if needed
# Required, if artifact is from a different repo
github_token: ${{secrets.GITHUB_TOKEN}}
# Required, workflow file name or ID
workflow: build-apk.yml
# Optional, will use the branch
branch: master
# Optional, uploaded artifact name,
# will download all artifacts if not specified
# and extract them in respective subdirectories
# https://github.com/actions/download-artifact#download-all-artifacts
name: apk-builds
# Optional, directory where to extract artifact. Defaults to the artifact name (see `name` input)
path: ${{ github.workspace }}/apk-build/
# Optional, defaults to current repo
repo: Secure-Compliance-Solutions-LLC/GVM-APK-build
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta2
uses: docker/metadata-action@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: ${{ steps.releasePreare.outputs.images }}
flavor: |
latest=${{ steps.releasePreareLatestTag.outputs.latest}}
prefix=
suffix=
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{raw}}
type=semver,pattern={{major}}.{{minor}}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
push: true
tags: ${{ steps.meta2.outputs.tags }}
labels: ${{ steps.meta2.outputs.labels }}
build-args: |
SETUP=0
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta3
uses: docker/metadata-action@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: ${{ steps.releasePreare.outputs.images }}
flavor: |
latest=${{ steps.releasePreareLatestTag.outputs.latest}}
onlatest=${{ steps.releasePreareLatestTag.outputs.latest}}
prefix=
suffix=-full,onlatest=${{ steps.releasePreareLatestTag.outputs.latest}}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{raw}}
type=semver,pattern={{major}}.{{minor}}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image -full tag
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
push: true
tags: ${{ steps.meta3.outputs.tags }}
labels: ${{ steps.meta3.outputs.labels }}
build-args: |
SETUP=0
OPT_PDF=1
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta4
uses: docker/metadata-action@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: ${{ steps.releasePreare.outputs.images }}
flavor: |
latest=${{ steps.releasePreareLatestTag.outputs.latest}}
onlatest=${{ steps.releasePreareLatestTag.outputs.latest}}
prefix=
suffix=-data,onlatest=${{ steps.releasePreareLatestTag.outputs.latest}}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{raw}}
type=semver,pattern={{major}}.{{minor}}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image with -data tag
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta4.outputs.tags }}
labels: ${{ steps.meta4.outputs.labels }}
build-args: |
SETUP=1
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta5
uses: docker/metadata-action@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: ${{ steps.releasePreare.outputs.images }}
flavor: |
latest=${{ steps.releasePreareLatestTag.outputs.latest}}
onlatest=${{ steps.releasePreareLatestTag.outputs.latest}}
prefix=
suffix=-data-full,onlatest=${{ steps.releasePreareLatestTag.outputs.latest}}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{raw}}
type=semver,pattern={{major}}.{{minor}}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image with -data-full tag
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta5.outputs.tags }}
labels: ${{ steps.meta5.outputs.labels }}
build-args: |
SETUP=1
OPT_PDF=1