Enhance Docker host resolution logic: add candidate endpoints and update environment variable
All checks were successful
Publish Container / publish (push) Successful in 7m48s
All checks were successful
Publish Container / publish (push) Successful in 7m48s
This commit is contained in:
parent
a30abd9e3f
commit
6341aa84f4
1 changed files with 13 additions and 14 deletions
|
|
@ -71,6 +71,7 @@ jobs:
|
|||
|
||||
if [ -n "${DOCKER_HOST:-}" ]; then
|
||||
echo "Using configured DOCKER_HOST=${DOCKER_HOST}"
|
||||
echo "DOCKER_HOST=${DOCKER_HOST}" >> "${GITHUB_ENV}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
|
@ -80,20 +81,18 @@ jobs:
|
|||
exit 0
|
||||
fi
|
||||
|
||||
if getent hosts forgejo-docker-in-docker >/dev/null 2>&1; then
|
||||
echo "DOCKER_HOST=tcp://forgejo-docker-in-docker:2375" >> "${GITHUB_ENV}"
|
||||
echo "Resolved DOCKER_HOST from compose service DNS"
|
||||
exit 0
|
||||
fi
|
||||
# Try a set of common candidate endpoints reachable from inside job containers.
|
||||
CANDIDATES="forgejo-docker-in-docker host.docker.internal 172.17.0.1 172.18.0.1 10.0.2.2"
|
||||
for c in $CANDIDATES; do
|
||||
echo "Testing http://${c}:2375/_ping ..."
|
||||
if curl --silent --max-time 2 "http://${c}:2375/_ping" >/dev/null 2>&1 || curl --silent --max-time 2 "http://${c}:2375/version" >/dev/null 2>&1; then
|
||||
echo "DOCKER_HOST=tcp://${c}:2375" >> "${GITHUB_ENV}"
|
||||
echo "Resolved DOCKER_HOST to tcp://${c}:2375"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
|
||||
GATEWAY_IP="$(ip route | awk '/default/ { print $3; exit }')"
|
||||
if [ -n "${GATEWAY_IP}" ]; then
|
||||
echo "DOCKER_HOST=tcp://${GATEWAY_IP}:2375" >> "${GITHUB_ENV}"
|
||||
echo "Resolved DOCKER_HOST from container default gateway: ${GATEWAY_IP}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Could not determine a reachable Docker daemon endpoint. Set vars.DOCKER_HOST explicitly."
|
||||
echo "Could not determine a reachable Docker daemon endpoint from candidates. Set vars.DOCKER_HOST explicitly."
|
||||
exit 1
|
||||
|
||||
- name: Check Docker daemon connectivity
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue