Skip to content

Honor file OutputPath and LocalImageName/LocalImageTag for Dockerfile image archives - #22685

Draft
Eric Erhardt (eerhardt) wants to merge 1 commit into
mainfrom
eerhardt-fix-dockerfile-image-archive-paths
Draft

Eric Erhardt (eerhardt) wants to merge 1 commit into
mainfrom
eerhardt-fix-dockerfile-image-archive-paths

Conversation

@eerhardt

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: efac9c43ea3808c1ad19a836e51b9387c4bdb079

Dimension Assessment Rationale
Change confidence 8/10 ↑ New unit tests cover file vs directory OutputPath, overridden vs default name/tag, and ContainerImageReference matching 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.
Diagnosis confidence 9/10 ↑ Code trace confirms all three problems: GetContainerImageArchivePath always appended a file name, the Dockerfile path used TryGetContainerImageName instead of the build options, and ContainerImageReference used different defaults.
Evidence fit 8.5/10 ↑ The hashed <name>-<hex>.tar file name and the ignored latest tag 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. OutputPath can name the archive file. ResourceExtensions.GetContainerImageArchivePath now 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 and ContainerImageReference all go through this helper. The image manager now creates the archive's parent directory instead of turning Images/worker.tar into a directory. A directory OutputPath still receives <name>-<tag>.tar.

2. LocalImageName/LocalImageTag are honored for archive builds. When OutputPath is 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. ContainerImageReference reports the written path. The default WithDockerfile/WithDockerfileFactory build-options callback now reports the image the build actually tags (taken from TryGetContainerImageName). Previously, after WithImage, it reported the resource name and latest. The image manager and ContainerImageReference now share one default for the name and tag (GetLocalImageNameAndTag). Image references are split on the last : after the last /, so a registry port such as localhost:5000/app is no longer mistaken for a tag.

Docs: updated ContainerBuildOptionsCallbackContext.OutputPath/LocalImageName/LocalImageTag remarks and the Aspire.Hosting.Dotnet README 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.
  • Full 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).
  • Full Aspire.Hosting.Docker.Tests: 161 passed, 2 failed (WSLc doesn't support Compose locally).

Fixes #22683

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

… 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]>
@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/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 22685

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 22685"

@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot November 26, 2026 00:39
@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

52 / 101 PR test projects · 4 PR jobs, from 8 changed files.

Selected PR test projects (52 / 101)

Aspire.Cli.EndToEnd.Tests, Aspire.Hosting.Analyzers.Tests, Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Kusto.Tests, Aspire.Hosting.Azure.Provisioning.Tests, Aspire.Hosting.Azure.Tests, Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Browsers.Tests, Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Containers.Tests, Aspire.Hosting.DevTunnels.Tests, Aspire.Hosting.Docker.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.EntityFrameworkCore.Tests, Aspire.Hosting.Foundry.Tests, Aspire.Hosting.Garnet.Tests, Aspire.Hosting.Go.Tests, Aspire.Hosting.Java.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Kafka.Tests, Aspire.Hosting.Keycloak.Tests, Aspire.Hosting.Kubernetes.Tests, Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests, Aspire.Hosting.MongoDB.Tests, Aspire.Hosting.MySql.Tests, Aspire.Hosting.Nats.Tests, Aspire.Hosting.OpenAI.Tests, Aspire.Hosting.Oracle.Tests, Aspire.Hosting.Orleans.Tests, Aspire.Hosting.PostgreSQL.Tests, Aspire.Hosting.Python.Tests, Aspire.Hosting.Qdrant.Tests, Aspire.Hosting.RabbitMQ.Tests, Aspire.Hosting.Radius.Tests, Aspire.Hosting.Redis.Tests, Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Rust.Tests, Aspire.Hosting.Seq.Tests, Aspire.Hosting.SqlServer.Tests, Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Hosting.Valkey.Tests, Aspire.Hosting.Yarp.Tests, Aspire.Playground.Tests, Aspire.Templates.Tests

Selected PR jobs (4)

cli-starter-validation, extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

⚠️ 46 of the 52 selected test projects come from a single change — src/Aspire.Hosting/ApplicationModel/ContainerBuildOptionsCallbackAnnotation.cs.

