Skip to content

Source OCI image-info from PublishConfiguration and don't pull unless necessary#2161

Open
lbussell wants to merge 9 commits into
mainfrom
lbussell/oci-image-info-fixes
Open

Source OCI image-info from PublishConfiguration and don't pull unless necessary#2161
lbussell wants to merge 9 commits into
mainfrom
lbussell/oci-image-info-fixes

Conversation

@lbussell

Copy link
Copy Markdown
Member

Previously, ImageBuilder pulled OCI image info using using CLI options. It also wasn't consistent across commands. This change resolves the artifact's location from PublishConfiguration (which is already injected via appsettings.json), so every command pulls from the registry where image-info was last published, falling back to the public registry when no publish registry is configured. The pulls are also gated to the scenarios that actually consume the image info, so commands don't need publish registry access when they don't use it.

These are ImageBuilder code-only changes; the corresponding pipeline template updates follow as a separate step per the two-step change process.

  • Resolve build-time image-info source from PublishConfiguration.
  • Resolve getStaleImages image-info source from PublishConfiguration, removing the override options.
  • Resolve generateBuildMatrix image-info source from PublishConfiguration, removing the override options.
  • Resolve mergeImageInfo initial image-info source from PublishConfiguration, removing the override options.
  • Only pull image-info in generateBuildMatrix when --trim-cached-images is set.
  • Only pull the initial image-info in mergeImageInfo when publishing.

lbussell and others added 6 commits June 25, 2026 11:12
BuildCommand located the previously-published image-info OCI artifact using the generic registry-override/repo-prefix options, which point at the per-build staging registry rather than the publish registry where the artifact actually lives.

Inject IOptions<PublishConfiguration> and resolve the image-info registry and repo prefix from PublishRegistry, falling back to the manifest registry when no publish registry is configured.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
GetStaleImagesCommand pulled the image-info OCI artifact using the --image-info-registry-override/--image-info-repo-prefix options. Inject IOptions<PublishConfiguration> and resolve the registry and repo prefix from PublishRegistry, falling back to the manifest registry. Remove the now-redundant override options.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
GenerateBuildMatrixCommand pulled the image-info OCI artifact using the --image-info-registry-override/--image-info-repo-prefix options. Inject IOptions<PublishConfiguration> and resolve the registry and repo prefix from PublishRegistry, falling back to the manifest registry. Remove the now-redundant override options.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
MergeImageInfoCommand pulled the initial (merge-target) image-info OCI artifact using the --initial-image-info-registry-override/--initial-image-info-repo-prefix options. Inject IOptions<PublishConfiguration> and resolve the registry and repo prefix from PublishRegistry, falling back to the manifest registry. Remove the now-redundant override options.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The OCI image-info artifact is only consumed to trim cached images from the matrix, and pulling it requires authenticated access to the publish registry. Skip the pull entirely unless --trim-cached-images was requested, so matrix generation does not need publish-registry access in scenarios that don't trim.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The initial (merge-target) image-info OCI artifact is only relevant when publishing, where it serves as the merge target for newly built image info. Gate the pull on the publish scenario so non-publish merges (which combine freshly produced image-info files) do not attempt to pull from the publish registry.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lbussell lbussell requested a review from a team as a code owner June 25, 2026 18:29
@lbussell lbussell changed the title Source OCI image-info from PublishConfiguration and don't Source OCI image-info from PublishConfiguration and don't pull unless necessary Jun 25, 2026
Comment thread src/ImageBuilder.Tests/BuildCommandTests.cs Fixed
command.Options.ImageInfoRepoPrefix,
default))
.ReturnsAsync(JsonHelper.SerializeObject(imageArtifactDetails));
command.Options.ImageInfoPath = Path.Combine(tempFolderContext.Path, "image-info.json");
PublishRegistry = new RegistryEndpoint { Server = publishRegistry, RepoPrefix = repoPrefix }
};
GenerateBuildMatrixCommand command = CreateCommand(imageInfoServiceMock.Object, publishConfig);
command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json");
Comment thread src/ImageBuilder.Tests/GenerateBuildMatrixCommandTests.cs Fixed
Comment thread src/ImageBuilder/Commands/MergeImageInfoCommand.cs Outdated

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.

