Repository navigation
Use Microsoft.Extensions.Configuration to load ACR Service Connection info at Runtime - #1880
Conversation
- Add RegistryUri property to Acr class for easy URI access - Add ToAcr() extension method on AcrConfiguration for type conversion - Remove unused using directive from AcrConfiguration.cs
Replace string parameters with ImageName type for better type safety: - GetManifestAsync(ImageName image, ...) - GetImageLayersAsync(ImageName image, ...) - GetLocalImageDigestAsync(ImageName image, ...)
Remove ownedAcr and serviceConnectionOptions parameters from Create method. Service connections are now looked up internally via IRegistryResolver and PublishConfiguration rather than being passed through the factory chain.
- Remove TokenCredential parameter from Create method - Inject IOptions<PublishConfiguration> and IAzureTokenCredentialProvider - Use PublishConfiguration.FindAcrByName() to look up service connections - Throw if no service connection is found for the requested ACR
…rnally - Change Create method to accept Acr type instead of string acrName - Remove IServiceConnection parameter - Inject IOptions<PublishConfiguration> to look up service connections - Use acr.RegistryUri directly instead of DockerHelper.GetAcrUri()
CopyImageService now looks up service connections from PublishConfiguration internally, so the factory pattern is no longer needed.
- Accept ICopyImageService instead of ICopyImageServiceFactory - Remove Lazy wrapper since service is now a singleton - Remove AcrServiceConnection from CopyImagesOptions - Remove ServiceConnectionOptionsBuilder from CopyImagesOptionsBuilder
…services - Accept ICopyImageService instead of ICopyImageServiceFactory - Use Acr.Parse().Name instead of CopyImageService.GetBaseAcrName()
- Update IManifestService mock setups to use ImageName instead of string - Normalize image digest dictionary keys using ImageName.Parse() to match how the mock receives ImageName types - Update GetStaleImagesCommand_BaseImageTagOverride test to use proper registry format (my-registry.io instead of my-registry) - Fix BuildCommand test verify to use It.IsAny<ImageName>() instead of string
There was a problem hiding this comment.
Pull request overview
This PR introduces a significant architectural improvement by adopting Microsoft.Extensions.Configuration to centralize ACR service connection management. Instead of passing service connection details through command-line arguments and method parameters, the configuration is loaded from appsettings.json at startup and made available throughout the application via dependency injection using IOptions<PublishConfiguration>.
Key Changes:
- Configuration-based approach replaces CLI arguments for ACR service connections across multiple commands (Build, CopyImages, CleanAcrImages, GenerateBuildMatrix, PublishManifest, AnnotateEolDigests)
- New
RegistryResolverservice centralizes registry resolution logic and authentication method determination - Introduced strongly-typed abstractions (
Acr,ImageNameas record types) for better type safety and easier reasoning about registry references - Removed factory pattern for
CopyImageService- now registered as a singleton directly
Reviewed changes
Copilot reviewed 66 out of 66 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
src/ImageBuilder/Configuration/PublishConfiguration.cs |
New configuration class defining ACR configurations for build, publish, and mirror registries |
src/ImageBuilder/Configuration/Acr.cs |
New strongly-typed ACR reference abstraction with normalization logic |
src/ImageBuilder/Configuration/ServiceConnection.cs |
New record type implementing IServiceConnection for configuration binding |
src/ImageBuilder/Configuration/ConfigurationExtensions.cs |
Extension methods for configuration setup and ACR lookup logic |
src/ImageBuilder/RegistryResolver.cs |
New service centralizing registry resolution and authentication method determination |
src/ImageBuilder/IRegistryResolver.cs |
Interface defining registry resolution contract with RegistryInfo result type |
src/ImageBuilder/RegistryManifestClientFactory.cs |
Updated to use RegistryResolver instead of direct parameter passing |
src/ImageBuilder/RegistryCredentialsProvider.cs |
Simplified to use RegistryResolver; removed explicit registry/connection parameters |
src/ImageBuilder/CopyImageService.cs |
No longer created via factory; added ArmClient caching and ACR lookup from configuration |
src/ImageBuilder/ImageName.cs |
Changed from class to record; added implicit conversions and ToString(); properties now non-nullable with empty string defaults |
src/ImageBuilder/AcrClientFactory.cs |
Updated to resolve service connections from configuration internally |
src/ImageBuilder/AcrContentClientFactory.cs |
Updated to resolve service connections from configuration internally |
src/ImageBuilder/Commands/*Options.cs |
Removed AcrServiceConnection CLI options from multiple command option classes |
src/ImageBuilder/Commands/*Command.cs |
Updated commands to no longer pass service connections explicitly; rely on configuration |
src/ImageBuilder/ImageBuilder.cs |
Added configuration loading via AddPublishConfiguration() and debug output |
src/ImageBuilder.Tests/* |
Updated test mocks and helpers to accommodate new architecture |
Comments suppressed due to low confidence (1)
src/ImageBuilder/ImageName.cs:73
- Condition is always null because of ... is ....
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mthalman
left a comment
There was a problem hiding this comment.
Fantastic set of changes. I really like the simplicity this enables. Just a few comments.
| public ServiceConnection? ServiceConnection { get; set; } = null; | ||
| } | ||
|
|
||
| public static class AcrConfigurationExtensions |
There was a problem hiding this comment.
What's the need for this? Why not define the ToAcr method directly in AcrConfiguration?
There was a problem hiding this comment.
I didn't see a compelling reason to include it in the record itself. If the record definition only includes the properties, then it's easier to glance at and reason about what kinds of configurations are possible/acceptable via appsettings.json. I could see an argument for moving this to ConfigurationExtensions.
I would have done the same for PublishConfiguration.GetKnownAcrConfigurations(), but I decided that method was better suited in the class since it needs to stay in sync with all of the AcrConfiguration properties.
|
Not sure why the Windows build is still failing, because I added to the |
…configuration (#1900) This PR is a follow-up to #1880. It updates the pipelines to use appsettings.json to configure service connections instead of passing them as command line arguments. It includes the ImageBuilder update from #1894. I am submitting this as a separate PR since I don't want automated builds to unexpectedly overwrite my progress. --------- Co-authored-by: dotnet-docker-bot <[email protected]> Co-authored-by: Copilot <[email protected]>
Fixes #1747
This PR introduces a configuration-based approach for managing ACR references and service connections. The changeset is big, but mostly straightforward.
Microsoft.Extensions.Configurationis used to loadappsettings.jsonat runtime. Configuration can be loaded or overridden from many different sources.PublishConfigurationproperty inappsettings.jsonis serialized to aPublishConfigurationobject when ImageBuilder starts up: https://github.com/lbussell/docker-tools/blob/3f27a6f46eb0ca4999585a3fdb91ae9bbfeb8502/src/ImageBuilder/Configuration/ConfigurationExtensions.cs#L16-L18IOptions<PublishConfiguration>via dependency injection: https://github.com/lbussell/docker-tools/blob/3f27a6f46eb0ca4999585a3fdb91ae9bbfeb8502/src/ImageBuilder/RegistryResolver.cs#L15PublishConfiguration, we no longer need to pass them as command line arguments nor do we need to pass them between functions.All of the other changes follow logically from there.
--acr-service-connectionCLI option from BuildOptions, CopyImagesOptions, CleanAcrImagesOptions, GenerateBuildMatrixOptions, AnnotateEolDigestsOptions, PublishManifestOptions.Pipeline changes will come in a follow-up because otherwise this PR wouldn't pass validation. They have already been prepared and tested. They exist on this branch: https://dev.azure.com/dnceng/internal/_git/dotnet-docker-tools?version=GBdev/loganbussell/me-configuration&_a=history. Successful pipeline run: part 1, part 2