Skip to content

Add programmatic configuration #1569

Open

Description

@cristianrgreco

What happens

Configuration comes only from environment variables and .testcontainers.properties, and each setting is read where it is used. Fourteen variables are read through process.env across packages/testcontainers/src (Ryuk image, port, privileged, verbose and disabled flags, the SSHD image and port, the hub image prefix, reuse, Docker auth config and others), plus the Docker host settings in the strategy config.

  • Changing a setting from code means assigning to process.env before the first container starts.
  • Nothing is typed or validated. A misspelt variable is silently ignored.
  • There is no way to read the effective configuration.

Expected

A typed configuration object with one place that resolves it:

TestContainers.configure({
  ryuk: { disabled: false, privileged: true },
  hubImageNamePrefix: "registry.example.com/mirror",
  reuse: { enabled: true },
});
  • Environment variables and the properties file keep working, with a documented precedence.
  • TestContainers.getConfiguration() returns what is in effect.

Where

  • packages/testcontainers/src/container-runtime/strategies/utils/config.ts
  • the process.env reads in reaper/reaper.ts, port-forwarder/port-forwarder.ts, container-runtime/image-name.ts, generic-container/generic-container.ts and container-runtime/auth/
  • packages/testcontainers/src/test-containers.ts

Notes

  • Java centralises this in TestcontainersConfiguration.
  • Configuration must be set before the runtime client and Ryuk are created. Decide what happens when it is changed afterwards.

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