diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 2db53f3..f259354 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -11,37 +11,76 @@ jobs: ci: name: build + unit + e2e runs-on: ubuntu-latest - services: - docker: - image: docker:dind - ports: - - "2375:2375" steps: - name: Checkout uses: actions/checkout@v4 - # Resolve the dind daemon endpoint up front (fail fast if the runner's dind is - # misconfigured). Gitea Actions services are sibling containers on the job network, - # reachable by service id; depending on runner config published ports may also land - # on localhost — try both and export whichever answers. The app URL follows the same - # endpoint: the flight container's port 3000 is published inside dind, so it is - # reachable wherever the daemon itself is. + # Full-dind runner: job containers already reach the runner's own docker daemon + # (pre-set DOCKER_HOST and/or a mounted /var/run/docker.sock) — no dind service. + # Resolve which endpoint works, export it as DOCKER_HOST, and derive E2E_BASE_URL + # from it: for tcp/https endpoints published ports live on that host; for a unix + # socket the daemon sits on the job's docker bridge, so its published ports are + # reached via the default gateway. - name: Resolve dind endpoint run: | - for host in tcp://localhost:2375 tcp://docker:2375; do - for i in $(seq 1 15); do - if DOCKER_HOST="$host" docker version --format '{{.Server.Version}}' >/dev/null 2>&1; then - echo "DOCKER_HOST=$host" >> "$GITHUB_ENV" - case "$host" in - *localhost*) echo "E2E_BASE_URL=http://localhost:3000" >> "$GITHUB_ENV" ;; - *) echo "E2E_BASE_URL=http://docker:3000" >> "$GITHUB_ENV" ;; - esac + set -u + + derive_url() { + ep="$1" + case "$ep" in + unix://*) + gw=$(ip route show default 2>/dev/null | awk '{print $3; exit}') + if [ -z "${gw:-}" ]; then + echo "::error::unix-socket daemon but no default gateway found (needed to reach published ports)" >&2 + return 1 + fi + echo "http://$gw:3000" ;; + tcp://*|https://*) + hostpart=$(printf '%s' "$ep" | sed -e 's|^[a-z]*://||') + hostpart=${hostpart%%:*} + if [ -z "$hostpart" ]; then return 1; fi + echo "http://$hostpart:3000" ;; + *) + echo "::error::cannot derive app URL from endpoint '$ep'" >&2 + return 1 ;; + esac + } + + # 1) A pre-set DOCKER_HOST that answers is used as-is, no probing. + if [ -n "${DOCKER_HOST:-}" ]; then + i=0 + while [ "$i" -lt 5 ]; do + if docker version --format '{{.Server.Version}}' >/dev/null 2>&1; then + url=$(derive_url "$DOCKER_HOST") || exit 1 + echo "using pre-set DOCKER_HOST=$DOCKER_HOST (E2E_BASE_URL=$url)" + echo "DOCKER_HOST=$DOCKER_HOST" >> "$GITHUB_ENV" + echo "E2E_BASE_URL=$url" >> "$GITHUB_ENV" exit 0 fi - sleep 2 + i=$((i+1)); sleep 2 + done + fi + + # 2) Otherwise probe candidates in order (short retry each). + tried="" + for ep in "${DOCKER_HOST:-}" unix:///var/run/docker.sock tcp://localhost:2375 tcp://localhost:2376 tcp://docker:2375 tcp://docker:2376; do + [ -n "$ep" ] || continue + case " $tried " in *" $ep "*) continue ;; esac + tried="$tried $ep" + i=0 + while [ "$i" -lt 10 ]; do + if DOCKER_HOST="$ep" docker version --format '{{.Server.Version}}' >/dev/null 2>&1; then + url=$(derive_url "$ep") || exit 1 + echo "using probed endpoint $ep (E2E_BASE_URL=$url)" + echo "DOCKER_HOST=$ep" >> "$GITHUB_ENV" + echo "E2E_BASE_URL=$url" >> "$GITHUB_ENV" + exit 0 + fi + i=$((i+1)); sleep 2 done done - echo "::error::no reachable dind endpoint (tried tcp://localhost:2375 and tcp://docker:2375)" >&2 + + echo "::error::no reachable docker daemon (tried: ${DOCKER_HOST:-}, unix:///var/run/docker.sock, tcp://localhost:2375, tcp://localhost:2376, tcp://docker:2375, tcp://docker:2376)" >&2 exit 1 - name: Setup Node