fix(daemon): Map the mock server to an address job containers can reach on every daemon

What

On Docker Desktop's WSL2 backend, jobs sat at Getting source from Git repository for ~130s and then failed with Failed to connect to glci-mock:<port> ... Could not connect to server. This happened on every job of every project (#179 (closed)).

Still reproduces on main (checked 2026-10-30): PreparePipeline / RepreparePipelineForResume map glci-mock to the pre-resolved gateway of a glci network on every daemon. The earlier fix (!198 (closed)) was auto-closed for inactivity and never merged. This MR rebases that work onto current main, then corrects it for what CI showed (below) and adds diagnostics.

Why

FF_NETWORK_PER_BUILD puts each job on a network gitlab-runner creates, never on a glci network. Jobs therefore reach the mock through an extra_hosts entry pointing at the Docker host, then the port published there. Two candidate addresses exist, and neither works everywhere:

  • The gateway of a glci network. On Linux and the macOS VM backends that address is host-local, so it works from any bridge, including from inside a docker:dind service. On Docker Desktop's WSL2 backend, packets to it from another bridge are dropped, not refused. That is #179 (closed): a two-minute hang, then a clone error that says nothing about networking.
  • Docker's host-gateway sentinel. On Docker Desktop this resolves to the VM's host address and works from any network. On a native Linux daemon it resolves to docker0's 172.17.0.1. A docker:dind service uses that same address for its own bridge, so from inside DinD it is a local interface, and every docker login $CI_REGISTRY there is refused. The first version of this MR (and !198 (closed)) used the sentinel everywhere. The registry e2e suite caught this, and the new trace notice below correctly named the cause.

Separately, [network] host_gateway, documented as the escape hatch, was read by nothing but glci config --network.

How

  • Fix, decided per daemon (mockGatewayFor):
    • With host_gateway = "auto" (the default), Docker Desktop on WSL2 gets the sentinel. glci detects this from docker info: OperatingSystem "Docker Desktop" plus a WSL2 kernel.
    • Every other daemon gets the gateway of glci's persistent bus network, as before. It uses the bus network rather than the per-pipeline one because the shared runner's config outlives any one pipeline.
    • Podman takes the gateway path too (releases before 4.7 reject the sentinel), and so do Windows daemons.
    • host_gateway = "host-gateway" forces the sentinel. An IP pins the local address. Remote runners use "auto" for their own daemon.
  • [network] is real and global-only.
    • host_gateway is wired and validated: auto, the sentinel, or an IP.
    • [network.extra_hosts] entries reach job containers. Each is validated as name:address, Docker's space-separated aliases are allowed, and any alias that names the mock is dropped.
    • The whole section is stripped from project configs.
    • A value glci cannot resolve now refuses the run instead of silently falling back to defaults. [tls] cert_validity is the exception: it falls back with a warning, since a project can set it.
  • Diagnostics, so the failure explains itself:
    • glci doctor gains a Job network row. It tests the address jobs really get: the sentinel, a pinned IP, or the gateway of a second throwaway network reached from a first one. It separates a wrong address from a host firewall, and fails only on evidence it measured. --no-job-network opts out.
    • When a job fails and its log shows a connection failure that names the mock (clone, curl, helper or docker-login wording), glci appends a WARNING: glci: ... block to the job's trace. The block names the address and points at glci doctor and the troubleshooting entry. A failure before step_script that was retried successfully is not blamed.
  • Docs: troubleshooting, docker-network, config-files, commands, how-it-works, named-runners, embedded-registry, ARCHITECTURE, SKILL.md.

Not reproduced locally

The bug needs Docker Desktop's WSL2 backend, which I don't have. The fix targets the root cause the reporter's evidence shows (their /etc/hosts and docker network inspect output). The detection rule is unit-tested against the reporter's exact docker info values. The new diagnostics are there so that if anything else is wrong on that setup, the failure says so.

Tests

  • go build ./..., go vet ./... (including -tags e2e), and unit tests for pkg/daemon, pkg/glciconfig, pkg/termcolor and cmd/glci all pass.
  • New unit tests:
    • the per-daemon decision (isDockerDesktopWSL, mockGatewayFor, remoteHostGateway);
    • the probe's classification of every engine outcome, against a stub engine;
    • the trace watch: chunking, ANSI, retries, step_script clearing, races;
    • a runJob-level test that the notice reaches a failed job's stored log, and not passing or cancelled ones;
    • SplitExtraHost / extraHostProblem tables;
    • doctor modes, rows and hints;
    • PreparePipeline and resume refusing an unresolvable [network] value.
  • e2e (test-integration-docker):
    • TestDockerInfra_JobNetworkProbe covers both the sentinel and the network-gateway shapes, plus a negative twin.
    • TestDockerInfra_JobResolvesMockToTheChosenAddress asserts from inside a real job which address glci-mock resolves to: host-gateway on Docker Desktop WSL2, the bus gateway elsewhere, and never docker0.
  • The MR pipeline's integration suites cover the real paths. Before the per-daemon fix, the registry suite failed on docker login from DinD, and the new trace notice named the cause. With the fix, the suites pass.

Closes #179 (closed)

Edited by Georgi N. Georgiev | GitLab

Merge request reports

Loading
Loading