-
Notifications
You must be signed in to change notification settings - Fork 3
344 lines (328 loc) · 11.2 KB
/
docker.image.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
name: Docker Image CI
on:
push:
branches:
- $default-branch
- development
- master
tags:
- '*.*.*-*'
# Run tests for any PRs
pull_request:
schedule:
- cron: '43 10 * * 4'
env:
IMAGE_NAME: calcardbackup
jobs:
codespell:
name: codespell
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Codespell
uses: codespell-project/actions-codespell@master
with:
ignore_words_list: ro,rw
skip: .git
check_filenames: true
check_hidden: true
super-linter:
name: super-linter
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Lint Code Base
uses: github/[email protected]
env:
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shiftleft:
name: shiftleft
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Perform ShiftLeft Scan
uses: ShiftLeftSecurity/scan-action@master
env:
WORKSPACE: ""
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SCAN_AUTO_BUILD: true
with:
output: reports
# Scan auto-detects the languages in your project. To override uncomment the below variable and set the type
# type: credscan,java
# type: python
- name: Upload report
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: reports
test-build:
needs:
- codespell
- super-linter
- shiftleft
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: linux/amd64
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- name: Build the Docker image
id: docker_test
uses: docker/build-push-action@v4
with:
builder: ${{ steps.buildx.outputs.name }}
push: false
outputs: type=docker,dest=/tmp/${{ env.IMAGE_NAME }}-${{ github.run_number }}.tar
tags: localhost:5000/foobar/${{ env.IMAGE_NAME }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
context: .
file: ./Dockerfile
platforms: linux/amd64
build-args: |
BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
BUILD_VERSION="$(git describe --tags)"
VCS_REF="$(git rev-parse --short HEAD)"
VCS_URL="$(git config --get remote.origin.url)"
VCS_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.IMAGE_NAME }}-${{ github.run_number }}
path: /tmp/${{ env.IMAGE_NAME }}-${{ github.run_number }}.tar
test:
needs:
- test-build
strategy:
fail-fast: false
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.IMAGE_NAME }}-${{ github.run_number }}
path: /tmp
- name: Load image and push to local registry
run: |
docker load --input /tmp/${{ env.IMAGE_NAME }}-${{ github.run_number }}.tar
docker image ls -a
docker push localhost:5000/foobar/${{ env.IMAGE_NAME }}
- name: Inspect the Docker image
run: |
docker buildx imagetools inspect localhost:5000/foobar/${{ env.IMAGE_NAME }}
- name: Test the Docker image
run: |
CONTAINER_OUTPUT="$(docker run --rm -t localhost:5000/foobar/${{ env.IMAGE_NAME }} /opt/calcardbackup/calcardbackup -h)"
# shellcheck disable=SC2086
TEST_STRING="$(echo ${CONTAINER_OUTPUT} | grep -c 'START calcardbackup')"
if ! [ "${TEST_STRING}" = "1" ]; then exit 1; fi
- name: Scan image with Container Scan
uses: Azure/container-scan@v0
env:
DOCKER_CONTENT_TRUST: 1
#DOCKLE_NON_SSL: true
with:
image-name: localhost:5000/foobar/${{ env.IMAGE_NAME }}
severity-threshold: HIGH
run-quality-checks: false
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: localhost:5000/foobar/${{ env.IMAGE_NAME }}
format: 'template'
template: '@/contrib/sarif.tpl'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
- name: Run the Anchore scan action itself with GitHub Advanced Security code scanning integration enabled
uses: anchore/scan-action@main
with:
image: localhost:5000/foobar/${{ env.IMAGE_NAME }}
acs-report-enable: true
fail-build: false
- name: Move reports
run: mkdir -p sarif-reports && cp ./*results.sarif ./sarif-reports/
- name: Upload Reports
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'sarif-reports'
release-docker:
name: Release Docker images
needs:
- test
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Prepare
id: prep
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }}
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}
run: |
USER="${GITHUB_REPOSITORY_OWNER}"
IMAGE_NAME="$(echo '${{ github.repository }}' | awk -F '/' '{print $2}' | sed s/docker-//)"
DOCKER_IMAGE="${USER}/${IMAGE_NAME}"
VERSION=edge
# running on a tag
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
fi
# running on a branch
if [[ "$GITHUB_REF" == refs/heads/* ]]; then
VERSION="${GITHUB_REF#refs/heads/}"
fi
# running on schedule
# shellcheck disable=SC2050
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
fi
# running on master branch
if [ "$VERSION" = "master" ]; then
VERSION=latest
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ "$VERSION" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\-[0-9]{1,3}$ ]]; then
REALEASE_TAG=true
fi
TAGS_INT="$TAGS"
TAGS=""
if [ "$DOCKERHUB_USERNAME" != '' ] && [ "$DOCKERHUB_TOKEN" != '' ]; then
if [ "$REALEASE_TAG" = "true" ]; then
TAGS="$TAGS_INT,${DOCKER_IMAGE}:latest"
else
TAGS="$TAGS_INT"
fi
fi
if [ "$GITHUB_TOKEN" != '' ]; then
if [ "$REALEASE_TAG" = "true" ]; then
TAGS="$TAGS,ghcr.io/$TAGS_INT,ghcr.io/${DOCKER_IMAGE}:latest"
else
TAGS="$TAGS,ghcr.io/$TAGS_INT"
fi
fi
if [ "$QUAY_USERNAME" != '' ] && [ "$QUAY_TOKEN" != '' ]; then
if [ "$REALEASE_TAG" = "true" ]; then
TAGS="$TAGS,quay.io/$TAGS_INT,quay.io/${DOCKER_IMAGE}:latest"
else
TAGS="$TAGS,quay.io/$TAGS_INT"
fi
fi
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.IMAGE_NAME }}-${{ github.run_number }}
path: /tmp
- name: Load image from test job
run: |
docker load --input /tmp/${{ env.IMAGE_NAME }}-${{ github.run_number }}.tar
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to ghcr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ github.event_name != 'pull_request' && env.GITHUB_TOKEN != '' }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${USER}
password: ${{ env.GITHUB_TOKEN }}
- name: Login to DockerHub Container Registry
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
if: ${{ github.event_name != 'pull_request' && env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' }}
uses: docker/login-action@v2
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}
- name: Login to Quay Container Registry
env:
QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }}
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}
if: ${{ github.event_name != 'pull_request' && env.QUAY_USERNAME != '' && env.QUAY_TOKEN != '' }}
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ env.QUAY_USERNAME }}
password: ${{ env.QUAY_TOKEN }}
- name: Test
id: docker_test
uses: docker/build-push-action@v4
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64
build-args: |
BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
BUILD_VERSION="$(git describe --tags)"
VCS_REF="$(git rev-parse --short HEAD)"
VCS_URL="$(git config --get remote.origin.url)"
VCS_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ steps.prep.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: |
BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
BUILD_VERSION="$(git describe --tags)"
VCS_REF="$(git rev-parse --short HEAD)"
VCS_URL="$(git config --get remote.origin.url)"
VCS_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}