Repository navigation
Honor file OutputPath and LocalImageName/LocalImageTag for Dockerfile image archives - #22685
Eric Erhardt (eerhardt) wants to merge 1 commit into
Conversation
… image archives Dockerfile archive builds now treat an OutputPath with a file extension as the archive file, use LocalImageName/LocalImageTag for --tag, the archive file name and the archive's image reference, and ContainerImageReference reports the archive path the runtime actually writes. Fixes #22683 Co-authored-by: Copilot App <[email protected]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 22685Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 22685" |
Tests selector52 / 101 PR test projects · 4 PR jobs, from 8 changed files. Selected PR test projects (52 / 101)
Selected PR jobs (4)
How these were chosen — grouped by what changed
🔧 show 46
🧪 📦 affected project 📦 affected project 🧪 🧪 Job reasons
Selection computed for commit |
There was a problem hiding this comment.
🟡 Changes recommended
Dockerfile archive builds can discard the existing image name and tag, while registry-port parsing and real-archive identity overrides lack regression coverage.
3 open issues
What changed in this PR
This PR aligns Dockerfile image archives with Aspire’s explicit output-file handling, addressing #22683 and extending the archive consistency work from #22666.
Changes:
- Honors explicit archive filenames while preserving directory-based output.
- Applies local image name/tag overrides to archive builds without changing runtime-loaded image identities.
- Shares image defaults and path resolution with
ContainerImageReference, with updated documentation and regression tests.
| File | Description |
|---|---|
| tests/Aspire.Hosting.Tests/Publishing/ResourceContainerImageManagerTests.cs | Tests archive paths, image overrides, and default identities. |
| tests/Aspire.Hosting.Tests/Publishing/PodmanSaveArgumentsTests.cs | Checks explicit archive filenames in Podman save arguments. |
| tests/Aspire.Hosting.Tests/Publishing/DockerContainerRuntimeTests.cs | Checks explicit archive filenames in Docker build arguments. |
| src/Aspire.Hosting/Publishing/ResourceContainerImageManager.cs | Applies archive image overrides and creates parent directories. |
| src/Aspire.Hosting/ContainerResourceBuilderExtensions.cs | Derives Dockerfile defaults from the resource’s image identity. |
| src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs | Shares archive path, image parsing, and default-resolution helpers. |
| src/Aspire.Hosting/ApplicationModel/ContainerImageReference.cs | Uses shared defaults to report archive paths consistently. |
| src/Aspire.Hosting/ApplicationModel/ContainerBuildOptionsCallbackAnnotation.cs | Documents output-path and Dockerfile image-override behavior. |
| src/Aspire.Hosting.Dotnet/README.md | Clarifies Dockerfile archive filename conventions. |
Review effort: Balanced
| var tagSeparator = imageReference.LastIndexOf(':'); | ||
| return tagSeparator > imageReference.LastIndexOf('/') | ||
| ? (imageReference[..tagSeparator], imageReference[(tagSeparator + 1)..]) | ||
| : (imageReference, null); |
| [Experimental("ASPIREPIPELINES003", UrlFormat = "https://aka.ms/aspire/diagnostics/{0}")] | ||
| internal static (string ImageName, string ImageTag) GetLocalImageNameAndTag(this ContainerBuildOptionsCallbackContext context) | ||
| { | ||
| return (context.LocalImageName ?? context.Resource.Name.ToLowerInvariant(), context.LocalImageTag ?? "latest"); |
| imageName = options.LocalImageName; | ||
| imageTag = options.LocalImageTag; |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |

Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
efac9c43ea3808c1ad19a836e51b9387c4bdb079OutputPath, overridden vs default name/tag, andContainerImageReferencematching the runtime path for Docker and Podman.↑ Affected test classes pass (305/307). The 2 failures are
RequiresFeature(ContainerRuntime)tests that also fail on baseline because WSLc is the only local runtime.↓ No real Docker/Podman archive build was run locally (Docker daemon unavailable).
↓ CI not yet inspected.
GetContainerImageArchivePathalways appended a file name, the Dockerfile path usedTryGetContainerImageNameinstead of the build options, andContainerImageReferenceused different defaults.<name>-<hex>.tarfile name and the ignoredlatesttag reported in the issue match the traced code.↓ The issue has no runtime repro; this is from code reading.
Description
Dockerfile-based image archives didn't follow the container build options the way .NET programs do after #22666.
1.
OutputPathcan name the archive file.ResourceExtensions.GetContainerImageArchivePathnow follows the .NET program rule (DotnetProgramPublishing.IsExplicitArchiveOutputPath): a path with a file extension that isn't an existing directory is the archive itself. The Docker (buildx --output,image save) and Podman (save) runtimes andContainerImageReferenceall go through this helper. The image manager now creates the archive's parent directory instead of turningImages/worker.tarinto a directory. A directoryOutputPathstill receives<name>-<tag>.tar.2.
LocalImageName/LocalImageTagare honored for archive builds. WhenOutputPathis set, these drive--tag, the archive file name and the archive's OCI ref. Builds that load the image into the runtime keep the resource's container image name, because push, local registry tagging and deployment targets look the image up by that name.3.
ContainerImageReferencereports the written path. The defaultWithDockerfile/WithDockerfileFactorybuild-options callback now reports the image the build actually tags (taken fromTryGetContainerImageName). Previously, afterWithImage, it reported the resource name andlatest. The image manager andContainerImageReferencenow share one default for the name and tag (GetLocalImageNameAndTag). Image references are split on the last:after the last/, so a registry port such aslocalhost:5000/appis no longer mistaken for a tag.Docs: updated
ContainerBuildOptionsCallbackContext.OutputPath/LocalImageName/LocalImageTagremarks and theAspire.Hosting.DotnetREADME archive section.Validation:
dotnet test --project tests\Aspire.Hosting.Tests\Aspire.Hosting.Tests.csproj --no-launch-profile -- --filter-class "*.ResourceContainerImageBuilderTests" --filter-class "*.DockerContainerRuntimeTests" --filter-class "*.PodmanSaveArgumentsTests" --filter-class "*.DotnetProgramArchiveTests" --filter-class "*.DotnetProgramPublishingTests" --filter-class "*.WslcContainerRuntimeTests" --filter-class "*.DistributedApplicationPipelineTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true": 305 passed, 2 failed. Both failures (CanBuildImageFromDockerfileResource_WithCustomOutputPath,_WithAllOptionsSet) also fail on baseline: they need a real Docker/Podman runtime, and only WSLc is available locally.Aspire.Hosting.Tests(excluding quarantined and outerloop): 3824 passed, 26 failed. All 26 failures are unrelated to this change (MSBuildTests temp-workspace file locks, git-worktree output policy, backchannel).Aspire.Hosting.Docker.Tests: 161 passed, 2 failed (WSLc doesn't support Compose locally).Fixes #22683
Checklist
<remarks />and<code />elements on your triple slash comments?