Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 11, 2025

Description

Adds validation for multiple container registries in Docker Compose, Azure Container App, and Azure App Service environments to prevent ambiguous registry selection. When multiple container registries exist in the app model without explicit selection, the system now throws a clear error message instead of silently falling back to defaults.

Changes:

  • Added validation in DockerComposeInfrastructure.GetContainerRegistry that throws InvalidOperationException when multiple registries exist without explicit .WithContainerRegistry() call
  • Added validation in AzureContainerAppEnvironment infrastructure configuration to check for multiple AzureContainerRegistryResource instances
  • Added validation in AzureAppServiceEnvironment infrastructure configuration to check for multiple AzureContainerRegistryResource instances
  • Error messages list available registries and suggest using .WithContainerRegistry(registryBuilder) to resolve

Before:

// Multiple registries present, no explicit selection
builder.AddContainerRegistry("docker-hub", "docker.io", "user1");
builder.AddContainerRegistry("ghcr", "ghcr.io", "user2");
var composeEnv = builder.AddDockerComposeEnvironment("env");
// Silently falls back to LocalContainerRegistry

builder.AddAzureContainerRegistry("acr1");
builder.AddAzureContainerRegistry("acr2");
var azureEnv = builder.AddAzureContainerAppEnvironment("app-host");
// Creates default registry without validation

After:

// Multiple registries present, no explicit selection
builder.AddContainerRegistry("docker-hub", "docker.io", "user1");
builder.AddContainerRegistry("ghcr", "ghcr.io", "user2");
var composeEnv = builder.AddDockerComposeEnvironment("env");
// Throws: "Docker Compose environment 'env' has multiple container registries available - 'docker-hub, ghcr'. 
//          Please specify which registry to use with '.WithContainerRegistry(registryBuilder)'."

builder.AddAzureContainerRegistry("acr1");
builder.AddAzureContainerRegistry("acr2");
var azureEnv = builder.AddAzureContainerAppEnvironment("app-host");
// Throws during infrastructure configuration with similar error message

// Explicit selection works correctly
var acr1 = builder.AddAzureContainerRegistry("acr1");
builder.AddAzureContainerRegistry("acr2");
var azureEnv = builder.AddAzureContainerAppEnvironment("app-host")
    .WithContainerRegistry(acr1); // Success

Implementation Notes:

  • Docker Compose validation occurs during GetContainerRegistry method call
  • Azure environment validation occurs during infrastructure configuration callback to allow fluent API pattern with .WithContainerRegistry()
  • Validation pattern matches existing PushPrereq step in DistributedApplicationPipeline

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No
Original prompt

On DockerComposeInfrastructure.cs, Add a check to GetContainerRegistry that checks if more than 1 container registry is declared in the app model. If there is more than one, throw an exception as is done in PushPrereq in DistributedApplicationPipeline.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…astructure

Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
Copilot AI changed the title [WIP] Add check for multiple container registries in GetContainerRegistry Add multiple container registry validation to DockerComposeInfrastructure Dec 11, 2025
Copilot AI requested a review from captainsafia December 11, 2025 23:14
@github-actions
Copy link
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13513

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13513"

@captainsafia captainsafia marked this pull request as ready for review December 12, 2025 00:24
Copilot AI review requested due to automatic review settings December 12, 2025 00:24
Copy link
Contributor

Copilot AI left a comment

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 adds validation to DockerComposeInfrastructure.GetContainerRegistry to detect and reject scenarios where multiple container registries exist in the app model without explicit selection. This aligns the behavior with the existing PushPrereq validation in DistributedApplicationPipeline.

Key changes:

  • Added validation logic that throws InvalidOperationException when multiple registries are detected without explicit .WithContainerRegistry() call
  • Included descriptive error message listing all available registries and suggesting the resolution
  • Added comprehensive test coverage for the new validation scenario

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Aspire.Hosting.Docker/DockerComposeInfrastructure.cs Added multiple registry validation logic in GetContainerRegistry method (lines 89-96) that matches the pattern used in PushPrereq step
tests/Aspire.Hosting.Docker.Tests/DockerComposeTests.cs Added test MultipleRegistries_WithoutExplicitRegistryOnEnvironment_ThrowsException to verify the validation throws with appropriate error message

The implementation looks good overall. The validation logic is consistent with the existing pattern in DistributedApplicationPipeline.PushPrereq, the error message is clear and actionable, and the test coverage validates the expected behavior. The changes are well-aligned with the repository's coding standards and patterns.

@captainsafia
Copy link
Member

@copilot Update the CreateDefaultAzureContainerRegistry check in the Azure Container App environment implementations and Azure App Service resource to check if there are multiple IAzureContainerRegistries registered in the app model and throw an error about needing to call WithContainerRegistry.

…ce environments

Per @captainsafia's feedback, added validation in CreateDefaultAzureContainerRegistry to check for multiple IAzureContainerRegistry instances in the app model and throw an error suggesting to call WithContainerRegistry when no explicit selection is made.

Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
Copilot AI requested a review from eerhardt as a code owner December 15, 2025 19:11
Copy link
Contributor Author

Copilot AI commented Dec 15, 2025

@copilot Update the CreateDefaultAzureContainerRegistry check in the Azure Container App environment implementations and Azure App Service resource to check if there are multiple IAzureContainerRegi...

Done in commit 1b18c18. Added validation to both AzureContainerAppEnvironment and AzureAppServiceEnvironment to check for multiple AzureContainerRegistryResource instances. The validation occurs during infrastructure configuration and throws with a clear error message suggesting to use .WithContainerRegistry(registryBuilder). Added tests for both scenarios (with and without explicit registry selection).

Copilot AI changed the title Add multiple container registry validation to DockerComposeInfrastructure Add multiple container registry validation to Docker Compose and Azure environments Dec 15, 2025
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.

2 participants