Skip to content

feat: Require explicit container image when creating container builder#1584

Merged
HofmeisterAn merged 35 commits intotestcontainers:developfrom
digital88:feat-1540
Dec 7, 2025
Merged

feat: Require explicit container image when creating container builder#1584
HofmeisterAn merged 35 commits intotestcontainers:developfrom
digital88:feat-1540

Conversation

@digital88
Copy link
Contributor

What does this PR do?

See #1540

Why is it important?

See #1540

@coderabbitai
Copy link

coderabbitai bot commented Nov 18, 2025

Important

Review skipped

More than 25% of the files skipped due to max files limit. The review is being skipped to prevent a low-quality review.

193 files out of 300 files are above the max files limit of 100. Please upgrade to Pro plan to get higher limits.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@netlify
Copy link

netlify bot commented Nov 18, 2025

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit 476780d
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-dotnet/deploys/6935949865c08d0008440b4d
😎 Deploy Preview https://deploy-preview-1584--testcontainers-dotnet.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 project configuration.

@digital88
Copy link
Contributor Author

Again random Elastic test failure. Need to merge #1593 first I think.

@digital88
Copy link
Contributor Author

Small overview:

Added two new constructors to each module. ctor(string) and ctor(IImage). They both call Init().WithImage() and pass the argument. Changed existing parameterless constructor to explicitly use old image like Init().WithImage(MODULE_DEFAULT_IMAGE). The old parameterless constructor is deprecated.

Added xml docs to point where image tags can be located, usually hub.docker.com.

Added same two new constructors and deprecated old constructor in ContainerBuilder. I changed almost all internal references to one of the new constuctors.

Added Dockerfile to each test project and wrote a new TestSession.GetImageFromDockerfile() helper. I tried to add latest version of every module in this Dockerfile.
Not all modules currently support latest versions of their images, so I had to put non-latest working image tag for some of them.

@digital88 digital88 marked this pull request as ready for review December 2, 2025 16:43
@HofmeisterAn
Copy link
Collaborator

Wow, this looks great! Thanks for your hard work. The only issue I noticed is with the xUnit.net module. It won't work anymore in the future. We probably need to use reflection here, even though I try to avoid it as much as possible. We need to think about whether there's another way. WDYT?

@digital88
Copy link
Contributor Author

digital88 commented Dec 3, 2025

The only issue I noticed is with the xUnit.net module.

Yes, this is valid problem, I think we need to make a new issue for it, and make a separate PR. We could for example pass a factory or "creator" delegate if reflection is not an option. Or maybe even use InternalsVisibleTo, and make constructor internal instead of public 😄

Copy link
Collaborator

@HofmeisterAn HofmeisterAn left a comment

Choose a reason for hiding this comment

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

As I mentioned, the PR looks pretty good. I just have a few small things we should address before merging. We also need to keep the docs in mind and update them afterward (having a branch ready for the release).

@digital88
Copy link
Contributor Author

Unrelated, but looks like Kafka tests also randomly fail. I already had this failure happen twice in this PR (for unrelated changes).

@HofmeisterAn
Copy link
Collaborator

Unrelated, but looks like Kafka tests also randomly fail. I already had this failure happen twice in this PR (for unrelated changes).

The best way is to test flaky modules in GH Codespaces with a script that runs the specific module tests indefinitely. I just took a quick look: the Kafka tests (seems to) finish in about a minute, but the overall test process doesn't exit and gets cancelled after five minutes.

@digital88
Copy link
Contributor Author

@HofmeisterAn
Does something else need to be done/fixed or we are good to merge this?

@HofmeisterAn HofmeisterAn changed the base branch from develop to main December 7, 2025 11:43
@HofmeisterAn HofmeisterAn changed the base branch from main to develop December 7, 2025 11:44
@digital88
Copy link
Contributor Author

digital88 commented Dec 7, 2025

My dockerfile parsing code in GetImageFromDockerfile() is very straightforward, so adding comments in first line(s) broke it :) Probably should ignore lines starting with #. I'll fix it.

@HofmeisterAn
Copy link
Collaborator

My dockerfile parsing code in GetImageFromDockerfile() is very straightforward, so adding comments in first line(s) broke it :) Probably should ignore lines starting with #. I'll fix it.

Ah, I just saw your comment, no worries. I've set the images in the Dockerfile to the versions used in the builder classes for now. We should update the images in a follow-up PR (65a2fc0). OK?

@digital88
Copy link
Contributor Author

My dockerfile parsing code in GetImageFromDockerfile() is very straightforward, so adding comments in first line(s) broke it :) Probably should ignore lines starting with #. I'll fix it.

Ah, I just saw your comment, no worries. I've set the images in the Dockerfile to the versions used in the builder classes for now. We should update the images in a follow-up PR (65a2fc0). OK?

Yes, but maybe let dependabot update them instead? :)

As a sidenote, while I was searching for latest images I encountered some obstacles such as:

  • Some non-docker hub registries is a pain to navigate and look up image tags. For example I couldn't figure IBM's icr and how to see available tags of Db2.
  • Some image vendors do not push LTS or even v{Major} tags. They may push current build tagged yyyy-mm-dd. Some even only push latest (Microsoft emulators)!
  • Even the vendors who push more or less semvered tags do not always list what is currently supported and/or LTS versions are. I need to guess or go to official docs site.
  • Some newer images do not work with our tests at all :) Kafka for example.

@HofmeisterAn
Copy link
Collaborator

I've reviewed everything and made a couple of small changes. LMKWYT. If you're okay with them, we can merge the PR.

Yes, but maybe let dependabot update them instead? :)

👍 Ideally, we can use Dependabot (for most of the images) and rely on its auto-update capabilities.

As a sidenote, while I was searching for latest images I encountered some obstacles such as:

Yeah, unfortunately there isn't much we can do here. There just aren't strict guidelines for images.

Some newer images do not work with our tests at all :) Kafka for example.

Yes, that's expected. It's one of the reasons we're doing this.

These are the follow-ups we should add as TODOs to the issue so we don't forget:

  • Prepare a draft PR to update the docs.
  • Prepare a draft PR to update the Testcontainers module catalog.
  • Update the examples after the 4.10.0 release.

Again, thanks for the work 💪!

@digital88
Copy link
Contributor Author

LMKWYT. If you're okay with them, we can merge the PR.

I think it's ready for merge. 👍

@HofmeisterAn HofmeisterAn changed the title (feat): Force user provided image name/tag when creating Builder #1540 feat: Require explicit container image when creating container builder Dec 7, 2025
@HofmeisterAn HofmeisterAn added the enhancement New feature or request label Dec 7, 2025
@HofmeisterAn HofmeisterAn merged commit d2318d1 into testcontainers:develop Dec 7, 2025
79 checks passed
0xced added a commit to 0xced/testcontainers-dotnet that referenced this pull request Dec 30, 2025
Follow-up to testcontainers#1584

When the parameterless constructors are actually removed
1. Remove the `new()` constraint on ContainerLifetime, ContainerFixture, ContainerTest, DbContainerFixture and DbContainerTest
2. Make ContainerFixture abstract
3. Change `protected virtual TBuilderEntity Configure() => new();` to `protected abstract TBuilderEntity Configure();` on ContainerLifetime
4. Delete the obsolete methods: `protected virtual TBuilderEntity Configure(TBuilderEntity builder)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants