Skip to content

Provide in-network connection details from modules #1567

Open

Description

@cristianrgreco

What happens

Module getters return the address as seen from the test process: the Docker host and a mapped port. A second container on the same Docker network needs a different address, the first container's network alias and its internal port, and no module provides it.

const db = await new PostgreSqlContainer(image).withNetwork(network).withNetworkAliases("db").start();

db.getConnectionUri(); // postgres://test:test@localhost:55012/test, no use to another container

const app = await new GenericContainer(appImage)
  .withNetwork(network)
  .withEnvironment({ DATABASE_URL: "postgres://test:test@db:5432/test" }) // assembled by hand
  .start();

The module knows the internal port, the credentials and the database name. The user has to repeat all of them, and keep them in step with the module's defaults.

Expected

Each module can produce its connection details for use inside a network:

db.getConnectionUri({ network }); // postgres://test:test@db:5432/test

A started container can report its aliases on a network, which this needs.

Where

  • packages/testcontainers/src/test-container.ts and started-generic-container.ts, for the aliases
  • the connection getters in packages/modules/*/src

Notes

  • Kafka and Redpanda already have to deal with in-network listeners. Their approach is a starting point.
  • The naming should follow whatever the modules converge on for connection getters.

Dependencies

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestminorBackward compatible functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions