Skip to content

Add pluggable image name substitution #1570

Open

Description

@cristianrgreco

What happens

The only way to redirect image pulls is TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX, which prefixes Docker Hub image names. It cannot:

  • map other registries (ghcr.io, quay.io, mcr.microsoft.com) to a mirror
  • apply different rules to different images
  • rewrite a tag or a digest

Organisations that mirror everything through an internal registry end up editing image names in every test.

Expected

A function that every image name passes through before it is pulled, registered in configuration:

TestContainers.configure({
  imageNameSubstitutor: (image) => (image.registry === "ghcr.io" ? image.withRegistry("mirror.example.com/ghcr") : image),
});

The existing prefix variable becomes the default substitutor.

Where

  • packages/testcontainers/src/container-runtime/image-name.ts
  • the places that build ImageName for Ryuk and SSHD

Notes

  • Java has a pluggable ImageNameSubstitutor, with PrefixingImageNameSubstitutor as the built-in equivalent of the prefix variable. Go has WithImageSubstitutors.
  • Decide whether images named in Compose files and Dockerfile FROM lines are in scope.

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