Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for custom registry prefixes at the configuration level #1928

Merged

Conversation

mdelapenya
Copy link
Collaborator

@mdelapenya mdelapenya commented Nov 28, 2023

What does this PR do?

This PR does two major things:

  1. It tries to simplify how the reaper is internally configured, and for that:
  • deprecates the reaper options defined in the container and network requests. This is needed because we do not want to configure the reaper per container, but instead, do that in one single place: the testcontainers configuration
  • moving the constant representing the Ryuk version to internal, as we do not want users to modify it but instead make it possible to define a custom prefix (see later)
  • removing ocurrences of the deprecated code at the test level, which they won't do anything to not collide with the new features.
  1. It adds support for configuring a Docker Hub prefix to be prepended to any Docker Hub image, with:
  • the TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX env var, or
  • the hub.image.name.prefix property

Testcontainers for Go will automatically apply the prefix to every image that it pulls from Docker Hub.

It will not apply the prefix to:

  • non-Hub image names (e.g. where another registry is set)
  • Docker Hub image names where the hub registry is explicitly part of the name (i.e. anything with a docker.io or registry.hub.docker.com host part)

The PR is adding a custom internal ImageSubstitutor, which is always appended to the user-defined image substitutor functions for a container request, so make sure it's always applied This substitutor will read the configuration to get the prefix, and will append it, when needed, to the image. Unit tests for it has been included.

The PR also improves the docs regarding image substitutors, listing all the images used in the tests.

Finally, the shell script to bump the reaper version has been updated, as the Go file for the Ryuk version has changed.

Why is it important?

First, alignment with the Java behavior. Second, create a consistent experience while pulling images from custom registries.

Related issues

@mdelapenya mdelapenya requested a review from a team as a code owner November 28, 2023 16:48
@mdelapenya mdelapenya added the feature New functionality or new behaviors on the existing one label Nov 28, 2023
@mdelapenya mdelapenya self-assigned this Nov 28, 2023
Copy link

netlify bot commented Nov 28, 2023

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 2dc912e
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/656619eae7f223000843c13a
😎 Deploy Preview https://deploy-preview-1928--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@eddumelendez eddumelendez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just left a comment that we can address later.

container, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: ContainerRequest{
Image: "alpine:latest",
ImageSubstitutors: []ImageSubstitutor{dockerImageSubstitutor{}},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this in a previous PR, but wonder in which uses cases do we need more than one substitute. If a substitute is added then the new image name should be pull from the registry, in this case, what happens when more than one is added. If it is not intended then should we deprecate it in a next PR and only accept one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmm I see your point, now with more perspective given the context from this PR. Yeah, makes sense. We just want one function plus the prefix prepender one, in the case it exists.

@mdelapenya mdelapenya merged commit 8fadbe0 into testcontainers:main Nov 28, 2023
112 checks passed
@mdelapenya mdelapenya deleted the image-substitutors-round-two branch November 29, 2023 06:18
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Nov 30, 2023
* main: (100 commits)
  fix: fallback matching of registry authentication config (testcontainers#1927)
  feat: support customizing the Docker build command (testcontainers#1931)
  docs: include MongoDB's username and password options into the docs (testcontainers#1930)
  feat: support for custom registry prefixes at the configuration level (testcontainers#1928)
  Add username and password functions to mongodb (testcontainers#1910)
  chore: skip TestContainerLogWithErrClosed as flaky on rootless docker (testcontainers#1925)
  docs: add some Vault module examples (testcontainers#1825)
  feat: support for executing commands in a container with user, workDir and env (testcontainers#1914)
  fix(modules.kafka): Switch to MaxInt for 32-bit support (testcontainers#1923)
  docs: fix code snippet for image substitution (testcontainers#1918)
  Add database driver note to SQL Wait strategy docs (testcontainers#1916)
  Reduce flakiness in ClickHouse tests (testcontainers#1902)
  lint: enable nonamedreturns (testcontainers#1909)
  chore: deprecate BindMount APIs (testcontainers#1907)
  fix(reaper): fix race condition when reusing reapers (testcontainers#1904)
  feat: Allow the container working directory to be specified (testcontainers#1899)
  chore: make rabbitmq examples more readable (testcontainers#1905)
  chore(deps): bump github.com/twmb/franz-go and github.com/twmb/franz-go/pkg/kadm in /modules/redpanda (testcontainers#1896)
  Fix - respect ContainerCustomizer in neo4j module (testcontainers#1903)
  chore(deps): bump github.com/nats-io/nkeys and github.com/nats-io/nats.go in /modules/nats (testcontainers#1897)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or new behaviors on the existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: ImageSubstitutor not applied to ryuk image
2 participants