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
3027permissions :
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
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 : |
0 commit comments