feat: composite action for labeled buildkitd + remote buildx driver

The default docker-container driver of docker/setup-buildx-action ignores
driver-opts labels (container created with labels={}) and the Docker API
cannot PATCH labels on existing containers. Start a privileged, labeled
buildkitd ourselves (idempotent, restart unless-stopped) and connect via
driver: remote endpoint docker-container://<name>.
This commit is contained in:
2026-09-01 11:52:19 +02:00
commit 69d77d4ca0
+47
View File
@@ -0,0 +1,47 @@
name: 'Setup BuildKit (with labels)'
description: 'Idempotently start a labeled buildkitd container and point buildx at it via the remote driver. The default docker-container driver cannot set container labels, and the Docker API has no PATCH-labels for existing containers — so we manage the container ourselves and Watchtower/Dockhand see the labels.'
inputs:
container_name:
description: 'Name of the buildkitd container'
required: false
default: 'buildkitd'
image:
description: 'BuildKit image'
required: false
default: 'moby/buildkit:buildx-stable-1'
monitor_only:
description: 'Value for com.centurylinklabs.watchtower.monitor-only'
required: false
default: 'false'
dockhand_notify:
description: 'Value for dockhand.notify'
required: false
default: 'false'
cleanup:
description: 'Stop the buildkitd container after the job (only for single-job runners; leave false on shared runners — concurrent jobs may be using it)'
required: false
default: 'false'
runs:
using: 'composite'
steps:
- name: Start BuildKit container (with labels)
shell: bash
run: |
docker ps -a --format '{{.Names}}' | grep -qx '${{ inputs.container_name }}' || \
docker run -d --name ${{ inputs.container_name }} --privileged \
--restart unless-stopped \
--label com.centurylinklabs.watchtower.monitor-only=${{ inputs.monitor_only }} \
--label dockhand.notify=${{ inputs.dockhand_notify }} \
${{ inputs.image }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
with:
driver: remote
endpoint: docker-container://${{ inputs.container_name }}
- name: Stop BuildKit (idle cleanup)
if: ${{ inputs.cleanup == 'true' && always() }}
shell: bash
run: docker stop ${{ inputs.container_name }} || true