Problem
encore test spawns Postgres containers via docker run -d -p 5432 with no --network flag, so they always land on Docker's default bridge network.
In Google Cloud Build, build steps run on the cloudbuild Docker network. The test container and the Postgres container end up on different networks, making 127.0.0.1:<mapped-port> unreachable:
failed to start cluster: database did not come up: failed to connect to
`user=postgres database=postgres`:
127.0.0.1:32768 (127.0.0.1): dial error: timeout: context deadline exceeded
This affects any CI system that runs build steps on a non-default Docker network (Cloud Build, some GitLab CI runners, Drone, etc.).
Proposed solution
Read an environment variable (e.g. ENCORE_DOCKER_NETWORK) in CreateCluster and pass --network to the docker run invocation when set.
Rough sketch in cli/daemon/sqldb/docker/docker.go:
if net := os.Getenv("ENCORE_DOCKER_NETWORK"); net != "" {
args = append(args, "--network", net)
}
Usage in Cloud Build:
- id: test
name: my-builder-image
env:
- ENCORE_DOCKER_NETWORK=cloudbuild
args: [-c, encore test ./...]
Workarounds
The only current workaround is polling docker ps and running docker network connect cloudbuild <container> after Encore spawns the Postgres container, which is fragile and race-prone.
Problem
encore testspawns Postgres containers viadocker run -d -p 5432with no--networkflag, so they always land on Docker's default bridge network.In Google Cloud Build, build steps run on the
cloudbuildDocker network. The test container and the Postgres container end up on different networks, making127.0.0.1:<mapped-port>unreachable:This affects any CI system that runs build steps on a non-default Docker network (Cloud Build, some GitLab CI runners, Drone, etc.).
Proposed solution
Read an environment variable (e.g.
ENCORE_DOCKER_NETWORK) inCreateClusterand pass--networkto thedocker runinvocation when set.Rough sketch in
cli/daemon/sqldb/docker/docker.go:Usage in Cloud Build:
Workarounds
The only current workaround is polling
docker psand runningdocker network connect cloudbuild <container>after Encore spawns the Postgres container, which is fragile and race-prone.