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 <[email protected]>
|
🚀 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 <[email protected]>
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 |
|
Started backporting to |
|
Pull request created: #2254
|
|
📝 Documentation has been drafted in microsoft/aspire.dev#2254 targeting Added a "Publish to a container archive" section to Note This draft PR needs human review before merging. |
… output (#22672) Backport of #22666 to release/17.0 /cc @eerhardt **Differs from main:** this backport keeps the .NET SDK's `<repository>.tar.gz` file name for a directory `OutputPath`, so it is not a breaking change in 17.0.x. The `<image>.tar` rename and name flattening (labeled `breaking-change` in #22666) ship only in `main`. Because the default directory name ends in `.tar.gz`, the uncompressed-archive warning fires only for explicitly chosen `.gz`/`.tgz` file names. ## Customer Impact Customers who publish a .NET project to an image archive (`Destination = ContainerImageDestination.Archive`) and also use `PublishWithContainerFiles` (for example, to copy a Vite frontend into `wwwroot`) get a different archive than without container files, so tools that consume it break (#22591): - `ImageFormat = Oci` fails on Docker with "Docker cannot export an OCI archive...", even though Docker Engine 25+ writes OCI layouts. - A directory `OutputPath` produces `<name>-<tag>.tar` instead of the SDK's `<name>.tar.gz`. - An explicit `.tar.gz` path is gzip-compressed only when layered, so OCI-layout tools such as `oras cp --from-oci-layout` fail with `invalid tar header`. Separately, `ContainerImageReference` returned a nonexistent `<name>-<tag>.tar` path for .NET projects with a directory `OutputPath`, even without container files. ## Testing Unit tests added or updated in `DockerContainerRuntimeTests`, `DotnetProgramArchiveTests`, `DotnetProgramPublishingTests`, and `ResourceContainerImageManagerTests` cover OCI save on Docker, layered and non-layered builds resolving to the same `<repository>.tar.gz` path, uncompressed output, existing dotted directories, and the `.gz` warning. On the backport branch, the 198 targeted Aspire.Hosting.Tests pass. The full Aspire.Hosting.Dotnet.Tests suite has 498 passing; 5 real-container tests there and 2 Dockerfile-build tests in Aspire.Hosting.Tests couldn't run locally because Docker wasn't running. They passed with Docker on the main PR (#22666). Manually verified that `docker image save` on Docker 29.9.3 writes `oci-layout` and `index.json`. ## Risk Low. The change is limited to .NET project archive publishing (`Destination = Archive`), with no public API changes. Archives from builds without container files keep 17.0's file name and format. Layered archives change name and compression to match the SDK, which is the bug fix. Explicit `.gz`/`.tgz` file names now log a warning. ## Regression? No. The OCI rejection, the layered naming, and the gzip behavior are all present in 13.6.5 (introduced with #19997). --------- Co-authored-by: Eric Erhardt <[email protected]> Co-authored-by: Copilot App <[email protected]>

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?