Skip to content

Commit 8d15519

Browse files
workflows: support optional image pushing
Signed-off-by: Patrick Stephens <pat@chronosphere.io>
1 parent cfc9ba9 commit 8d15519

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

.github/workflows/call-build-images.yaml

+20-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ on:
3434
type: string
3535
required: false
3636
default: ""
37+
push:
38+
description: Optionally push the images to the registry, defaults to true but for forks we cannot do this in PRs.
39+
type: boolean
40+
required: false
41+
default: true
3742
secrets:
3843
token:
3944
description: The Github token or similar to authenticate with for the registry.
@@ -44,6 +49,8 @@ on:
4449
cosign_private_key_password:
4550
description: If the Cosign key requires a password then specify here, otherwise not required.
4651
required: false
52+
env:
53+
DOCKER_PUSH_EXTRA_FLAGS: ${{ inputs.push && '' || '--dry-run' }}
4754
jobs:
4855
call-build-images-meta:
4956
name: Extract any supporting metadata
@@ -120,8 +127,8 @@ jobs:
120127
platforms: linux/${{ matrix.platform }}
121128
# Must be disabled to provide legacy format images from the registry
122129
provenance: false
123-
push: true
124-
load: false
130+
push: ${{ inputs.push }}
131+
load: ${{ !inputs.push}}
125132
build-args: |
126133
FLB_NIGHTLY_BUILD=${{ inputs.unstable }}
127134
RELEASE_VERSION=${{ inputs.version }}
@@ -184,12 +191,13 @@ jobs:
184191

185192
- name: Create production manifest
186193
run: |
187-
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
194+
docker buildx imagetools create $DOCKER_PUSH_EXTRA_FLAGS $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
188195
$(printf '${{ inputs.registry }}/${{ inputs.image }}@sha256:%s ' *)
189196
shell: bash
190197
working-directory: /tmp/production-digests
191198

192199
- name: Inspect image
200+
if: inputs.push
193201
run: |
194202
docker buildx imagetools inspect ${{ inputs.registry }}/${{ inputs.image }}:${{ steps.meta.outputs.version }}
195203
shell: bash
@@ -235,17 +243,19 @@ jobs:
235243

236244
- name: Create debug manifest
237245
run: |
238-
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
246+
docker buildx imagetools create $DOCKER_PUSH_EXTRA_FLAGS $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
239247
$(printf '${{ inputs.registry }}/${{ inputs.image }}@sha256:%s ' *)
240248
shell: bash
241249
working-directory: /tmp/debug-digests
242250

243251
- name: Inspect image
252+
if: inputs.push
244253
run: |
245254
docker buildx imagetools inspect ${{ inputs.registry }}/${{ inputs.image }}:${{ steps.debug-meta.outputs.version }}
246255
shell: bash
247256

248257
call-build-images-generate-schema:
258+
if: inputs.push
249259
needs:
250260
- call-build-images-meta
251261
- call-build-container-image-manifests
@@ -276,6 +286,7 @@ jobs:
276286
if-no-files-found: error
277287

278288
call-build-images-scan:
289+
if: inputs.push
279290
needs:
280291
- call-build-images-meta
281292
- call-build-container-image-manifests
@@ -311,6 +322,7 @@ jobs:
311322
exit-level: WARN
312323

313324
call-build-images-sign:
325+
if: inputs.push
314326
needs:
315327
- call-build-images-meta
316328
- call-build-container-image-manifests
@@ -400,6 +412,10 @@ jobs:
400412
- name: Build the production images
401413
run: |
402414
docker build -t ${{ inputs.registry }}/${{ inputs.image }}:windows-${{ matrix.windows-base-version }}-${{ inputs.version }} --build-arg FLB_NIGHTLY_BUILD=${{ inputs.unstable }} --build-arg WINDOWS_VERSION=ltsc${{ matrix.windows-base-version }} -f ./dockerfiles/Dockerfile.windows .
415+
416+
- name: Push the production images
417+
if: inputs.push
418+
run: |
403419
docker push ${{ inputs.registry }}/${{ inputs.image }}:windows-${{ matrix.windows-base-version }}-${{ inputs.version }}
404420
405421
# We cannot use this action as it requires privileged mode

.github/workflows/pr-package-tests.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ jobs:
4747
username: ${{ github.actor }}
4848
image: ${{ github.repository }}/pr
4949
unstable: ${{ needs.pr-package-test-build-get-meta.outputs.date }}
50+
# We do not push as forks cannot get a token with the right permissions
51+
push: false
5052
secrets:
5153
token: ${{ secrets.GITHUB_TOKEN }}
5254
cosign_private_key: ${{ secrets.COSIGN_PRIVATE_KEY }}

0 commit comments

Comments
 (0)