Simplify: plain docker build with DOCKER_HOST, no buildx

This commit is contained in:
Hermes
2026-05-02 18:56:57 -07:00
parent c6aae208d1
commit 6de66e6940

View File

@@ -1,10 +1,10 @@
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
inputs:
dockerfile:
description: Path to Dockerfile (relative to build_context)
description: Path to Dockerfile (relative to build context)
default: Dockerfile
context:
description: Build context path (relative to repo root)
@@ -15,12 +15,6 @@ inputs:
tags:
description: Additional tags as CSV appended to defaults
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:
description: Docker registry for login (e.g. ghcr.io)
default: ""
@@ -30,18 +24,12 @@ inputs:
registry-password:
description: Docker registry password (use secrets.DOCKER_PASSWORD)
default: ""
platforms:
description: Target platforms as CSV (e.g. linux/amd64,linux/arm64)
default: linux/amd64
push:
description: Push images to registry after build
default: "false"
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:
@@ -58,54 +46,9 @@ runs:
using: composite
env:
DOCKER_HOST: tcp://docker.local:2375
DOCKER_BUILDKIT: "1"
BUILDKIT_HOST: tcp://docker.local:2375
DOCKER_BUILDKIT: "0"
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
id: meta
shell: bash
@@ -142,18 +85,6 @@ runs:
id: build
shell: bash
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=""
if [ -n "${{ inputs.build-args }}" ]; then
for arg in $(echo "${{ inputs.build-args }}" | tr ',' ' '); do
@@ -161,56 +92,26 @@ runs:
done
fi
PLATFORM_FLAG=""
if [ "${{ inputs.use-buildx }}" = "true" ] && [ "${{ inputs.platforms }}" != "linux/amd64" ]; then
PLATFORM_FLAG="--platform=${{ inputs.platforms }}"
fi
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 }}
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 }}
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: Push image
id: push
if: inputs.push == 'true'
shell: bash
run: |
set -x
docker push "${{ inputs.image-name }}:${{ steps.meta.outputs.tag }}"
docker push "${{ inputs.image-name }}:latest"
for t in $(echo ${{ steps.meta.outputs.tags }} | tr ',' ' '); do
docker push "${{ inputs.image-name }}:$t"
done
- name: Get image digest
id: push-digest
@@ -219,4 +120,3 @@ runs:
run: |
DIGEST="$(docker inspect "${{ inputs.image-name }}:${{ steps.meta.outputs.tag }}" --format '{{.Digest}}' 2>/dev/null)"
echo "digest=$DIGEST" >> $GITHUB_OUTPUT
echo "digest_full=${{ inputs.image-name }}@$DIGEST" >> $GITHUB_OUTPUT