Skip to content

Commit c6bf514

Browse files
authored
Merge pull request #1922 from kube-logging/feat/e2e-image-build-parallel
2 parents d17c8cd + 09ab68e commit c6bf514

File tree

4 files changed

+164
-90
lines changed

4 files changed

+164
-90
lines changed

.github/workflows/artifacts.yaml

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,6 @@ on:
2828
container-image-tag:
2929
description: Container image tag
3030
value: ${{ jobs.container-image.outputs.tag }}
31-
container-image-ref:
32-
description: Container image ref
33-
value: ${{ jobs.container-image.outputs.ref }}
34-
fluentd-full-image-name:
35-
description: Fluentd-full container image name
36-
value: ${{ jobs.fluentd-full-image.outputs.name }}
37-
fluentd-full-image-digest:
38-
description: Fluentd-full container image digest
39-
value: ${{ jobs.fluentd-full-image.outputs.digest }}
40-
fluentd-full-image-tag:
41-
description: Fluentd-full container image tag
42-
value: ${{ jobs.fluentd-full-image.outputs.tag }}
43-
fluentd-full-image-ref:
44-
description: Fluentd-full container image ref
45-
value: ${{ jobs.fluentd-full-image.outputs.ref }}
4631
helm-chart-name:
4732
description: Helm chart OCI name
4833
value: ${{ jobs.helm-chart.outputs.name }}
@@ -80,7 +65,6 @@ jobs:
8065
name: ${{ steps.image-name.outputs.value }}
8166
digest: ${{ steps.build.outputs.digest }}
8267
tag: ${{ steps.meta.outputs.version }}
83-
ref: ${{ steps.image-ref.outputs.value }}
8468

8569
steps:
8670
- name: Checkout repository
@@ -94,6 +78,7 @@ jobs:
9478

9579
- name: Set up Cosign
9680
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0
81+
if: inputs.publish
9782

9883
- name: Set image name
9984
id: image-name
@@ -214,10 +199,6 @@ jobs:
214199
fi
215200
fi
216201

217-
- name: Set image ref
218-
id: image-ref
219-
run: echo "value=${{ steps.image-name.outputs.value }}@${{ steps.build.outputs.digest }}" >> "$GITHUB_OUTPUT"
220-
221202
- name: Fetch image
222203
run: skopeo --insecure-policy copy docker://${{ steps.image-name.outputs.value }}:${{ steps.meta.outputs.version }} oci-archive:image.tar
223204
if: inputs.publish
@@ -275,6 +256,7 @@ jobs:
275256

276257
- name: Set up Cosign
277258
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0
259+
if: inputs.publish && inputs.release
278260

279261
- name: Set chart name
280262
id: chart-name
@@ -435,6 +417,7 @@ jobs:
435417

436418
- name: Set up Cosign
437419
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0
420+
if: inputs.publish && inputs.release
438421

439422
- name: Set chart name
440423
id: chart-name

.github/workflows/dependency-images.yaml

Lines changed: 127 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ on:
2323
fluentd-image-tag:
2424
description: Container image tag
2525
value: ${{ jobs.fluentd.outputs.tag }}
26-
fluentd-image-ref:
27-
description: Container image ref
28-
value: ${{ jobs.fluentd.outputs.ref }}
2926