🔧 src/Aspire.Hosting/ApplicationModel/ContainerBuildOptionsCallbackAnnotation.cs (changed source)
→ 46 via the project graph

show 46

Aspire.Hosting.Analyzers.Tests (2 hops), Aspire.Hosting.Azure.EntraId.Tests (2 hops), Aspire.Hosting.Azure.Kubernetes.Tests (2 hops), Aspire.Hosting.Azure.Kusto.Tests (2 hops), Aspire.Hosting.Azure.Provisioning.Tests (3 hops), Aspire.Hosting.Azure.Tests, Aspire.Hosting.Browsers.Tests (2 hops), Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Containers.Tests (2 hops), Aspire.Hosting.DevTunnels.Tests (2 hops), Aspire.Hosting.Docker.Tests (2 hops), Aspire.Hosting.DotnetTool.Tests (2 hops), Aspire.Hosting.EntityFrameworkCore.Tests (2 hops), Aspire.Hosting.Foundry.Tests (2 hops), Aspire.Hosting.Garnet.Tests (2 hops), Aspire.Hosting.Go.Tests (2 hops), Aspire.Hosting.Java.Tests (2 hops), Aspire.Hosting.JavaScript.Tests (2 hops), Aspire.Hosting.Kafka.Tests (2 hops), Aspire.Hosting.Keycloak.Tests (2 hops), Aspire.Hosting.Kubernetes.Tests (2 hops), Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests (2 hops), Aspire.Hosting.MongoDB.Tests (2 hops), Aspire.Hosting.MySql.Tests (2 hops), Aspire.Hosting.Nats.Tests (2 hops), Aspire.Hosting.OpenAI.Tests (2 hops), Aspire.Hosting.Oracle.Tests (2 hops), Aspire.Hosting.Orleans.Tests (2 hops), Aspire.Hosting.PostgreSQL.Tests (2 hops), Aspire.Hosting.Python.Tests (2 hops), Aspire.Hosting.Qdrant.Tests (2 hops), Aspire.Hosting.RabbitMQ.Tests (2 hops), Aspire.Hosting.Redis.Tests (2 hops), Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Rust.Tests (2 hops), Aspire.Hosting.Seq.Tests (2 hops), Aspire.Hosting.SqlServer.Tests (2 hops), Aspire.Hosting.Testing.Tests (2 hops), Aspire.Hosting.Valkey.Tests (2 hops), Aspire.Hosting.Yarp.Tests (2 hops), Aspire.Playground.Tests

🧪 tests/Aspire.Hosting.Tests/Publishing/DockerContainerRuntimeTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests
→ 3 via the project graph: Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.Radius.Tests

📦 affected project Aspire.Hosting.Dotnet
→ 2 tests: Aspire.Cli.EndToEnd.Tests, Aspire.Templates.Tests

📦 affected project Aspire.Hosting
→ 1 test: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Hosting.Tests/Publishing/PodmanSaveArgumentsTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

🧪 tests/Aspire.Hosting.Tests/Publishing/ResourceContainerImageManagerTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

Job reasons

Job Triggered by
cli-starter-validation affected project Aspire.Hosting.PostgreSQL
extension-e2e • src/Aspire.Hosting/ApplicationModel/ContainerBuildOptionsCallbackAnnotation.cs, src/Aspire.Hosting/ApplicationModel/ContainerImageReference.cs, src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs, src/Aspire.Hosting/ContainerResourceBuilderExtensions.cs, src/Aspire.Hosting/Publishing/ResourceContainerImageManager.cs
• affected project Aspire.Hosting
polyglot • affected project Aspire.Hosting
• affected project Aspire.Hosting.Azure.Provisioning
typescript-api-compat affected project Aspire.Hosting

Selection computed for commit efac9c4.

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.

🟡 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

Comment on lines +1479 to +1482
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");
Comment on lines +412 to +413
imageName = options.LocalImageName;
imageTag = options.LocalImageTag;
@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dockerfile image archives ignore file OutputPath and LocalImageName/LocalImageTag, and ContainerImageReference reports the wrong path

2 participants