Add container registry mirror support for image builds#14128
Add container registry mirror support for image builds#14128bbartels wants to merge 6 commits intodotnet:mainfrom
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14128Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 14128" |
There was a problem hiding this comment.
Pull request overview
This pull request adds opt-in container registry mirror support for Aspire container image builds. When configured via WithContainerRegistryMirror, Aspire generates a temporary MSBuild .targets file that rewrites the ContainerBaseImage property during dotnet publish to replace source registries (e.g., mcr.microsoft.com) with mirror registries (e.g., internal Artifactory or ACR pull-through caches). This enables enterprise environments to use internal registry mirrors without modifying project files.
Changes:
- Added public API (
ContainerRegistryMirrorOptions,WithContainerRegistryMirror,WithContainerRegistryMirrors) for configuring registry mirrors - Modified
ResourceContainerImageManagerto inject MSBuild targets file viaCustomAfterMicrosoftCommonTargetsproperty - Added MSBuild-based test that validates registry rewriting without requiring Docker
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| src/Aspire.Hosting/Publishing/ContainerRegistryMirror.cs | Defines the public API for configuring container registry mirrors with options class and extension methods |
| src/Aspire.Hosting/Publishing/ResourceContainerImageManager.cs | Implements the registry mirror injection logic by generating and injecting temporary MSBuild targets files during container builds |
| tests/Aspire.Hosting.Tests/Publishing/ContainerRegistryMirrorMsBuildTests.cs | Adds integration test that validates the MSBuild targets file correctly rewrites ContainerBaseImage property |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/Aspire.Hosting.Tests/Publishing/ContainerRegistryMirrorMsBuildTests.cs
Show resolved
Hide resolved
tests/Aspire.Hosting.Tests/Publishing/ContainerRegistryMirrorMsBuildTests.cs
Show resolved
Hide resolved
|
@copilot review the new changes please |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/Aspire.Hosting.Tests/Publishing/ContainerRegistryMirrorMsBuildTests.cs
Show resolved
Hide resolved
tests/Aspire.Hosting.Tests/Publishing/ContainerRegistryMirrorMsBuildTests.cs
Outdated
Show resolved
Hide resolved
tests/Aspire.Hosting.Tests/Publishing/ContainerRegistryMirrorMsBuildTests.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Is this a .NET specific feature? |
Yes, this is to make |
|
Though, the concept could be expanded for other languages. Not entirely sure how/what images they are pulling. I can have a look |
| serviceProvider, | ||
| Options.Create(mirrorOptions))) | ||
| { | ||
| var method = typeof(ResourceContainerImageManager).GetMethod( |
Description
Adds opt-in container registry mirror support for Aspire container image builds, helpful for airgapped deployments. When configured, Aspire injects a temporary MSBuild
.targetsfile intodotnet publish(viaCustomAfterMicrosoftCommonTargets) that rewrites the computedContainerBaseImageregistry from a source registry (e.g.,mcr.microsoft.com) to a mirror registry (e.g., an internal Artifactory/ACR pull-through cache). This enables enterprise/proxied base-image pulls without changing project files or Dockerfiles.Also adds an MSBuild-level test that creates a temporary project, runs
dotnet msbuild, and asserts the injected targets file rewrites theContainerBaseImageproperty as expected (no Docker required).Fixes # (issue)
Dependencies: none.
Checklist
<remarks />and<code />elements on your triple slash comments?doc-ideatemplatebreaking-changetemplatediagnostictemplate