Merged
Conversation
Builds upon #3021 and #3411: * adds a pluggable image substitution mechanism using ServiceLoader, enabling users to perform custom substitution/auditing of images being used by their tests * provides a default implementation that behaves similarly to legacy `TestcontainersConfiguration` approach (`testcontainers.properties`) Notes: * behaviour is similar but not quite identical to `TestcontainersConfiguration`: use of a configured custom image for, e.g. Kafka/Pulsar that does not have a tag specified causes the substitution to take effect for all usages. It seems very unlikely that people would be using a mix of the config file image overrides in some places _and_ specific images specified in code in others. * Duplication of default image names in modules vs `TestcontainersConfiguration` class is intentional: specifying image overrides in `testcontainers.properties` should be removed in the future. * ~Add log deprecation warnings when `testcontainers.properties` image overrides are used.~ Defer to a future release?
Builds upon #3021 and #3411: * adds a pluggable image substitution mechanism using ServiceLoader, enabling users to perform custom substitution/auditing of images being used by their tests * provides a default implementation that behaves similarly to legacy `TestcontainersConfiguration` approach (`testcontainers.properties`) Notes: * behaviour is similar but not quite identical to `TestcontainersConfiguration`: use of a configured custom image for, e.g. Kafka/Pulsar that does not have a tag specified causes the substitution to take effect for all usages. It seems very unlikely that people would be using a mix of the config file image overrides in some places _and_ specific images specified in code in others. * Duplication of default image names in modules vs `TestcontainersConfiguration` class is intentional: specifying image overrides in `testcontainers.properties` should be removed in the future. * ~Add log deprecation warnings when `testcontainers.properties` image overrides are used.~ Defer to a future release?
For many orgs, sticking a prefix on the front of image names might be enough to use a private registry. I've added a default behaviour whereby, if a particular environment variable is present, image names are automatically substituted. e.g. `TESTCONTAINERS_IMAGE_NAME_PREFIX=my.registry.com/` would transform `redis` to `my.registry.com/redis` etc.
Merged
Docs update required
rnorth
commented
Nov 8, 2020
Comment on lines
+48
to
+75
| ## Automatically modifying Docker Hub image names | ||
|
|
||
| Testcontainers can be configured to modify Docker Hub image names on the fly to apply a prefix string. | ||
|
|
||
| Consider this if: | ||
|
|
||
| * Developers and CI machines need to use different image names. For example, developers are able to pull images from Docker Hub, but CI machines need to pull from a private registry | ||
| * Your private registry has copies of images from Docker Hub where the names are predictable, and just adding a prefix is enough. | ||
| For example, `registry.mycompany.com/mirror/mysql:8.0.22` can be derived from the original Docker Hub image name (`mysql:8.0.22`) with a consistent prefix string: `registry.mycompany.com/mirror/` | ||
|
|
||
| In this case, image name references in code are **unchanged**. | ||
| i.e. you would leave as-is: | ||
|
|
||
| <!--codeinclude--> | ||
| [Unchanged direct Docker Hub image name](../examples/junit4/generic/src/test/java/generic/ImageNameSubstitutionTest.java) inside_block:directDockerHubReference | ||
| <!--/codeinclude--> | ||
|
|
||
| You can then configure Testcontainers to apply the prefix `registry.mycompany.com/mirror/` to every image that it tries to pull from Docker Hub. | ||
| This can be done in one of two ways: | ||
|
|
||
| * Setting environment variables `TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX=registry.mycompany.com/mirror/` | ||
| * Via config file, setting `hub.image.name.prefix` in either: | ||
| * the `~/.testcontainers.properties` file in your user home directory, or | ||
| * a file named `testcontainers.properties` on the classpath | ||
|
|
||
| Testcontainers will automatically apply the prefix to every image that it pulls from Docker Hub - please verify that all [the required images](./pull_rate_limiting.md#which-images-are-used-by-testcontainers) exist in your registry. | ||
|
|
||
| Testcontainers will not apply the prefix to non-Hub image names. |
Member
Author
There was a problem hiding this comment.
Testcontainers will not apply the prefix to non-Hub image names.
Judgement call required on this specific point!
Member
There was a problem hiding this comment.
Since the offender is Docker Hub with its rate limits, I would say let's focus on it first 👍
bsideup
reviewed
Nov 21, 2020
…tor' into default-prefixing-image-substitutor
|
Any chances this could be merged and released anytime soon ? |
bsideup
reviewed
Nov 30, 2020
core/src/main/java/org/testcontainers/utility/PrefixingImageNameSubstitutor.java
Outdated
Show resolved
Hide resolved
bsideup
reviewed
Nov 30, 2020
core/src/main/java/org/testcontainers/utility/PrefixingImageNameSubstitutor.java
Outdated
Show resolved
Hide resolved
bsideup
reviewed
Nov 30, 2020
core/src/main/java/org/testcontainers/utility/PrefixingImageNameSubstitutor.java
Outdated
Show resolved
Hide resolved
bsideup
reviewed
Nov 30, 2020
core/src/main/java/org/testcontainers/utility/PrefixingImageNameSubstitutor.java
Show resolved
Hide resolved
bsideup
reviewed
Nov 30, 2020
core/src/test/java/org/testcontainers/utility/PrefixingImageNameSubstitutorTest.java
Show resolved
Hide resolved
…meSubstitutor.java Co-authored-by: Sergei Egorov <[email protected]>
…t and -absent cases, the prefix is applied as-is)
bsideup
reviewed
Dec 8, 2020
Co-authored-by: Sergei Egorov <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #3411, #3021
Split out from #3021
For many orgs, sticking a prefix on the front of image names might be enough to use a private registry. I've added a default behaviour whereby, if a particular environment variable is present, image names are automatically substituted.