3027
permissions:
3128
contents: read
@@ -45,10 +42,125 @@ jobs:
4542
IMAGE_TYPES=$(echo '${{ inputs.image-types }}' | jq -R -c 'split(",")')
4643
echo "image-types=${IMAGE_TYPES}" >> $GITHUB_OUTPUT
4744
48-
fluentd-image:
49-
name: Fluentd image
45+
fluentd-image-export:
46+
name: Fluentd image export
5047
needs: prepare-matrix
5148
runs-on: ${{ matrix.platform == 'linux/arm64' && 'linux-arm64' || 'ubuntu-latest' }}
49+
if: ${{ !inputs.publish }}
50+
51+
permissions:
52+
contents: read
53+
packages: write
54+
id-token: write
55+
56+
outputs:
57+
name: ${{ steps.image-name.outputs.value }}
58+
digest: ${{ steps.build.outputs.digest }}
59+
tag: ${{ steps.meta.outputs.version }}
60+
61+
strategy:
62+
matrix:
63+
platform:
64+
- linux/amd64
65+
- linux/arm64
66+
image-type: ${{ fromJson(needs.prepare-matrix.outputs.image-types) }}
67+
68+
steps:
69+
- name: Prepare arm64 environment
70+
if: matrix.platform == 'linux/arm64'
71+
run: |
72+
sudo install -m 0755 -d /etc/apt/keyrings
73+
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
74+
echo \
75+
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
76+
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
77+
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
78+
sudo apt-get update && sudo apt-get install -y acl docker-ce docker-ce-cli containerd.io docker-buildx-plugin
79+
USERID=$(id -u)
80+
sudo setfacl --modify user:${USERID}:rw /var/run/docker.sock
81+
82+
- name: Checkout repository
83+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
84+
85+
- name: Set up QEMU
86+
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
87+
with:
88+
platforms: all
89+
90+
- name: Set up Docker Buildx
91+
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
92+
93+
- name: Set image name
94+
id: image-name
95+
run: echo "value=ghcr.io/${{ github.repository }}/fluentd" >> "$GITHUB_OUTPUT"
96+
97+
- name: Set platform
98+
run: |
99+
platform=${{ matrix.platform }}
100+
echo "PLATFORM=${platform//\//-}" >> $GITHUB_ENV
101+
102+
- name: Gather build metadata
103+
id: meta
104+
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
105+
with:
106+
images: ${{ steps.image-name.outputs.value }}
107+
flavor: |
108+
latest = false
109+
tags: |
110+
type=ref,event=branch,suffix=-${{ matrix.image-type }}
111+
type=ref,event=pr,prefix=pr-,suffix=-${{ matrix.image-type }}
112+
type=semver,pattern={{raw}},suffix=-${{ matrix.image-type }}
113+
type=raw,value=latest,enable={{is_default_branch}},suffix=-${{ matrix.image-type }}
114+
labels: |
115+
org.opencontainers.image.description=Custom Fluentd image for the Logging operator.
116+
org.opencontainers.image.title=Logging operator Fluentd image
117+
org.opencontainers.image.authors=Kube logging authors
118+
org.opencontainers.image.documentation=https://kube-logging.dev/docs/
119+
120+
- name: Build and push fluentd-${{ matrix.image-type }}-${{ matrix.platform }} image
121+
id: build
122+
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0
123+
with:
124+
context: images/fluentd
125+
platforms: ${{ matrix.platform }}
126+
labels: ${{ steps.meta.outputs.labels }}
127+
cache-from: type=gha
128+
cache-to: type=gha,mode=max
129+
target: ${{ matrix.image-type }}
130+
outputs: type=oci,dest=image.tar,name=${{ steps.image-name.outputs.value }},annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }}
131+
132+
- name: Extract OCI tarball
133+
run: |
134+
mkdir -p image
135+
tar -xf image.tar -C image
136+
137+
- name: Run Trivy vulnerability scanner
138+
uses: aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # 0.29.0
139+
env:
140+
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2
141+
TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db:1
142+
with:
143+
input: image
144+
format: sarif
145+
output: trivy-results.sarif
146+
147+
- name: Upload Trivy scan results as artifact
148+
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
149+
with:
150+
name: "[${{ github.job }}-${{ matrix.image-type }}-${{ env.PLATFORM }}] Trivy scan results"
151+
path: trivy-results.sarif
152+
retention-days: 5
153+
154+
- name: Upload Trivy scan results to GitHub Security tab
155+
uses: github/codeql-action/upload-sarif@df409f7d9260372bd5f19e5b04e83cb3c43714ae # v3.27.9
156+
with:
157+
sarif_file: trivy-results.sarif
158+
159+
fluentd-image-push:
160+
name: Fluentd image push
161+
needs: prepare-matrix
162+
runs-on: ${{ matrix.platform == 'linux/arm64' && 'linux-arm64' || 'ubuntu-latest' }}
163+
if: inputs.publish
52164

