fix(ci): scan all interfaces and full /24 to locate DinD daemon

The previous fallback only scanned .1-.50 of the first interface's
subnet, missing the DinD container when its IP is higher (.51+) or
when the forgejo-jobs network is on a different interface than
hostname -I returned first.

Now iterates all non-loopback IPs from hostname -I, scans each
subnet's full /24 (.1-254), and uses a 0.3 s bash /dev/tcp probe
instead of nc -zw1 to keep the total scan time under ~80 s.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Thomas SharedInbox
2026-05-24 01:52:41 +02:00
co-authored by Claude Sonnet 4.6
parent 2a92c8766f
commit 68dcee6968
+12 -9
View File
@@ -53,17 +53,20 @@ jobs:
exit 0
fi
# Codeberg's act runner may not register the service container with the
# 'docker' DNS alias. Fall back: scan the local /24 subnet for port 2375.
# 'docker' DNS alias. Scan all local /24 subnets (one per runner
# interface) for any host accepting connections on port 2375.
echo "Docker unreachable via hostname; scanning network for DinD..." >&2
MY_IP=$(hostname -I | awk '{print $1}')
PREFIX=$(echo "$MY_IP" | cut -d. -f1-3)
FOUND=""
for i in $(seq 1 50); do
ip="${PREFIX}.${i}"
if nc -zw1 "$ip" 2375 2>/dev/null; then
FOUND="$ip"
break
fi
for MY_IP in $(hostname -I); do
case "$MY_IP" in 127.*) continue ;; esac
PREFIX=$(echo "$MY_IP" | cut -d. -f1-3)
for i in $(seq 1 254); do
ip="${PREFIX}.${i}"
if (timeout 0.3 bash -c "echo >/dev/tcp/${ip}/2375" 2>/dev/null); then
FOUND="$ip"
break 2
fi
done
done
if [ -z "$FOUND" ]; then
echo "ERROR: Could not locate Docker daemon on the network" >&2