feat: add use-buildx option to fall back to plain docker build

This commit is contained in:
Hermes
2026-05-02 18:22:19 -07:00
parent 28a544906c
commit 074185b6cd

View File

@@ -39,6 +39,9 @@ inputs:
build-args:
description: Build args as CSV KEY=VALUE
default: ""
use-buildx:
description: Use docker buildx (set to false for runners without buildx support)
default: "true"
outputs:
image:
@@ -61,13 +64,14 @@ runs:
steps:
- name: Set up QEMU for multi-platform builds
shell: bash
if: inputs.platforms != 'linux/amd64'
if: inputs.use-buildx == 'true' && inputs.platforms != 'linux/amd64'
run: |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes 2>/dev/null || true
- name: Set up Docker Buildx
id: buildx
shell: bash
if: inputs.use-buildx == 'true'
run: |
mkdir -p $HOME/.docker/cli-plugins
curl -fsSL https://github.com/docker/buildx/releases/download/v0.12.1/buildx-v0.12.1.linux-amd64 \
@@ -141,7 +145,7 @@ runs:
DOCKER_BUILDKIT: "1"
run: |
CACHE_FROM_FLAG=""
if [ -n "${{ inputs.cache-from }}" ]; then
if [ -n "${{ inputs.cache-from }}" ] && [ "${{ inputs.use-buildx }}" = "true" ]; then
CACHE_FROM_FLAG="--cache-from=${{ inputs.cache-from }}"
fi
@@ -153,30 +157,57 @@ runs:
fi
PLATFORM_FLAG=""
if [ "${{ inputs.platforms }}" != "linux/amd64" ]; then
if [ "${{ inputs.use-buildx }}" = "true" ] && [ "${{ inputs.platforms }}" != "linux/amd64" ]; then
PLATFORM_FLAG="--platform=${{ inputs.platforms }}"
fi
# Choose output mode
if [ "${{ inputs.push }}" = "true" ]; then
OUTPUT_FLAG="--push --output=type=registry"
else
OUTPUT_FLAG="--load --output=type=docker"
fi
if [ "${{ inputs.use-buildx }}" = "true" ]; then
# Use docker buildx
if [ "${{ inputs.push }}" = "true" ]; then
OUTPUT_FLAG="--push --output=type=registry"
else
OUTPUT_FLAG="--load --output=type=docker"
fi
set -x
docker buildx build \
$PLATFORM_FLAG \
--tag "${{ inputs.image-name }}:${{ steps.meta.outputs.tag }}" \
--tag "${{ inputs.image-name }}:latest" \
$(for t in $(echo ${{ steps.meta.outputs.tags }} | tr ',' ' '); do echo -n "--tag ${{ inputs.image-name }}:$t "; done) \
--file ${{ inputs.context }}/${{ inputs.dockerfile }} \
--cache-to=${{ inputs.cache-to }} \
$CACHE_FROM_FLAG \
$BUILD_ARGS_FLAG \
--progress=plain \
$OUTPUT_FLAG \
${{ inputs.context }}
set -x
docker buildx build \
$PLATFORM_FLAG \
--tag "${{ inputs.image-name }}:${{ steps.meta.outputs.tag }}" \
--tag "${{ inputs.image-name }}:latest" \
$(for t in $(echo ${{ steps.meta.outputs.tags }} | tr ',' ' '); do echo -n "--tag ${{ inputs.image-name }}:$t "; done) \
--file ${{ inputs.context }}/${{ inputs.dockerfile }} \
--cache-to=${{ inputs.cache-to }} \
$CACHE_FROM_FLAG \
$BUILD_ARGS_FLAG \
--progress=plain \
$OUTPUT_FLAG \
${{ inputs.context }}
else
# Plain docker build (no buildx)
if [ "${{ inputs.push }}" = "true" ]; then
set -x
docker build \
--tag "${{ inputs.image-name }}:${{ steps.meta.outputs.tag }}" \
--tag "${{ inputs.image-name }}:latest" \
$(for t in $(echo ${{ steps.meta.outputs.tags }} | tr ',' ' '); do echo -n "--tag ${{ inputs.image-name }}:$t "; done) \
--file ${{ inputs.context }}/${{ inputs.dockerfile }} \
$BUILD_ARGS_FLAG \
--progress=plain \
${{ inputs.context }}
docker push "${{ inputs.image-name }}:${{ steps.meta.outputs.tag }}"
docker push "${{ inputs.image-name }}:latest"
else
set -x
docker build \
--tag "${{ inputs.image-name }}:${{ steps.meta.outputs.tag }}" \
--tag "${{ inputs.image-name }}:latest" \
$(for t in $(echo ${{ steps.meta.outputs.tags }} | tr ',' ' '); do echo -n "--tag ${{ inputs.image-name }}:$t "; done) \
--file ${{ inputs.context }}/${{ inputs.dockerfile }} \
$BUILD_ARGS_FLAG \
--progress=plain \
${{ inputs.context }}
fi
fi
- name: Get image digest
id: push-digest