dotnet / aspire

An opinionated, cloud ready stack for building observable, production ready, distributed applications in .NET
https://learn.microsoft.com/dotnet/aspire
MIT License
3.73k stars 430 forks source link

Adding a project reference with an uppercase name breaks ACA publish #4505

Open jongalloway opened 3 months ago

jongalloway commented 3 months ago

Adding a project reference to apphost using an uppercase name will work fine locally but errors out during publish.

Repro:

  1. Create a new project using the Aspire Starter template (should repro with any .NET Aspire app)
  2. Edit the Program.cs in the AppHost to change the project reference name to include uppercase characters:
    builder.AddProject<Projects.AspireSample_Web>("WebFrontEnd")
    .WithExternalHttpEndpoints()
    .WithReference(apiService);
  3. Deploy to ACA using Visual Studio using the steps in the learn docs.

Deployment fails with the following error message:

6/13/2024 2:20:49 PM: Info   (x) Failed: Deploying service WebFrontEnd
6/13/2024 2:20:49 PM: Error failed deploying service 'WebFrontEnd': updating container app service: applying manifest: PUT https://management.azure.com/subscriptions/asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf/resourceGroups/rg-aspire-deployment-repro/providers/Microsoft.App/containerApps/WebFrontEnd
--------------------------------------------------------------------------------
RESPONSE 400: 400 Bad Request
ERROR CODE: ContainerAppInvalidName
--------------------------------------------------------------------------------
{
  "error": {
    "code": "ContainerAppInvalidName",
    "message": "Invalid ContainerApp name 'WebFrontEnd'. A name must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character and cannot have '--'. The length must not be more than 32 characters."
  }
}
--------------------------------------------------------------------------------

Changing the reference name to lowercase using builder.AddProject<Projects.AspireSample_Web>("webfrontend") and republishing will succeed.

We should both document this issue and ideally include an analyzer or warning that reference names should be lowercased.

DamianEdwards commented 3 months ago

This restriction is specific to Azure Container Apps I believe, so ideally AZD would fail earlier (well before attempting to deploy the app container) with an error making it clear that the app name is invalid. @ellismg

We definitely should have an analyzer that validates resource names based on the rules in ModelName.ValidateName which is tracked by #1209