Add pluggable image name substitution

Open
#1,570 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
docker, typescript

Research direction

Start with packages/testcontainers/src/container-runtime/image-name.ts and trace how ImageName is built for Ryuk and SSHD. The issue leaves the scope of Compose images and Dockerfile FROM lines undecided, and depends on configuration work in #1569. Done means image pulls pass through the configured substitutor, with the existing prefix variable as the default.

Written by the indexing model from the issue text.

Description

enhancement minor

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

  • Blocked by #1569: the substitutor is registered through configuration.
Dominant language
TypeScript
Stars
2.7k
Forks
290
Avg merge
4d 1h
Merged PRs (30d)
22

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from testcontainers/testcontainers-node

All issues in testcontainers/testcontainers-node

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.