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