Simplify: plain docker build with DOCKER_HOST, no buildx
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
name: Docker Build + Push
|
name: Docker Build + Push
|
||||||
description: Build and push Docker images with buildx and layer caching for Gitea Actions
|
description: Build and push Docker images for Gitea Actions using the docker daemon at DOCKER_HOST
|
||||||
author: eric
|
author: eric
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
dockerfile:
|
dockerfile:
|
||||||
description: Path to Dockerfile (relative to build_context)
|
description: Path to Dockerfile (relative to build context)
|
||||||
default: Dockerfile
|
default: Dockerfile
|
||||||
context:
|
context:
|
||||||
description: Build context path (relative to repo root)
|
description: Build context path (relative to repo root)
|
||||||
@@ -15,12 +15,6 @@ inputs:
|
|||||||
tags:
|
tags:
|
||||||
description: Additional tags as CSV appended to defaults
|
description: Additional tags as CSV appended to defaults
|
||||||
default: ""
|
default: ""
|
||||||
cache-from:
|
|
||||||
description: Cache source (e.g. type=gha, or image:tag)
|
|
||||||
default: type=local,src=/tmp/buildx-cache
|
|
||||||
cache-to:
|
|
||||||
description: Cache destination for buildx (type=gha or type=local)
|
|
||||||
default: type=local,dest=/tmp/buildx-cache,mode=max
|
|
||||||
registry:
|
registry:
|
||||||
description: Docker registry for login (e.g. ghcr.io)
|
description: Docker registry for login (e.g. ghcr.io)
|
||||||
default: ""
|
default: ""
|
||||||
@@ -30,18 +24,12 @@ inputs:
|
|||||||
registry-password:
|
registry-password:
|
||||||
description: Docker registry password (use secrets.DOCKER_PASSWORD)
|
description: Docker registry password (use secrets.DOCKER_PASSWORD)
|
||||||
default: ""
|
default: ""
|
||||||
platforms:
|
|
||||||
description: Target platforms as CSV (e.g. linux/amd64,linux/arm64)
|
|
||||||
default: linux/amd64
|
|
||||||
push:
|
push:
|
||||||
description: Push images to registry after build
|
description: Push images to registry after build
|
||||||
default: "false"
|
default: "false"
|
||||||
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:
|
||||||
@@ -58,54 +46,9 @@ runs:
|
|||||||
using: composite
|
using: composite
|
||||||
env:
|
env:
|
||||||
DOCKER_HOST: tcp://docker.local:2375
|
DOCKER_HOST: tcp://docker.local:2375
|
||||||
DOCKER_BUILDKIT: "1"
|
DOCKER_BUILDKIT: "0"
|
||||||
BUILDKIT_HOST: tcp://docker.local:2375
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up QEMU for multi-platform builds
|
|
||||||
shell: bash
|
|
||||||
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 \
|
|
||||||
-o $HOME/.docker/cli-plugins/docker-buildx
|
|
||||||
chmod +x $HOME/.docker/cli-plugins/docker-buildx
|
|
||||||
docker buildx version
|
|
||||||
|
|
||||||
# Clean up any existing broken builder
|
|
||||||
docker buildx rm -f gitea-builder 2>/dev/null || true
|
|
||||||
|
|
||||||
# Try docker-container driver first (for multi-platform), fall back to docker driver
|
|
||||||
OUTPUT=$(docker buildx create \
|
|
||||||
--name gitea-builder \
|
|
||||||
--driver docker-container \
|
|
||||||
--driver-opt image=moby/buildkit:buildx-stable-1 \
|
|
||||||
--driver-opt network=host \
|
|
||||||
--use 2>&1)
|
|
||||||
echo "$OUTPUT"
|
|
||||||
|
|
||||||
if echo "$OUTPUT" | grep -qi "error\|failed\|permission\|denied"; then
|
|
||||||
# docker-container failed, fall back to docker driver
|
|
||||||
docker buildx rm -f gitea-builder 2>/dev/null || true
|
|
||||||
docker buildx create --name gitea-builder --driver docker --use
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Verify builder works
|
|
||||||
INSPECT_OUTPUT=$(docker buildx inspect --bootstrap 2>&1) || true
|
|
||||||
echo "$INSPECT_OUTPUT"
|
|
||||||
if echo "$INSPECT_OUTPUT" | grep -qi "error\|failed"; then
|
|
||||||
docker buildx rm -f gitea-builder 2>/dev/null || true
|
|
||||||
docker buildx create --name gitea-builder --driver docker --use
|
|
||||||
docker buildx inspect --bootstrap
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Compute metadata
|
- name: Compute metadata
|
||||||
id: meta
|
id: meta
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -142,18 +85,6 @@ runs:
|
|||||||
id: build
|
id: build
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
# Disable BuildKit for plain docker builds (avoids container networking issues)
|
|
||||||
export DOCKER_BUILDKIT=0
|
|
||||||
|
|
||||||
if [ "${{ inputs.use-buildx }}" = "true" ]; then
|
|
||||||
export DOCKER_BUILDKIT=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
CACHE_FROM_FLAG=""
|
|
||||||
if [ -n "${{ inputs.cache-from }}" ] && [ "${{ inputs.use-buildx }}" = "true" ]; then
|
|
||||||
CACHE_FROM_FLAG="--cache-from=${{ inputs.cache-from }}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
BUILD_ARGS_FLAG=""
|
BUILD_ARGS_FLAG=""
|
||||||
if [ -n "${{ inputs.build-args }}" ]; then
|
if [ -n "${{ inputs.build-args }}" ]; then
|
||||||
for arg in $(echo "${{ inputs.build-args }}" | tr ',' ' '); do
|
for arg in $(echo "${{ inputs.build-args }}" | tr ',' ' '); do
|
||||||
@@ -161,56 +92,26 @@ runs:
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PLATFORM_FLAG=""
|
set -x
|
||||||
if [ "${{ inputs.use-buildx }}" = "true" ] && [ "${{ inputs.platforms }}" != "linux/amd64" ]; then
|
docker build \
|
||||||
PLATFORM_FLAG="--platform=${{ inputs.platforms }}"
|
--tag "${{ inputs.image-name }}:${{ steps.meta.outputs.tag }}" \
|
||||||
fi
|
--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 \
|
||||||
|
${{ inputs.context }}
|
||||||
|
|
||||||
if [ "${{ inputs.use-buildx }}" = "true" ]; then
|
- name: Push image
|
||||||
# Use docker buildx
|
id: push
|
||||||
if [ "${{ inputs.push }}" = "true" ]; then
|
if: inputs.push == 'true'
|
||||||
OUTPUT_FLAG="--push --output=type=registry"
|
shell: bash
|
||||||
else
|
run: |
|
||||||
OUTPUT_FLAG="--load --output=type=docker"
|
set -x
|
||||||
fi
|
docker push "${{ inputs.image-name }}:${{ steps.meta.outputs.tag }}"
|
||||||
|
docker push "${{ inputs.image-name }}:latest"
|
||||||
set -x
|
for t in $(echo ${{ steps.meta.outputs.tags }} | tr ',' ' '); do
|
||||||
docker buildx build \
|
docker push "${{ inputs.image-name }}:$t"
|
||||||
$PLATFORM_FLAG \
|
done
|
||||||
--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 \
|
|
||||||
${{ 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 \
|
|
||||||
${{ inputs.context }}
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Get image digest
|
- name: Get image digest
|
||||||
id: push-digest
|
id: push-digest
|
||||||
@@ -219,4 +120,3 @@ runs:
|
|||||||
run: |
|
run: |
|
||||||
DIGEST="$(docker inspect "${{ inputs.image-name }}:${{ steps.meta.outputs.tag }}" --format '{{.Digest}}' 2>/dev/null)"
|
DIGEST="$(docker inspect "${{ inputs.image-name }}:${{ steps.meta.outputs.tag }}" --format '{{.Digest}}' 2>/dev/null)"
|
||||||
echo "digest=$DIGEST" >> $GITHUB_OUTPUT
|
echo "digest=$DIGEST" >> $GITHUB_OUTPUT
|
||||||
echo "digest_full=${{ inputs.image-name }}@$DIGEST" >> $GITHUB_OUTPUT
|
|
||||||
|
|||||||
Reference in New Issue
Block a user