53165
permissions:
54166
contents: read
@@ -59,7 +171,6 @@ jobs:
59171
name: ${{ steps.image-name.outputs.value }}
60172
digest: ${{ steps.build.outputs.digest }}
61173
tag: ${{ steps.meta.outputs.version }}
62-
ref: ${{ steps.image-ref.outputs.value }}
63174

64175
strategy:
65176
matrix:
@@ -128,7 +239,7 @@ jobs:
128239
cache-from: type=gha
129240
cache-to: type=gha,mode=max
130241
target: ${{ matrix.image-type }}
131-
outputs: type=image,name=${{ steps.image-name.outputs.value }},push-by-digest=true,push=true,annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }}
242+
outputs: type=image,push=true,push-by-digest=true,name=${{ steps.image-name.outputs.value }},annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }}
132243

133244
- name: Export digest
134245
run: |
@@ -176,7 +287,8 @@ jobs:
176287
merge-fluentd-image:
177288
name: Merge Fluentd image
178289
runs-on: ubuntu-latest
179-
needs: [prepare-matrix, fluentd-image]
290+
needs: [prepare-matrix, fluentd-image-push]
291+
if: inputs.publish
180292

181293
permissions:
182294
contents: read
@@ -201,7 +313,6 @@ jobs:
201313
registry: ghcr.io
202314
username: ${{ github.actor }}
203315
password: ${{ github.token }}
204-
if: inputs.publish
205316

206317
- name: Download digests
207318
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
@@ -214,7 +325,7 @@ jobs:
214325
id: meta
215326
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
216327
with:
217-
images: ${{ needs.fluentd-image.outputs.name }}
328+
images: ${{ needs.fluentd-image-push.outputs.name }}
218329
flavor: |
219330
latest = false
220331
tags: |
@@ -226,21 +337,16 @@ jobs:
226337
- name: Create multi-arch manifest list
227338
working-directory: /tmp/digests
228339
run: |
229-
if [[ "${{ inputs.publish }}" == "true" ]]; then
230-
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
231-
$(printf '${{ needs.fluentd-image.outputs.name }}@sha256:%s ' *)
232-
else
233-
docker buildx imagetools create --dry-run $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
234-
$(printf '${{ needs.fluentd-image.outputs.name }}@sha256:%s ' *)
235-
fi
340+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
341+
$(printf '${{ needs.fluentd-image-push.outputs.name }}@sha256:%s ' *)
236342
237343
- name: Export digest
238344
run: |
239-
DIGEST=$(docker buildx imagetools inspect ${{ needs.fluentd-image.outputs.name }}:${{ steps.meta.outputs.version }} --format '{{json .}}' | jq -r '.manifest.digest')
345+
DIGEST=$(docker buildx imagetools inspect ${{ needs.fluentd-image-push.outputs.name }}:${{ steps.meta.outputs.version }} --format '{{json .}}' | jq -r '.manifest.digest')
240346
echo "DIGEST=$DIGEST" >> $GITHUB_ENV
241347
242348
- name: Sign image with GitHub OIDC Token
243-
if: ${{ inputs.publish && github.repository_owner == 'kube-logging' }} # Check if the workflow is called by the same GitHub organization
349+
if: ${{ github.repository_owner == 'kube-logging' }} # Check if the workflow is called by the same GitHub organization
244350
env:
245351
DIGEST: ${{ env.DIGEST }}
246352
TAGS: ${{ steps.meta.outputs.tags }}
@@ -253,7 +359,7 @@ jobs:
253359
cosign sign --yes --rekor-url "https://rekor.sigstore.dev/" ${images}
254360
255361
- name: Verify signed image with cosign
256-
if: ${{ inputs.publish && github.repository_owner == 'kube-logging' }} # Check if the workflow is called by the same GitHub organization
362+
if: ${{ github.repository_owner == 'kube-logging' }} # Check if the workflow is called by the same GitHub organization
257363
env:
258364
DIGEST: ${{ env.DIGEST }}
259365
TAGS: ${{ steps.meta.outputs.tags }}
@@ -265,12 +371,8 @@ jobs:
265371
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" | jq
266372
done
267373
268-
- name: Set image ref
269-
id: image-ref
270-
run: echo "value=${{ needs.fluentd-image.outputs.name }}@${{ env.DIGEST }}" >> "$GITHUB_OUTPUT"
271-
272374
- name: Fetch image
273-
run: skopeo --insecure-policy copy docker://${{ needs.fluentd-image.outputs.name }}:${{ steps.meta.outputs.version }} oci-archive:image.tar
375+
run: skopeo --insecure-policy copy docker://${{ needs.fluentd-image-push.outputs.name }}:${{ steps.meta.outputs.version }} oci-archive:image.tar
274376

