From 7841e69c38f9bfff8df3824126034b2d81a8ceb8 Mon Sep 17 00:00:00 2001 From: Ondrej Belusky Date: Tue, 1 Sep 2026 13:29:26 +0200 Subject: [PATCH] fix: recreate buildkitd when not running (config drift) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The name-exists guard skipped recreation when a stopped container from a previous failed run existed — e.g. one created before the port mapping was added, leaving 127.0.0.1:8375 with no listener. New logic: recreate the container whenever it is not running; keep it (warm cache) when it is already up. --- action.yml | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/action.yml b/action.yml index 7edd326..37b8127 100644 --- a/action.yml +++ b/action.yml @@ -36,14 +36,19 @@ runs: - 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 \ - --network ${{ inputs.network }} \ - -p 127.0.0.1:${{ inputs.port }}:${{ inputs.port }} \ - --restart unless-stopped \ - --label com.centurylinklabs.watchtower.monitor-only=${{ inputs.monitor_only }} \ - --label dockhand.notify=${{ inputs.dockhand_notify }} \ - ${{ inputs.image }} --addr tcp://0.0.0.0:${{ inputs.port }} + # Recreate if a stopped/old container exists (config drift, e.g. port + # mapping changes, would otherwise be skipped by the name guard). + # If it is already running with the right config, keep it (warm cache). + if [ "$(docker inspect -f '{{.State.Running}}' ${{ inputs.container_name }} 2>/dev/null)" != "true" ]; then + docker rm -f ${{ inputs.container_name }} >/dev/null 2>&1 || true + docker run -d --name ${{ inputs.container_name }} --privileged \ + --network ${{ inputs.network }} \ + -p 127.0.0.1:${{ inputs.port }}:${{ inputs.port }} \ + --restart unless-stopped \ + --label com.centurylinklabs.watchtower.monitor-only=${{ inputs.monitor_only }} \ + --label dockhand.notify=${{ inputs.dockhand_notify }} \ + ${{ inputs.image }} --addr tcp://0.0.0.0:${{ inputs.port }} + fi - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4