Skip to content

Commit 072cda5

Browse files
committed
feat: support passing 'builder' parameter in push-to-gar-docker
We are trying to use the [buildkit-cache-dance][1] method to get better caching of our Go build cache in CI, but that requires having control over the buildx builder in our pipelines. This commit adds the 'builder' input to the push-to-gar-docker shared action, and conditionally creates a new builder if it isn't provided. [1]: https://github.com/reproducible-containers/buildkit-cache-dance/
1 parent 0657368 commit 072cda5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

actions/push-to-gar-docker/action.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ inputs:
9191
Whether to load the built image into the local docker daemon.
9292
required: false
9393
default: "false"
94+
builder:
95+
description: |
96+
Name of the buildx builder to use. If not specified, a new builder will be created.
97+
This is useful when you need to reuse a builder, for example with buildkit-cache-dance.
98+
required: false
9499

95100
outputs:
96101
version:
@@ -117,6 +122,9 @@ outputs:
117122
metadata:
118123
description: "Build result metadata (from docker/build-push-action)"
119124
value: ${{ steps.build.outputs.metadata }}
125+
builder:
126+
description: "Name of the buildx builder used"
127+
value: ${{ steps.resolve-builder.outputs.name }}
120128

121129
runs:
122130
using: composite
@@ -178,11 +186,23 @@ runs:
178186

179187
- name: Set up Docker Buildx
180188
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
189+
id: buildx
190+
if: ${{ inputs.builder == '' }}
181191
with:
182192
driver: ${{ inputs.docker-buildx-driver }}
183193
version: v0.28.0 # Latest is 0.29.1 which has an issue with pushing to some registries https://github.com/docker/buildx/issues/3446
184194
buildkitd-config: ${{ runner.environment == 'self-hosted' && '/etc/buildkitd.toml' || '' }}
185195

196+
- name: Resolve builder name
197+
id: resolve-builder
198+
shell: bash
199+
run: |
200+
if [ -n "${{ inputs.builder }}" ]; then
201+
echo "name=${{ inputs.builder }}" >> "${GITHUB_OUTPUT}"
202+
else
203+
echo "name=${{ steps.buildx.outputs.name }}" >> "${GITHUB_OUTPUT}"
204+
fi
205+
186206
# The `context` input is flagged by Zizmor as a [sink]. This means that with
187207
# the upstream action the user's input to the input ends up in an output,
188208
# and so if it's not handled properly, it could lead to a template injection
@@ -209,6 +229,7 @@ runs:
209229
build-contexts: ${{ inputs.build-contexts }}
210230
secrets: ${{ inputs.secrets }}
211231
load: ${{ inputs.load == 'true' }}
232+
builder: ${{ steps.resolve-builder.outputs.name }}
212233

213234
- name: Cleanup checkout directory
214235
if: ${{ !cancelled() }}

0 commit comments

Comments
 (0)