Skip to content

Route direct Testcontainers usage through the custom Docker Hub proxy - #1605

Merged
afscrome merged 1 commit into
mainfrom
afscrome-testcontainers-docker-proxy
Sep 22, 2026
Merged

afscrome merged 1 commit into
mainfrom
afscrome-testcontainers-docker-proxy

Conversation

@afscrome

Copy link
Copy Markdown
Contributor

Summary

Some test fixtures create containers directly via DotNet.Testcontainers (bypassing Aspire's container resource model), so they weren't covered by the existing CUSTOM_CONTAINER_REGISTRY rate-limit mitigation that AspireIntegrationTestFixture applies to Aspire-hosted resources.

Changes

  • Added TestContainerRegistry.Resolve(string registry) to CommunityToolkit.Aspire.Testing. It swaps the registry to the value of the CUSTOM_CONTAINER_REGISTRY environment variable, but only when the input registry is the default Docker Hub (docker.io) registry — otherwise it returns the registry unchanged.
  • Applied TestContainerRegistry.Resolve(...) when constructing the image reference in every fixture that builds a Testcontainers container directly:
    • CommunityToolkit.Aspire.OllamaSharp.Tests
    • CommunityToolkit.Aspire.Meilisearch.Tests
    • CommunityToolkit.Aspire.SurrealDb.Tests
    • CommunityToolkit.Aspire.GoFeatureFlag.Tests
    • CommunityToolkit.Aspire.KurrentDB.Tests
    • CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests

The last two (KurrentDB, SqlServer) already pull from non-Docker-Hub registries, so this is a no-op for them today but future-proofs them if that ever changes.

Why not a generic .WithContainerRegistryMirror() builder extension?

I considered a fluent extension method on Testcontainers' IContainerBuilder<> (mirroring Aspire's own WithImageRegistry), but it isn't feasible generically: the builder interface only exposes WithImage(string)/WithImage(IImage) with no public getter for the image/registry already configured on a builder. Without being able to read back the existing image/repository/tag, an extension can't isolate and rewrite just the registry portion. A static helper used when building the image string is the simplest approach that still works uniformly across all fixtures.

Testing

Built each modified test project (dotnet build) — all succeed with no new warnings/errors.

Test fixtures that create containers directly via DotNet.Testcontainers
(bypassing Aspire's container resource model) were still pulling images
straight from their configured registry, so they weren't protected by
the existing CUSTOM_CONTAINER_REGISTRY rate-limit mitigation used for
Aspire-hosted resources.

A generic '.WithContainerRegistryMirror()' builder extension isn't
possible here: Testcontainers' fluent builder interface only exposes
'WithImage(string)', with no public getter for the image/registry
already configured on a builder, so an extension method can't rewrite
just the registry portion of an already-set image. Add a
TestContainerRegistry.Resolve(string registry) helper to
CommunityToolkit.Aspire.Testing instead, and use it when constructing
the image string in every fixture that builds a Testcontainers image
directly (Ollama, Meilisearch, SurrealDb, GoFeatureFlag, KurrentDB,
SqlServer). The helper only swaps the registry when it's the default
docker.io Docker Hub, so it's a no-op for the fixtures already using a
different registry (SqlServer, KurrentDB) while still future-proofing
them if that ever changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@afscrome
afscrome requested a review from Odonno as a code owner September 22, 2026 16:44
Copilot AI lite review requested due to automatic review settings September 22, 2026 16:44
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/CommunityToolkit/Aspire/main/eng/scripts/dogfood-pr.sh | bash -s -- 1605

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/CommunityToolkit/Aspire/main/eng/scripts/dogfood-pr.ps1) } 1605"

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Configure the Testcontainers Ryuk image for the mirror and add resolver test coverage.

Review effort: Lite
Findings: None

What changed in this PR

Routes direct Testcontainers image pulls through CUSTOM_CONTAINER_REGISTRY for Docker Hub images while preserving other registries.

Changes:

  • Added TestContainerRegistry.Resolve.
  • Applied it across six direct Testcontainers fixtures.
File Summary
tests/​CommunityToolkit.Aspire.Testing/​TestContainerRegistry.cs Adds shared registry resolution.
tests/​CommunityToolkit.Aspire.SurrealDb.Tests/​SurrealDbContainerFixture.cs Resolves the container image registry.
tests/​CommunityToolkit.Aspire.OllamaSharp.Tests/​OllamaContainerFeature.cs Resolves the container image registry.
tests/​CommunityToolkit.Aspire.Meilisearch.Tests/​MeilisearchContainerFixture.cs Resolves the container image registry.
tests/​CommunityToolkit.Aspire.KurrentDB.Tests/​KurrentDBContainerFixture.cs Applies registry resolution to image construction.
tests/​CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/​SqlServerContainerFixture.cs Applies registry resolution to image construction.
tests/​CommunityToolkit.Aspire.GoFeatureFlag.Tests/​GoFeatureFlagContainerFixture.cs Resolves the container image registry.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Odonno Odonno left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@afscrome

Copy link
Copy Markdown
Contributor Author

re Copilot comment Ryuk image is used by test containers to cleanup images. The agent will be blown away in CI, so not a problem.

Test failure due to microsoft/aspire#20316

@afscrome
afscrome merged commit 9ca61e4 into main Sep 22, 2026
154 of 155 checks passed
@afscrome
afscrome deleted the afscrome-testcontainers-docker-proxy branch September 22, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants