Skip to content

Support configurable Docker network for test databases (ENCORE_DOCKER_NETWORK) #2382

Description

@odsod

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions