Skip to content

Replace InternalMirrorRegistry and PublicMirrorRegistry with a single MirrorRegistry#2120

Draft
lbussell wants to merge 10 commits into
dotnet:mainfrom
lbussell:refactor-mirror-registries
Draft

Replace InternalMirrorRegistry and PublicMirrorRegistry with a single MirrorRegistry#2120
lbussell wants to merge 10 commits into
dotnet:mainfrom
lbussell:refactor-mirror-registries

Conversation

@lbussell
Copy link
Copy Markdown
Member

This PR is based on #2119. It follows the changes in that PR to their natural conclusion by first removing the unused/old base image regex override CLI options in favor of PublishConfiguration, and then unifies PublicMirrorRegistry and InternalMirrorRegistry into a single MirrorRegistry property.

In effect, this means that mirror registry info is always read from PublishConfiguration, and ImageBuilder never has to know about the differences between internal vs. private configuration (that would be an anti-pattern).

lbussell and others added 10 commits May 22, 2026 15:30
copyBaseImages already imports every base image into the internal
staging ACR ('mirror/' prefix) immediately before getStaleImages runs,
but getStaleImages was still resolving FROM tags against docker.io.
That path is unreachable from the internal 1ES pool, so the command
hangs for 30s on each Docker Hub base image and the job fails.

Rewrite any non-MCR / non-*.azurecr.io FROM reference to the staging
mirror via --base-override-regex/--base-override-sub. The job already
authenticates to InternalMirrorRegistry via reference-service-connections,
so no credential changes are needed. Also drops the buildtools-only
override (which never matched the actual library/<distro> FROM lines).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The previous --base-override-regex/sub approach rewrote external FROM
tags to point at the staging mirror, but the rewritten repo prefix
also leaked into the digest comparison string. image-info.json stores
the digest against the canonical (public) repo, so every rewritten
image compared unequal and was reported stale on every run.

Switch getStaleImages to the same mechanism the build/matrix flow
already uses:
- Add --registry-override and --source-repo-prefix options (mirroring
  what ManifestOptions exposes and what copyBaseImages consumes).
- Construct ImageNameResolverForMatrix per subscription manifest.
  GetFromImagePullTag returns the staging mirror location for fetching
  the digest; GetFromImagePublicTag returns the canonical reference
  used to build the digest comparison string.

The pipeline yml now passes --registry-override / --source-repo-prefix
in place of the regex pair, matching how the copyBaseImages step in
the same job is invoked. --base-override-regex/sub remains supported
for genuine one-off overrides.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Two different FROM spellings can normalize to the same pull tag
(e.g. 'almalinux:8' and 'library/almalinux:8' both pull from
'<staging>/mirror/library/almalinux:8') but produce different public
tags. The previous code cached the full '<repo>@<sha>' comparison
string by pull tag, which meant the second lookup could reuse the
first FROM's public repo prefix and falsely mark the image as stale.

Cache only the raw SHA so the comparison string is always built from
the current platform's own public tag.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ride-sub

The same redirect-to-mirror behavior is expressible via the existing
--registry-override + --source-repo-prefix pair, which is type-checked
rather than an opaque regex/replacement and is already used by every
non-trivial caller (build, copyBaseImages, generateBuildMatrix matrix
flow). The regex form survived as a parallel mechanism but is no
longer needed.

Changes:
- Delete BaseImageOverrideOptions and its two ApplyBaseImageOverride
  call sites in ImageNameResolver (GetFromImagePublicTag and
  GetFromImageTag).
- Drop BaseImageOverrideOptions from BuildOptions, BuildCommand,
  GenerateBuildMatrixOptions, GenerateBuildMatrixCommand,
  CopyBaseImagesOptions, CopyBaseImagesCommand, GetStaleImagesOptions,
  GetStaleImagesCommand.
- Update init-common.yml public-build branch to use
  '--source-repo-prefix "" --registry-override <public-mirror>'
  instead of the regex pair.
- Delete the three tests that exercised the regex form
  (BuildCommand_MirroredImages_BaseImageTagOverride,
  CopyBaseImagesCommand.OverridenBaseTag,
  GetStaleImagesCommand_BaseImageTagOverride). Their scenarios have no
  semantic analogue under the registry/prefix system.
- Document the breaking change in eng/docker-tools/CHANGELOG.md,
  including migration notes for downstream repos and a note about the
  inert custom override file in dotnet-buildtools-prereqs-docker.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the conflated --registry-override/--source-repo-prefix pair
(and the regex-based --base-override-regex/--base-override-sub form
removed in earlier commits) with a single MirrorRegistry field on
PublishConfiguration. The pipeline templates choose the appropriate
mirror (internal staging vs. public mirror) at template-compile time
based on the AzDO team project, so the C# app sees one registry to
redirect external base-image lookups to without any runtime
conditionals or per-command CLI plumbing.

Key change in ImageNameResolver: external FROM tags are now rewritten
using the mirror server (not Manifest.Registry), so source redirection
no longer leaks into the destination tag of built images. This fixes
the previous bug where setting --registry-override on public builds
would also rewrite the push destination.

Surface changes:
- New RegistryEndpoint.RepoPrefix field; new PublishConfiguration.MirrorRegistry.
- Removed PublishConfiguration.InternalMirrorRegistry/PublicMirrorRegistry
  (the YAML side keeps them for project-specific dispatch; the C# binder
  ignores unknown JSON keys).
- Removed --source-repo-prefix CLI option from build/buildMatrix/getStaleImages.
- Removed --registry-override CLI option from getStaleImages (was added
  earlier in this branch and is no longer needed for stale detection).
- publish-config-prod.yml + publish-config-nonprod.yml: emit MirrorRegistry
  conditionally based on ${{ variables['System.TeamProject'] }}.
- init-common.yml: drop public-build override branch (now handled in publish
  config); internal branch keeps --registry-override only.
- check-base-image-updates.yml: drop --registry-override/--source-repo-prefix
  from the getStaleImages invocation.
- BuildCommand, GenerateBuildMatrixCommand, GetStaleImagesCommand take
  IOptions<PublishConfiguration> via DI.

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.

1 participant