Repository navigation
Make layered .NET container archives match SDK archive output - #22666
Conversation
PublishWithContainerFiles archives now support OCI on Docker 25+, use the SDK's <name>.tar.gz directory naming, and are written as uncompressed tar like the SDK. Fixes #22591 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 22666Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 22666" |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
Archive output path classification differs from the SDK for existing dotted directories, causing non-layered publishing to fail and requiring aligned logic and regression coverage.
1 open issue
What changed in this PR
This PR aligns layered .NET container archives with SDK output so adding PublishWithContainerFiles does not change archive naming or compression. It also enables layered OCI archive export on Docker Engine 25+.
Changes:
- Replace Docker’s OCI rejection with validation of the saved archive’s OCI layout.
- Share SDK-style archive path resolution and remove extension-based gzip compression.
- Update regression tests and document archive behavior.
| File | Description |
|---|---|
tests/Aspire.Hosting.Tests/Publishing/ResourceContainerImageManagerTests.cs |
Update uncompressed archive assertions and publish-failure test naming. |
tests/Aspire.Hosting.Tests/Publishing/DotnetProgramArchiveTests.cs |
Cover SDK-style paths, uncompressed output, and OCI tag preservation. |
tests/Aspire.Hosting.Tests/Publishing/DockerContainerRuntimeTests.cs |
Cover OCI save support and missing-layout failures. |
src/Aspire.Hosting/Publishing/DockerContainerRuntime.cs |
Allow OCI saves and validate layout metadata. |
src/Aspire.Hosting/ApplicationModel/DotnetProgramPublishing.cs |
Centralize archive paths and remove outer gzip compression. |
src/Aspire.Hosting/ApplicationModel/ContainerImageReference.cs |
Resolve .NET archive references using the shared path helper. |
src/Aspire.Hosting.Dotnet/README.md |
Document Docker requirements, naming, and compression behavior. |
Review effort: Balanced
|
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. |
…r-archive-oci-naming
…sions Aspire now resolves a directory OutputPath to <flattened-image-name>.tar and passes the SDK an explicit archive file, so SDK-only and layered publishing write the same file regardless of the SDK's own path rules. Existing directories stay directories. Explicit .gz/.tgz archive names log a warning because the archive is an uncompressed tar. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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 |
|
I’d love to sync some of this with DCP. I added an image layer concept there a while back, with the idea that we might want to treat layers as first class parts of the API, but never got around to adding it in Aspire outside of some experiments due to concerns with how some usage of layers could interact with mounts. |
|
/backport to release/17.0 |

Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
96ce2c5ce4db24b50c07ef63680485a7fc2db6be↑ Real Docker 29.9.3
docker image saveoutput containsoci-layoutandindex.json.↓ On this revision, 7 real-container tests (
AddDotnetProject_SdkContainerArchiveRunsPublishedProgram,FileBasedAppWithContainerFilesPreservesLocalImageAndBuildsArchive, two Dockerfile builds) could not run locally because Docker was stopped; they passed on the previous revision and need CI to confirm.↓ No end-to-end
aspire do build-serverrun against real Docker or Podman.↓ Classic Docker image store verified only by reading moby's
save.go.<name>-<tag>.tarnaming, and extension-based gzip inPublishArchiveAsync.↑ SDK behavior confirmed in
ArchiveFileRegistryandContainerArchive.↓ The reporter's AppHost was not reproduced end-to-end.
Description
Adding
PublishWithContainerFilesto a .NET project that publishes to an archive (ContainerImageDestination.Archive) changed the archive compared to the same project without container files. Code that consumes the archive couldn't treat both cases the same way.Without container files, the .NET SDK writes the archive itself. With container files, Aspire builds the SDK image into the local runtime, layers the files on with a generated Dockerfile, exports it with
docker image save/podman save, and copies the result toOutputPath. That second path had its own rules:ImageFormat = Ocion DockerOutputPath<name>-<tag>.tar(the SDK wrote<name>.tar.gz)<name>.tarfor both pathsOutputPathending in.gz/.tgzChanges
docker image savewrites an OCI image layout (oci-layout,index.json,blobs/) alongside the Dockermanifest.json, with either image store and no configuration. The up-front rejection is removed. After saving an OCI-format layered archive, Aspire checks foroci-layoutandindex.jsonand fails with a clear "requires Docker Engine 25 or later" message if they're missing.DotnetProgramPublishing.GetArchiveOutputPathand passes the SDK an explicitContainerArchiveOutputPathfile. A path with an extension is a file. A path without one, ending in a directory separator, or naming an existing directory is a directory and gets<flattened-image-name>.tar; for example,team/programbecomesteam-program.tar. The SDK-only path, the layering path, andContainerImageReferenceall use this one rule. That avoids the SDK's misleading<repository>.tar.gzdefault (dotnet/sdk-container-builds#518) and its failure on existing dotted directories. It also fixesContainerImageReferencefor .NET projects without container files, which used to return<name>-<tag>.tar, a file the SDK never wrote.PublishArchiveAsyncno longer gzips based on the extension. The SDK always writes an uncompressed outer tar (its layers are gzipped inside), and OCI-layout consumers such asoras cp --from-oci-layoutanddocker loadexpect a plain tar. An explicit.gz/.tgzfile name now logs a warning that the archive is an uncompressed tar.src/Aspire.Hosting.Dotnet/README.mdis updated.User-facing usage
From the issue; this now works on Docker and writes
images/server.tarwhether or notPublishWithContainerFilesis used:Breaking changes
This changes where .NET project archives are written when
WithContainerBuildOptionssetsDestination = ContainerImageDestination.ArchiveandOutputPathis a directory. The archive file is now<LocalImageName>.tar, with registry-qualified names flattened into one file name (team/programbecomesteam-program.tar). Previously:PublishWithContainerFiles: the .NET SDK wrote<LocalImageName>.tar.gz, an uncompressed tar despite the name (dotnet/sdk-container-builds#518). Registry-qualified names created subdirectories.PublishWithContainerFiles: Aspire wrote<LocalImageName>-<tag>.tar.Who is affected: anything outside Aspire that hard-codes the old file name, such as CI steps, scripts, or deployment manifests that read
images/server.tar.gz. Aspire's own deployment steps are not affected, because they resolve the path throughContainerImageReference, which returns the new name.How to update: read
<LocalImageName>.tarinstead. Or setOutputPathto an explicit file name, such asPath.Combine(outputDir, "server.tar.gz"), which is used as-is; Aspire logs a warning because the archive is not gzip-compressed.Other behavior changes:
.tar.gz/.tgzOutputPathused to be gzip-compressed and is now an uncompressed tar, matching the SDK. Aspire logs a warning for these names.archives.v1, is treated as a directory. Previously, publishing without container files failed trying to write a file there.Servicing: a 17.0.x backport should keep the SDK's
<LocalImageName>.tar.gzdirectory naming (unflattened), so the rename ships only inmain. The OCI, compression, and path-consistency fixes can be backported.Validation
dotnet test --project tests\Aspire.Hosting.Tests\Aspire.Hosting.Tests.csproj --no-launch-profile -- --filter-class "*.DotnetProgramArchiveTests" --filter-class "*.DockerContainerRuntimeTests" --filter-class "*.DotnetProgramPublishingTests" --filter-class "*.PodmanSaveArgumentsTests" --filter-class "*.ContainerImageArchiveRewriterTests" --filter-class "*.DistributedApplicationPipelineTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true": passed (197 tests).dotnet test --project tests\Aspire.Hosting.Tests\Aspire.Hosting.Tests.csproj --no-launch-profile -- --filter-class "*.ResourceContainerImageBuilderTests" --filter-class "*.WslcContainerRuntimeTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true": 114 passed, 2 failed. The failures are Dockerfile builds that need Docker, which wasn't running locally.dotnet test --project tests\Aspire.Hosting.Dotnet.Tests\Aspire.Hosting.Dotnet.Tests.csproj --no-launch-profile -- --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true": 498 passed, 5 failed, 7 skipped. The failures are real-container archive tests that selected WSLc because Docker wasn't running; they passed on the previous revision with Docker.docker image save busybox:lateston Docker 29.9.3 (containerd store) producedindex.json,manifest.json, andoci-layout.New or updated tests:
docker image savefor single- and multi-platform builds, and the failure when the OCI layout is missing.<image>.tarpath, the SDK receives that explicit file, and existing dotted directories are treated as directories..gz/.tgzname logs a warning;.tarand directory output don't.OutputPathform.Karol Zadora-Przylecki (@karolz-ms), could you take a look?
Fixes #22591
Checklist
<remarks />and<code />elements on your triple slash comments?