Repository navigation
246 lines (219 loc) · 10.7 KB
/
Copy pathpackages.yml
File metadata and controls
246 lines (219 loc) · 10.7 KB
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
name: Packages
on:
push:
branches: [main]
release:
types: [published]
workflow_dispatch:
inputs:
release_tag:
description: 'Canonical release tag (for example impartus-cli-v0.1.27). Dispatch this workflow from the default branch and pass any historical tag here. Replaying an older stable tag moves rolling aliases.'
required: true
type: string
concurrency:
group: packages-${{ (inputs.release_tag || github.event.release.tag_name) && 'release' || github.ref }}
cancel-in-progress: false
env:
REGISTRY: ghcr.io
IMAGE_NAME: ghcr.io/${{ github.repository }}
jobs:
publish-ghcr:
name: Publish GHCR Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
security-events: write
actions: read
steps:
- name: Checkout workflow tooling
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.workflow_sha }}
- name: Stage container smoke test
# Copied out of the workspace so it survives the source checkout below and
# also runs for historical release tags that predate it.
run: install -D -m 0755 scripts/container-smoke.sh "$RUNNER_TEMP/impartus-tooling/container-smoke.sh"
- name: Prepare image variables
id: vars
env:
RELEASE_TAG: ${{ inputs.release_tag || github.event.release.tag_name }}
RELEASE_DATE: ${{ github.event.release.published_at }}
EVENT_NAME: ${{ github.event_name }}
run: |
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
echo "::warning::Replaying an older stable release moves latest and rolling version aliases; replay the newest release afterward to restore them."
fi
scripts/package-image-vars.sh "$RELEASE_TAG" "$RELEASE_DATE" "$EVENT_NAME" >> "$GITHUB_OUTPUT"
- name: Verify exact release tag
if: ${{ steps.vars.outputs.mode == 'release' }}
env:
MODE: ${{ steps.vars.outputs.mode }}
SOURCE_REF: ${{ steps.vars.outputs.source_ref }}
run: |
if [[ "$MODE" != "release" || ! "$SOURCE_REF" =~ ^refs/tags/impartus-cli-v[0-9A-Za-z.-]+$ ]]; then
echo "Unexpected release source ref: $SOURCE_REF" >&2
exit 1
fi
if ! git ls-remote --exit-code --refs origin "$SOURCE_REF" >/dev/null; then
echo "Release tag does not exist: $SOURCE_REF" >&2
exit 1
fi
- name: Checkout selected source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ steps.vars.outputs.source_ref || github.sha }}
- name: Resolve source revision
id: revision
run: echo "commit=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Set up QEMU
uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=raw,value=main,enable=${{ steps.vars.outputs.mode == 'snapshot' }}
type=sha,format=short,prefix=sha-,enable=${{ steps.vars.outputs.mode == 'snapshot' }}
type=raw,value=${{ steps.vars.outputs.version }},enable=${{ steps.vars.outputs.mode == 'release' }}
type=raw,value=${{ steps.vars.outputs.major_minor }},enable=${{ steps.vars.outputs.mode == 'release' && steps.vars.outputs.stable == 'true' }}
type=raw,value=${{ steps.vars.outputs.major }},enable=${{ steps.vars.outputs.mode == 'release' && steps.vars.outputs.stable == 'true' }}
type=raw,value=latest,enable=${{ steps.vars.outputs.mode == 'release' && steps.vars.outputs.stable == 'true' }}
labels: |
org.opencontainers.image.title=impartus-cli
org.opencontainers.image.description=CLI and HTTP API for downloading Impartus lecture recordings.
org.opencontainers.image.url=https://github.com/${{ github.repository }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.licenses=MIT
org.opencontainers.image.created=${{ steps.vars.outputs.build_date }}
org.opencontainers.image.revision=${{ steps.revision.outputs.commit }}
org.opencontainers.image.version=${{ steps.vars.outputs.version }}
- name: Build multi-platform OCI image for security gate
id: build
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: false
tags: impartus:prepublish-scan
labels: ${{ steps.meta.outputs.labels }}
outputs: type=oci,dest=/tmp/impartus-image,tar=false
build-args: |
VERSION=${{ steps.vars.outputs.version }}
BUILD_DATE=${{ steps.vars.outputs.build_date }}
COMMIT=${{ steps.revision.outputs.commit }}
- name: Scan linux/amd64 image before publish
id: scan_amd64
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
env:
TRIVY_PLATFORM: linux/amd64
with:
scan-type: 'image'
input: '/tmp/impartus-image'
scanners: 'vuln'
format: 'sarif'
output: 'trivy-image-amd64-results.sarif'
severity: 'CRITICAL,HIGH,MEDIUM'
exit-code: '1'
ignore-unfixed: true
- name: Scan linux/arm64 image before publish
id: scan_arm64
if: ${{ always() && steps.build.outcome == 'success' }}
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
env:
TRIVY_PLATFORM: linux/arm64
with:
scan-type: 'image'
input: '/tmp/impartus-image'
scanners: 'vuln'
format: 'sarif'
output: 'trivy-image-arm64-results.sarif'
severity: 'CRITICAL,HIGH,MEDIUM'
exit-code: '1'
ignore-unfixed: true
skip-setup-trivy: true
# Load each platform from the exact scanned OCI layout and exercise the CLI
# and ffmpeg before anything is published. arm64 runs under QEMU.
- name: Smoke test linux/amd64 image before publish
id: smoke_amd64
if: ${{ always() && steps.build.outcome == 'success' }}
run: |
skopeo copy --override-os linux --override-arch amd64 oci:/tmp/impartus-image:prepublish-scan docker-daemon:impartus-smoke:amd64
"$RUNNER_TEMP/impartus-tooling/container-smoke.sh" impartus-smoke:amd64 linux/amd64
- name: Smoke test linux/arm64 image before publish
id: smoke_arm64
if: ${{ always() && steps.build.outcome == 'success' }}
run: |
skopeo copy --override-os linux --override-arch arm64 oci:/tmp/impartus-image:prepublish-scan docker-daemon:impartus-smoke:arm64
"$RUNNER_TEMP/impartus-tooling/container-smoke.sh" impartus-smoke:arm64 linux/arm64
- name: Upload linux/amd64 Trivy SARIF results
if: ${{ always() && github.event.repository.security_and_analysis.advanced_security.status == 'enabled' }}
uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
with:
sarif_file: trivy-image-amd64-results.sarif
category: trivy-image-amd64
- name: Upload linux/arm64 Trivy SARIF results
if: ${{ always() && github.event.repository.security_and_analysis.advanced_security.status == 'enabled' }}
uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
with:
sarif_file: trivy-image-arm64-results.sarif
category: trivy-image-arm64
- name: Upload Trivy image reports
if: ${{ always() }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: trivy-image-results
path: |
trivy-image-amd64-results.sarif
trivy-image-arm64-results.sarif
if-no-files-found: warn
retention-days: 30
- name: Set up ORAS
id: oras
if: ${{ always() && steps.scan_amd64.outcome == 'success' && steps.scan_arm64.outcome == 'success' && steps.smoke_amd64.outcome == 'success' && steps.smoke_arm64.outcome == 'success' }}
uses: oras-project/setup-oras@005458ad77f1c8facd38a094e4af2e69e5607ff4 # v2.0.2
with:
version: 1.3.2
- name: Log in to GHCR
id: login
if: ${{ always() && steps.scan_amd64.outcome == 'success' && steps.scan_arm64.outcome == 'success' && steps.smoke_amd64.outcome == 'success' && steps.smoke_arm64.outcome == 'success' && steps.oras.outcome == 'success' }}
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Publish scanned multi-platform OCI image
id: publish
if: ${{ always() && steps.scan_amd64.outcome == 'success' && steps.scan_arm64.outcome == 'success' && steps.smoke_amd64.outcome == 'success' && steps.smoke_arm64.outcome == 'success' && steps.oras.outcome == 'success' && steps.login.outcome == 'success' }}
env:
IMAGE_TAGS: ${{ steps.meta.outputs.tags }}
run: |
mapfile -t image_refs <<< "$IMAGE_TAGS"
if [[ ${#image_refs[@]} -eq 0 || -z "${image_refs[0]}" ]]; then
echo "No image tags were generated" >&2
exit 1
fi
expected_prefix="${IMAGE_NAME}:"
destination="${image_refs[0]}"
if [[ "$destination" != "$expected_prefix"* ]]; then
echo "Unexpected image reference: $destination" >&2
exit 1
fi
for image_ref in "${image_refs[@]:1}"; do
if [[ "$image_ref" != "$expected_prefix"* ]]; then
echo "Unexpected image reference: $image_ref" >&2
exit 1
fi
destination+=",${image_ref#"$expected_prefix"}"
done
oras cp --from-oci-layout /tmp/impartus-image:prepublish-scan "$destination"
local_digest="$(oras resolve --oci-layout /tmp/impartus-image:prepublish-scan)"
published_digest="$(oras resolve "${image_refs[0]}")"
if [[ "$local_digest" != "$published_digest" ]]; then
echo "Published digest does not match the scanned OCI image" >&2
exit 1
fi