Skip to content

Draft of incremental container generation - #49556

Closed
baronfel wants to merge 40 commits into
dotnet:mainfrom
baronfel:incremental-containers
Closed

baronfel wants to merge 40 commits into
dotnet:mainfrom
baronfel:incremental-containers

Conversation

@baronfel

@baronfel baronfel commented Jun 25, 2025 •

Copy link
Copy Markdown
Member

Fixes dotnet/sdk-container-builds#438

This is a wholesale rewrite of the way that we generate container images to support better MSBuild incrementality (as well as controlling/caching the location that the SDK stores the pulled base image layers/manifests/etc).

In general, today we re-do a lot of work for each individual image:

  • manifest pulling
  • RID selection
  • app layer creation
  • app manifest/config creation
  • publishing to various destinations

We do all of these things per-RID, every build.

With this PR we attempt to:

  • pull manifests once (and support caching them!)
  • pull layers once
  • use the data from this stage as inputs to the rest of the container generation
  • make the app-level layer, configuration, and manifest generation incremental
  • separate the creation of the artifacts from the sending of the artifacts
  • disentangle the giant ball of mud that CreateNewImage is :)

Right now, for single-RID containers we are very incremental! The main gaps are:

  • rebuilds are missing some data (need input from @rainersigwald on the best way to ensure that Items created during Task execution are actually handled correctly across runs)
  • the multi-arch manifest creation/publishing isn't yet created
  • after this the only thing that we need .NET 7+ for is actually creating the app layer - the containerize app can become a CLI app that just makes a tar archive from a given directory. every other part of the pipeline can use the same Task implementations on framework and modern .NET

<ContainerGenerateLabels Condition="'$(ContainerGenerateLabels)' == ''">true</ContainerGenerateLabels>
<ContainerGenerateLabelsImageCreated Condition="'$(ContainerGenerateLabelsImageCreated)' == ''">true</ContainerGenerateLabelsImageCreated>
<!-- NOTE: this label screws up incrementality - may want to disable it by default -->
<ContainerGenerateLabelsImageCreated Condition="'$(ContainerGenerateLabelsImageCreated)' != 'true'">false</ContainerGenerateLabelsImageCreated>

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.

Could you use the last write timestamp of the main output assembly instead? That should be close enough to the actual date and is better than nothing.

I've found the created label very useful when troubleshooting people running latest tag, not realising it may not be the same latest as the container registry, so it would be a shame to loose it by default.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a really interesting idea - System.IO.File.GetLastWriteTime is a static method so we can easily call it from the MSBuild logic to power this!

@github-actions

Copy link
Copy Markdown
Contributor

Due to lack of recent activity, this PR has been labeled as 'Stale'. It will be closed if no further activity occurs within 7 more days. Any new comment will remove the label.

@github-actions github-actions Bot added the stale label Jan 31, 2026
@baronfel baronfel removed the stale label Jan 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Due to lack of recent activity, this PR has been labeled as 'Stale'. It will be closed if no further activity occurs within 7 more days. Any new comment will remove the label.

@github-actions github-actions Bot added the stale label May 27, 2026
@github-actions github-actions Bot closed this Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Containers Related to dotnet SDK containers functionality stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Incremental Build of Container Images

2 participants