forked from cilium/cilium
-
Notifications
You must be signed in to change notification settings - Fork 0
368 lines (325 loc) · 17.4 KB
/
build-images-base.yaml
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
name: Base Image Release Build
# Any change in triggers needs to be reflected in the concurrency group.
on:
pull_request_target:
types:
- opened
- synchronize
- reopened
paths:
- images/runtime/**
- images/builder/**
# This workflow can be reused so that renovate can execute this workflow_dispatch:
# run from a different environment than 'release-base-images'. See
# build-images-base-renovate.yaml
workflow_call:
secrets:
QUAY_BASE_RELEASE_USERNAME:
required: true
QUAY_BASE_RELEASE_PASSWORD:
required: true
AUTO_COMMITTER_PEM:
required: true
AUTO_COMMITTER_APP_ID:
required: true
inputs:
environment:
required: true
type: string
default: "release-base-images"
permissions:
# To be able to access the repository with `actions/checkout`
contents: read
# Required to generate OIDC tokens for `sigstore/cosign-installer` authentication
id-token: write
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
has-credentials:
name: Check for Quay secrets
runs-on: ubuntu-24.04
environment: ${{ inputs.environment || 'release-base-images' }}
timeout-minutes: 2
outputs:
present: ${{ steps.secrets.outputs.present }}
steps:
- name: Check for secrets
id: secrets
env:
has_credentials: ${{ secrets.QUAY_BASE_RELEASE_USERNAME && secrets.QUAY_BASE_RELEASE_PASSWORD && 1 }}
if: ${{ env.has_credentials }}
run:
echo 'present=1' >> "$GITHUB_OUTPUT"
build-and-push:
needs: has-credentials
# Skip this workflow for repositories without credentials and branches that are created by renovate where the event type is pull_request_target
if: ${{ needs.has-credentials.outputs.present && ! (github.event_name == 'pull_request_target' && startsWith(github.head_ref, 'renovate/')) }}
name: Build and Push Images
timeout-minutes: 45
environment: ${{ inputs.environment || 'release-base-images' }}
runs-on: ubuntu-24.04
steps:
- name: Checkout default branch (trusted)
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
ref: ${{ github.event.repository.default_branch }}
persist-credentials: false
- name: Cleanup Disk space in runner
uses: ./.github/actions/disk-cleanup
- name: Checkout base branch (trusted)
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
ref: ${{ github.base_ref }}
persist-credentials: false
- name: Copy scripts to trusted directory
run: |
mkdir -p ../cilium-base-branch/images/runtime/
cp ./images/runtime/update-cilium-runtime-image.sh ../cilium-base-branch/images/runtime/
mkdir -p ../cilium-base-branch/images/builder/
cp ./images/builder/update-cilium-builder-image.sh ../cilium-base-branch/images/builder/
mkdir -p ../cilium-base-branch/images/scripts/
cp ./images/scripts/get-image-digest.sh ../cilium-base-branch/images/scripts/
mkdir -p ../cilium-base-branch/api/v1
cp ./api/v1/Makefile ../cilium-base-branch/api/v1/
cp ./Makefile.defs ../cilium-base-branch/Makefile.defs
cp ./Makefile.quiet ../cilium-base-branch/Makefile.quiet
- name: Set Environment Variables
uses: ./.github/actions/set-env-variables
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
- name: Install Cosign
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0
# Warning: since this is a privileged workflow, subsequent workflow job
# steps must take care not to execute untrusted code.
- name: Checkout pull request branch (NOT TRUSTED)
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }}
- name: Set-up git
run: |
git config user.name "Cilium Imagebot"
git config user.email "noreply@cilium.io"
- name: Generating image tag for Cilium-Runtime
id: runtime-tag
run: |
echo tag="$(git ls-tree --full-tree HEAD -- ./images/runtime | awk '{ print $3 }')" >> $GITHUB_OUTPUT
- name: Checking if tag for Cilium-Runtime already exists
id: cilium-runtime-tag-in-repositories
shell: bash
run: |
if docker buildx imagetools inspect quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-runtime:${{ steps.runtime-tag.outputs.tag }} &>/dev/null; then
echo exists="true" >> $GITHUB_OUTPUT
else
echo exists="false" >> $GITHUB_OUTPUT
fi
- name: Login to quay.io
if: ${{ steps.cilium-runtime-tag-in-repositories.outputs.exists == 'false' }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: quay.io
username: ${{ secrets.QUAY_BASE_RELEASE_USERNAME }}
password: ${{ secrets.QUAY_BASE_RELEASE_PASSWORD }}
- name: Release build cilium-runtime
if: ${{ steps.cilium-runtime-tag-in-repositories.outputs.exists == 'false' }}
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
id: docker_build_release_runtime
with:
provenance: false
context: ./images/runtime
file: ./images/runtime/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: |
quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-runtime:${{ steps.runtime-tag.outputs.tag }}
- name: Sign Container Image Runtime
if: ${{ steps.cilium-runtime-tag-in-repositories.outputs.exists == 'false' }}
run: |
cosign sign -y quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-runtime@${{ steps.docker_build_release_runtime.outputs.digest }}
- name: Generate SBOM
if: ${{ steps.cilium-runtime-tag-in-repositories.outputs.exists == 'false' }}
uses: anchore/sbom-action@8d0a6505bf28ced3e85154d13dc6af83299e13f1 # v0.17.4
with:
artifact-name: sbom_cilium-runtime_${{ steps.runtime-tag.outputs.tag }}.spdx.json
output-file: ./sbom_cilium-runtime_${{ steps.runtime-tag.outputs.tag }}.spdx.json
image: quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-runtime:${{ steps.runtime-tag.outputs.tag }}
- name: Attach SBOM attestation to container image
if: ${{ steps.cilium-runtime-tag-in-repositories.outputs.exists == 'false' }}
run: |
cosign attest -r -y --predicate sbom_cilium-runtime_${{ steps.runtime-tag.outputs.tag }}.spdx.json --type spdxjson quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-runtime@${{ steps.docker_build_release_runtime.outputs.digest }}
- name: Image Release Digest Runtime
if: ${{ steps.cilium-runtime-tag-in-repositories.outputs.exists == 'false' }}
shell: bash
run: |
mkdir -p image-digest/
echo "## cilium-runtime" > image-digest/cilium-runtime.txt
echo "" >> image-digest/cilium-runtime.txt
echo "\`quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-runtime:${{ steps.runtime-tag.outputs.tag }}@${{ steps.docker_build_release_runtime.outputs.digest }}\`" >> image-digest/cilium-runtime.txt
echo "" >> image-digest/cilium-runtime.txt
- name: Upload artifact digests runtime
if: ${{ steps.cilium-runtime-tag-in-repositories.outputs.exists == 'false' }}
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: image-digest cilium-runtime
path: image-digest
retention-days: 1
- name: Update Runtime Image
id: update-runtime-image
run: |
if [[ "${{ steps.cilium-runtime-tag-in-repositories.outputs.exists == 'false' }}" == "true" ]]; then
../cilium-base-branch/images/runtime/update-cilium-runtime-image.sh "quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-runtime:${{ steps.runtime-tag.outputs.tag }}@${{ steps.docker_build_release_runtime.outputs.digest }}"
else
digest=$(../cilium-base-branch/images/scripts/get-image-digest.sh "quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-runtime:${{ steps.runtime-tag.outputs.tag }}")
../cilium-base-branch/images/runtime/update-cilium-runtime-image.sh "quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-runtime:${{ steps.runtime-tag.outputs.tag }}@${digest}"
fi
if ! git diff --quiet; then
git commit -sam "images: update cilium-{runtime,builder}"
echo committed="true" >> $GITHUB_OUTPUT
else
echo committed="false" >> $GITHUB_OUTPUT
fi
- name: Generating image tag for Cilium-Builder
id: builder-tag
run: |
echo tag="$(git ls-tree --full-tree HEAD -- ./images/builder | awk '{ print $3 }')" >> $GITHUB_OUTPUT
- name: Checking if tag for Cilium-Builder already exists
id: cilium-builder-tag-in-repositories
shell: bash
run: |
if docker buildx imagetools inspect quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-builder:${{ steps.builder-tag.outputs.tag }} &>/dev/null; then
echo exists="true" >> $GITHUB_OUTPUT
else
echo exists="false" >> $GITHUB_OUTPUT
fi
- name: Login to quay.io
if: ${{ steps.cilium-builder-tag-in-repositories.outputs.exists == 'false' && steps.cilium-runtime-tag-in-repositories.outputs.exists != 'false' }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: quay.io
username: ${{ secrets.QUAY_BASE_RELEASE_USERNAME }}
password: ${{ secrets.QUAY_BASE_RELEASE_PASSWORD }}
- name: Release build cilium-builder
if: ${{ steps.cilium-builder-tag-in-repositories.outputs.exists == 'false' }}
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
id: docker_build_release_builder
with:
provenance: false
context: ./images/builder
file: ./images/builder/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: |
quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-builder:${{ steps.builder-tag.outputs.tag }}
- name: Sign Container Image Builder
if: ${{ steps.cilium-builder-tag-in-repositories.outputs.exists == 'false' }}
run: |
cosign sign -y quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-builder@${{ steps.docker_build_release_builder.outputs.digest }}
- name: Generate SBOM
if: ${{ steps.cilium-builder-tag-in-repositories.outputs.exists == 'false' }}
uses: anchore/sbom-action@8d0a6505bf28ced3e85154d13dc6af83299e13f1 # v0.17.4
with:
artifact-name: sbom_cilium-builder_${{ steps.builder-tag.outputs.tag }}.spdx.json
output-file: ./sbom_cilium-builder_${{ steps.builder-tag.outputs.tag }}.spdx.json
image: quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-builder:${{ steps.builder-tag.outputs.tag }}
- name: Attach SBOM attestation to container image
if: ${{ steps.cilium-runtime-tag-in-repositories.outputs.exists == 'false' }}
run: |
cosign attest -r -y --predicate sbom_cilium-builder_${{ steps.builder-tag.outputs.tag }}.spdx.json --type spdxjson quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-builder@${{ steps.docker_build_release_builder.outputs.digest }}
- name: Image Release Digest Builder
if: ${{ steps.cilium-builder-tag-in-repositories.outputs.exists == 'false' }}
shell: bash
run: |
mkdir -p image-digest/
echo "## cilium-builder" > image-digest/cilium-builder.txt
echo "" >> image-digest/cilium-builder.txt
echo "\`quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-builder:${{ steps.builder-tag.outputs.tag }}@${{ steps.docker_build_release_builder.outputs.digest }}\`" >> image-digest/cilium-builder.txt
echo "" >> image-digest/cilium-builder.txt
- name: Upload artifact digests builder
if: ${{ steps.cilium-builder-tag-in-repositories.outputs.exists == 'false' }}
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: image-digest cilium-builder
path: image-digest
retention-days: 1
- name: Update Runtime Image
run: |
if [[ "${{ steps.cilium-runtime-tag-in-repositories.outputs.exists == 'false' }}" == "true" ]]; then
../cilium-base-branch/images/runtime/update-cilium-runtime-image.sh "quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-runtime:${{ steps.runtime-tag.outputs.tag }}@${{ steps.docker_build_release_runtime.outputs.digest }}"
else
digest=$(../cilium-base-branch/images/scripts/get-image-digest.sh "quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-runtime:${{ steps.runtime-tag.outputs.tag }}")
../cilium-base-branch/images/runtime/update-cilium-runtime-image.sh "quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-runtime:${{ steps.runtime-tag.outputs.tag }}@${digest}"
fi
- name: Update Builder Images
run: |
if [[ "${{ steps.cilium-builder-tag-in-repositories.outputs.exists == 'false' }}" == "true" ]]; then
../cilium-base-branch/images/builder/update-cilium-builder-image.sh "quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-builder:${{ steps.builder-tag.outputs.tag }}@${{ steps.docker_build_release_builder.outputs.digest }}"
else
digest=$(../cilium-base-branch/images/scripts/get-image-digest.sh "quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-builder:${{ steps.builder-tag.outputs.tag }}")
../cilium-base-branch/images/builder/update-cilium-builder-image.sh "quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-builder:${{ steps.builder-tag.outputs.tag }}@${digest}"
fi
- name: Update Protobuf APIs
# The builder image contains 'protoc', which can cause autogenerated
# protobuf files to change. Re-generate the API to compensate.
if: ${{ steps.cilium-builder-tag-in-repositories.outputs.exists == 'false' }}
env:
CONTAINER_IMAGE: quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-builder:${{ steps.builder-tag.outputs.tag }}@${{ steps.docker_build_release_builder.outputs.digest }}
run: |
export VOLUME=$PWD/api/v1
make -C ../cilium-base-branch/api/v1
- name: Commit changes
id: update-builder-image
run: |
if [[ "${{ steps.cilium-builder-tag-in-repositories.outputs.exists == 'false' }}" == "true" ]]; then
../cilium-base-branch/images/builder/update-cilium-builder-image.sh "quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-builder:${{ steps.builder-tag.outputs.tag }}@${{ steps.docker_build_release_builder.outputs.digest }}"
else
digest=$(../cilium-base-branch/images/scripts/get-image-digest.sh "quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-builder:${{ steps.builder-tag.outputs.tag }}")
../cilium-base-branch/images/builder/update-cilium-builder-image.sh "quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-builder:${{ steps.builder-tag.outputs.tag }}@${digest}"
fi
if ! git diff --quiet; then
if [[ "${{ steps.update-runtime-image.outputs.committed }}" == "true" ]]; then
git commit --amend -sam "images: update cilium-{runtime,builder}"
else
git commit -sam "images: update cilium-{runtime,builder}"
fi
echo committed="true" >> $GITHUB_OUTPUT
else
echo committed="false" >> $GITHUB_OUTPUT
fi
- name: Get token
if: ${{ steps.update-runtime-image.outputs.committed == 'true' || steps.update-builder-image.outputs.committed == 'true' }}
id: get_token
uses: cilium/actions-app-token@61a6271ce92ba02f49bf81c755685d59fb25a59a # v0.21.1
with:
APP_PEM: ${{ secrets.AUTO_COMMITTER_PEM }}
APP_ID: ${{ secrets.AUTO_COMMITTER_APP_ID }}
- name: Push changes into PR
if: ${{ steps.update-runtime-image.outputs.committed == 'true' || steps.update-builder-image.outputs.committed == 'true' }}
env:
ref: ${{ github.event.pull_request.head.ref || github.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
run: |
git diff HEAD^
git push https://x-access-token:${{ steps.get_token.outputs.app_token }}@github.com/${{ env.repository }}.git HEAD:${{ env.ref }}
image-digests:
name: Display Digests
runs-on: ubuntu-24.04
needs: build-and-push
steps:
- name: Downloading Image Digests
shell: bash
run: |
mkdir -p image-digest/
- name: Download digests of all images built
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
path: image-digest/
pattern: "*image-digest *"
- name: Image Digests Output
shell: bash
run: |
cd image-digest/
find -type f | sort | xargs -d '\n' cat