-
Notifications
You must be signed in to change notification settings - Fork 65
357 lines (323 loc) · 13.3 KB
/
docker.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
# Copyright 2020 Wayback Archiver. All rights reserved.
# Use of this source code is governed by the GNU GPL v3
# license that can be found in the LICENSE file.
#
name: Docker
on:
push:
tags:
- "v*"
branches:
- 'main'
- 'develop'
paths-ignore:
- "**.md"
- 'snapcraft.yaml'
- 'requirements.txt'
- '.github/**'
- '!.github/workflows/docker.yml'
- 'docs/**'
- 'mkdocs.yml'
pull_request:
branches:
- 'main'
paths-ignore:
- "**.md"
- 'snapcraft.yaml'
- 'requirements.txt'
- '.github/**'
- '!.github/workflows/docker.yml'
- 'docs/**'
- 'mkdocs.yml'
workflow_dispatch:
permissions:
contents: read
# New runs to only cancel in-progress runs of the same workflow.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
publish:
name: Build and push Docker image
runs-on: ubuntu-latest
permissions:
packages: write
id-token: write
outputs:
image: ${{ steps.prep.outputs.ghcr }}
version: ${{ steps.meta.outputs.version }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@2e205a28d0e1da00c5f53b161f4067b052c61f34 # v1.5.0
with:
egress-policy: audit
disable-telemetry: true
allowed-endpoints: >
ghcr.io:443
github.com:443
api.github.com:443
*.githubusercontent.com
docker.io:443
auth.docker.io:443
index.docker.io:443
registry-1.docker.io:443
production.cloudflare.docker.com:443
dl-cdn.alpinelinux.org:443
storage.googleapis.com:443
proxy.golang.org:443
sum.golang.org:443
- name: Checkout default branch
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
fetch-depth: 0
- name: Install Cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@e1523de7571e31dbe865fd2e80c5c7c23ae71eb4 # v3.4.0
- name: Prepare
id: prep
run: |
GHCR_HOST=ghcr.io
DOCKER_HOST=docker.io
DOCKER_IMAGE_SCOPE=${{ github.repository }} # foo/bar
if [ "${{ github.event_name }}" = "schedule" ]; then
DOCKER_IMAGE_VERSION=nightly
elif [[ $GITHUB_REF == refs/tags/* ]]; then
DOCKER_IMAGE_VERSION=${GITHUB_REF#refs/*/v}
TAGS="${DOCKER_HOST}/${DOCKER_IMAGE_SCOPE}:latest,${GHCR_HOST}/${DOCKER_IMAGE_SCOPE}:latest"
else
DOCKER_IMAGE_VERSION=edge
fi
TAGS="${TAGS},${DOCKER_HOST}/${DOCKER_IMAGE_SCOPE}:${DOCKER_IMAGE_VERSION},${GHCR_HOST}/${DOCKER_IMAGE_SCOPE}:${DOCKER_IMAGE_VERSION}"
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "version=${DOCKER_IMAGE_VERSION}" >> $GITHUB_OUTPUT
echo "docker=${DOCKER_HOST}/${DOCKER_IMAGE_SCOPE}" >> $GITHUB_OUTPUT
echo "ghcr=${GHCR_HOST}/${DOCKER_IMAGE_SCOPE}" >> $GITHUB_OUTPUT
echo "images=${DOCKER_HOST}/${DOCKER_IMAGE_SCOPE},${GHCR_HOST}/${DOCKER_IMAGE_SCOPE}" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f03ac48505955848960e80bbb68046aa35c7b9e7 # v2.4.1
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate meta
id: meta
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0
with:
images: ${{ steps.prep.outputs.images }}
tags: |
type=semver,pattern=${{ steps.prep.outputs.version }}
type=raw,${{ steps.prep.outputs.version }}
- name: Build artifacts
uses: docker/bake-action@6c87dcca988e4e074e3ab1f976a70f63ec9673fb # v2.3.0
env:
WAYBACK_IPFS_TARGET: ${{ secrets.WAYBACK_IPFS_TARGET }}
WAYBACK_IPFS_APIKEY: ${{ secrets.WAYBACK_IPFS_APIKEY }}
WAYBACK_IPFS_SECRET: ${{ secrets.WAYBACK_IPFS_SECRET }}
with:
files: ./docker-bake.hcl
targets: artifact-all
set: |
*.cache-from=type=local,src=/tmp/.image-cache/artifacts
*.cache-to=type=local,dest=/tmp/.image-cache-new/artifacts
- name: Build and push Docker image
uses: docker/bake-action@6c87dcca988e4e074e3ab1f976a70f63ec9673fb # v2.3.0
env:
WAYBACK_IPFS_TARGET: ${{ secrets.WAYBACK_IPFS_TARGET }}
WAYBACK_IPFS_APIKEY: ${{ secrets.WAYBACK_IPFS_APIKEY }}
WAYBACK_IPFS_SECRET: ${{ secrets.WAYBACK_IPFS_SECRET }}
with:
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: release
push: ${{ github.event_name != 'pull_request' }}
set: |
*.cache-from=type=local,src=/tmp/.image-cache/image
*.cache-to=type=local,dest=/tmp/.image-cache-new/image
- name: Siging image
if: github.event_name != 'pull_request'
env:
TAGS: ${{ steps.meta.outputs.tags }}
COSIGN_PRIVATE_KEY: ${{secrets.COSIGN_PRIVATE_KEY}}
COSIGN_PASSWORD: ${{secrets.COSIGN_PASSPHARSE}}
run: |
cosign sign --yes --key env://COSIGN_PRIVATE_KEY ${TAGS}
- name: Check manifest
if: github.event_name != 'pull_request'
run: |
docker buildx imagetools inspect ${{ steps.prep.outputs.docker }}:${{ steps.meta.outputs.version }}
docker buildx imagetools inspect ${{ steps.prep.outputs.ghcr }}:${{ steps.meta.outputs.version }}
- name: Inspect image
if: github.event_name != 'pull_request'
run: |
docker pull ${{ steps.prep.outputs.docker }}:${{ steps.meta.outputs.version }}
docker image inspect ${{ steps.prep.outputs.docker }}:${{ steps.meta.outputs.version }}
docker pull ${{ steps.prep.outputs.ghcr }}:${{ steps.meta.outputs.version }}
docker image inspect ${{ steps.prep.outputs.ghcr }}:${{ steps.meta.outputs.version }}
- name: Cosign verify
if: github.event_name != 'pull_request'
run: |
IMAGE_NAME=${{ steps.prep.outputs.ghcr }}:${{ steps.meta.outputs.version }}
cat cosign.pub
cosign verify --key cosign.pub $IMAGE_NAME
allinone:
name: AllInOne Docker image
runs-on: ubuntu-latest
permissions:
packages: write
id-token: write
outputs:
image: ${{ steps.prep.outputs.ghcr }}
version: ${{ steps.meta.outputs.version }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@2e205a28d0e1da00c5f53b161f4067b052c61f34 # v1.5.0
with:
egress-policy: audit
disable-telemetry: true
allowed-endpoints: >
ghcr.io:443
github.com:443
api.github.com:443
docker.io:443
*.githubusercontent.com
auth.docker.io:443
registry-1.docker.io:443
production.cloudflare.docker.com:443
dl-cdn.alpinelinux.org:443
storage.googleapis.com:443
proxy.golang.org:443
sum.golang.org:443
- name: Checkout default branch
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
fetch-depth: 0
- name: Install Cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@e1523de7571e31dbe865fd2e80c5c7c23ae71eb4 # v3.4.0
- name: Prepare
id: prep
run: |
GHCR_HOST=ghcr.io
DOCKER_IMAGE_SCOPE=${{ github.repository }} # foo/bar
if [ "${{ github.event_name }}" = "schedule" ]; then
DOCKER_IMAGE_VERSION=nightly
elif [[ $GITHUB_REF == refs/tags/* ]]; then
DOCKER_IMAGE_VERSION=${GITHUB_REF#refs/*/v}
TAGS="${GHCR_HOST}/${DOCKER_IMAGE_SCOPE}"
else
DOCKER_IMAGE_VERSION=edge
fi
TAGS="${TAGS},${GHCR_HOST}/${DOCKER_IMAGE_SCOPE}:${DOCKER_IMAGE_VERSION}"
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "version=${DOCKER_IMAGE_VERSION}" >> $GITHUB_OUTPUT
echo "ghcr=${GHCR_HOST}/${DOCKER_IMAGE_SCOPE}" >> $GITHUB_OUTPUT
echo "images=${GHCR_HOST}/${DOCKER_IMAGE_SCOPE}" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f03ac48505955848960e80bbb68046aa35c7b9e7 # v2.4.1
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate meta
id: meta
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0
with:
images: ${{ steps.prep.outputs.images }}
flavor: |
suffix=-bundle,onlatest=true
tags: |
type=semver,pattern=${{ steps.prep.outputs.version }}
type=raw,${{ steps.prep.outputs.version }}
- name: Build artifacts
uses: docker/bake-action@6c87dcca988e4e074e3ab1f976a70f63ec9673fb # v2.3.0
env:
WAYBACK_IPFS_TARGET: ${{ secrets.WAYBACK_IPFS_TARGET }}
WAYBACK_IPFS_APIKEY: ${{ secrets.WAYBACK_IPFS_APIKEY }}
WAYBACK_IPFS_SECRET: ${{ secrets.WAYBACK_IPFS_SECRET }}
with:
files: ./docker-bake.hcl
targets: artifact-all
set: |
*.cache-from=type=local,src=/tmp/.image-cache/artifacts
*.cache-to=type=local,dest=/tmp/.image-cache-new/artifacts
- name: Build and push Docker image
uses: docker/bake-action@6c87dcca988e4e074e3ab1f976a70f63ec9673fb # v2.3.0
env:
WAYBACK_IPFS_TARGET: ${{ secrets.WAYBACK_IPFS_TARGET }}
WAYBACK_IPFS_APIKEY: ${{ secrets.WAYBACK_IPFS_APIKEY }}
WAYBACK_IPFS_SECRET: ${{ secrets.WAYBACK_IPFS_SECRET }}
with:
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: bundle
push: ${{ github.event_name != 'pull_request' }}
set: |
*.cache-from=type=local,src=/tmp/.image-cache/image
*.cache-to=type=local,dest=/tmp/.image-cache-new/image
- name: Sign image with a key
if: github.event_name != 'pull_request'
env:
TAGS: ${{ steps.meta.outputs.tags }}
COSIGN_PRIVATE_KEY: ${{secrets.COSIGN_PRIVATE_KEY}}
COSIGN_PASSWORD: ${{secrets.COSIGN_PASSPHARSE}}
run: |
cosign sign --yes --key env://COSIGN_PRIVATE_KEY ${TAGS}
- name: Check manifest
if: github.event_name != 'pull_request'
run: |
docker buildx imagetools inspect ${{ steps.prep.outputs.ghcr }}:${{ steps.meta.outputs.version }}
- name: Inspect image
if: github.event_name != 'pull_request'
run: |
docker pull ${{ steps.prep.outputs.ghcr }}:${{ steps.meta.outputs.version }}
docker image inspect ${{ steps.prep.outputs.ghcr }}:${{ steps.meta.outputs.version }}
- name: Cosign verify
if: github.event_name != 'pull_request'
run: |
IMAGE_NAME=${{ steps.prep.outputs.ghcr }}:${{ steps.meta.outputs.version }}
cat cosign.pub
cosign verify --key cosign.pub $IMAGE_NAME
trivy-standalone:
name: Trivy for standalone
uses: wabarc/.github/.github/workflows/reusable-trivy.yml@main
needs: publish
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
with:
scan-type: 'image'
image-ref: '${{ needs.publish.outputs.image }}:${{ needs.publish.outputs.version }}'
sarif: 'container-standalone.sarif'
egress-policy: 'audit'
trivy-bundle:
name: Trivy for bundle
uses: wabarc/.github/.github/workflows/reusable-trivy.yml@main
needs: allinone
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
with:
scan-type: 'image'
image-ref: '${{ needs.allinone.outputs.image }}:${{ needs.allinone.outputs.version }}'
sarif: 'container-bundle.sarif'
egress-policy: 'audit'