From 69d77d4ca0845acf8b1c485d1eea7e36932c19ab Mon Sep 17 00:00:00 2001 From: Ondrej Belusky Date: Tue, 1 Sep 2026 11:52:19 +0200 Subject: [PATCH] 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://. --- action.yml | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 action.yml diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..fec00e7 --- /dev/null +++ b/action.yml @@ -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