fix(build-and-push): stop DOCKER_HOST overriding remote-builder context
- DOCKER_HOST env var was set to the builder hostname, which Docker treats as tcp://host:2375 and which overrides the active docker context, so the SSH remote-builder context was ignored (Cannot connect to tcp://docker-build.haven:2375) - context endpoint used a literal ssh://***@ instead of the docker_user input - create an actual buildx builder instance named remote-builder (build-push-action needs a builder instance, not just a context)
This commit is contained in:
@@ -63,22 +63,35 @@ runs:
|
||||
shell: bash
|
||||
env:
|
||||
SSH_KEY: ${{ inputs.ssh_key }}
|
||||
DOCKER_HOST: ${{ inputs.docker_host }}
|
||||
BUILDER_HOST: ${{ inputs.docker_host }}
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${SSH_KEY}" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
ssh-keyscan "${DOCKER_HOST}" >> ~/.ssh/known_hosts
|
||||
ssh-keyscan "${BUILDER_HOST}" >> ~/.ssh/known_hosts
|
||||
|
||||
- name: Set up remote Docker Buildx builder
|
||||
shell: bash
|
||||
env:
|
||||
DOCKER_HOST: ${{ inputs.docker_host }}
|
||||
DOCKER_USER: ${{ inputs.docker_user }}
|
||||
BUILDER_HOST: ${{ inputs.docker_host }}
|
||||
BUILDER_USER: ${{ inputs.docker_user }}
|
||||
run: |
|
||||
# Never set the DOCKER_HOST env var to the builder hostname: a bare
|
||||
# value is treated as tcp://host:2375 and, more importantly, DOCKER_HOST
|
||||
# *overrides* the active docker context — which is exactly what broke
|
||||
# the previous version (it tried tcp://docker-build.haven:2375 instead
|
||||
# of the SSH context). We drive everything through a context instead.
|
||||
unset DOCKER_HOST || true
|
||||
|
||||
docker context rm -f remote-builder 2>/dev/null || true
|
||||
docker context create remote-builder \
|
||||
--docker "host=ssh://${DOCKER_USER}@${DOCKER_HOST}"
|
||||
docker context use remote-builder
|
||||
--docker "host=ssh://${BUILDER_USER}@${BUILDER_HOST}"
|
||||
|
||||
# build-push-action's `builder: remote-builder` needs a *buildx builder
|
||||
# instance* named remote-builder, not just a context. Create it from the
|
||||
# SSH context so it resolves to the remote engine over SSH.
|
||||
docker buildx rm -f remote-builder 2>/dev/null || true
|
||||
docker buildx create --name remote-builder --context remote-builder --use
|
||||
docker buildx inspect --bootstrap
|
||||
|
||||
- name: Generate tags list
|
||||
|
||||
Reference in New Issue
Block a user