275377
- name: Extract OCI tarball
276378
run: |

.github/workflows/e2e.yaml

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,47 @@ env:
1313

1414
jobs:
1515
build:
16-
name: Image build
16+
name: Build ${{ matrix.image }} image
1717
runs-on: ubuntu-latest
18+
19+
strategy:
20+
matrix:
21+
include:
22+
- image: fluentd
23+
context: images/fluentd
24+
tags: fluentd-full:local
25+
target: full
26+
output: fluentd-full.tar
27+
- image: controller
28+
context: .
29+
tags: controller:local
30+
target: e2e-test
31+
build_args: GO_BUILD_FLAGS=-cover -covermode=atomic
32+
output: controller.tar
33+
1834
steps:
1935
- name: Checkout
2036
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2137

2238
- name: Set up Docker Buildx
2339
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
2440

25-
- name: Build and export fluentd-full image
26-
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0
27-
with:
28-
context: images/fluentd
29-
tags: fluentd-full:local
30-
cache-from: type=gha
31-
cache-to: type=gha,mode=max
32-
target: full
33-
outputs: type=docker,dest=/tmp/fluentd-full.tar
34-
35-
- name: Build and export operator image
41+
- name: Build and export ${{ matrix.image }}-image
3642
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0
3743
with:
38-
context: .
39-
tags: controller:local
44+
context: ${{ matrix.context }}
45+
tags: ${{ matrix.tags }}
4046
cache-from: type=gha
4147
cache-to: type=gha,mode=max
42-
target: e2e-test
43-
build-args: |
44-
GO_BUILD_FLAGS=-cover -covermode=atomic
45-
outputs: type=docker,dest=/tmp/controller.tar
48+
target: ${{ matrix.target }}
49+
build-args: ${{ matrix.build_args }}
50+
outputs: type=docker,dest=/tmp/${{ matrix.output }}
4651

4752
- name: Upload artifact
4853
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
4954
with:
50-
name: e2e-images
51-
path: /tmp/*.tar
55+
name: e2e-${{ matrix.image }}
56+
path: /tmp/${{ matrix.output }}
5257

5358
go:
5459
name: Go end2end tests
@@ -67,8 +72,9 @@ jobs:
6772
- name: Download artifact
6873
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
6974
with:
70-
name: e2e-images
75+
pattern: e2e-*
7176
path: /tmp
77+
merge-multiple: true
7278

7379
- name: Load image
7480
run: |
@@ -124,8 +130,9 @@ jobs:
124130
- name: Download artifact
125131
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
126132
with:
127-
name: e2e-images
133+
pattern: e2e-*
128134
path: /tmp
135+
merge-multiple: true
129136

130137
- name: Load image
131138
run: |

0 commit comments

Comments
 (0)