Pull request overview

This PR standardizes how ImageBuilder resolves and pulls the OCI image-info artifact by sourcing the registry/repo-prefix from PublishConfiguration (via appsettings.json) instead of per-command CLI override options, and it reduces registry access requirements by skipping pulls when the artifact isn’t needed.

Changes:

  • Resolve image-info OCI artifact source from PublishConfiguration.PublishRegistry (with fallback to the manifest registry) across build-time cache checks and related commands.
  • Remove command-line options that override the image-info pull registry/repo-prefix to make behavior consistent across commands.
  • Gate image-info pulls to only the scenarios that consume it (generateBuildMatrix only when --trim-cached-images is set; mergeImageInfo only when publishing), and update tests accordingly.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/ImageBuilder/Commands/MergeImageInfoOptions.cs Removes CLI override options for initial image-info artifact source.
src/ImageBuilder/Commands/MergeImageInfoCommand.cs Pulls initial image-info from publish registry configuration during publish scenario.
src/ImageBuilder/Commands/GetStaleImagesOptions.cs Removes image-info pull override options.
src/ImageBuilder/Commands/GetStaleImagesCommand.cs Pulls image-info from publish registry config (or manifest registry fallback).
src/ImageBuilder/Commands/GenerateBuildMatrixOptions.cs Removes image-info pull override options.
src/ImageBuilder/Commands/GenerateBuildMatrixCommand.cs Pulls image-info only when trimming cached images, using publish registry config.
src/ImageBuilder/Commands/BuildCommand.cs Uses publish registry config for build-time image-info pulls (fallback to manifest registry).
src/ImageBuilder.Tests/MergeImageInfoFilesCommandTests.cs Updates tests for new PublishConfiguration-based behavior.
src/ImageBuilder.Tests/GetStaleImagesCommandTests.cs Updates tests to supply publish registry config instead of CLI overrides.
src/ImageBuilder.Tests/GenerateBuildMatrixCommandTests.cs Adds/updates tests for publish registry sourcing + conditional pulls when trimming.
src/ImageBuilder.Tests/BuildCommandTests.cs Adds test coverage for publish registry + repo-prefix resolution.

Comment on lines 214 to 217
string imageInfoRegistry = string.IsNullOrWhiteSpace(_publishConfig.PublishRegistry?.Server)
? manifest.Model.Registry
: _publishConfig.PublishRegistry.Server;
if (string.IsNullOrWhiteSpace(imageInfoRegistry))
Comment on lines +73 to +78
// The image-info artifact lives in the publish registry (where it was last published).
// Fall back to the manifest registry when no publish registry is configured.
string imageInfoRegistry = string.IsNullOrWhiteSpace(_publishConfig.PublishRegistry?.Server)
? Manifest.Model.Registry
: _publishConfig.PublishRegistry.Server;

Comment on lines +325 to +331
// The build-time cache check reads the previously-published image info, which lives in the
// publish registry (where publishImageInfoArtifact writes it). Fall back to the manifest
// registry when no publish registry is configured (e.g. public PR builds without appsettings).
string imageInfoRegistry = string.IsNullOrWhiteSpace(_publishConfig.PublishRegistry?.Server)
? Manifest.Model.Registry
: _publishConfig.PublishRegistry.Server;

lbussell and others added 2 commits June 25, 2026 16:13
Addresses Copilot review feedback on PR #2161. When falling back to the manifest registry (no publish registry configured), the code still used PublishRegistry.RepoPrefix, which could incorrectly prefix the repo name when the prefix was set but the server was blank.

Resolve the registry and repo prefix together so the prefix is null on fallback, and throw a clearer error when no registry is available.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants