Repository navigation
Preserve unique suffixes in App Service site names - #18941
Bhupesh Cholake (RealBhupesh) wants to merge 2 commits into
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18941Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 18941" |
There was a problem hiding this comment.
Pull request overview
Updates App Service naming to preserve resource-group suffixes after truncation.
Changes:
- Truncates site-name prefixes before appending suffixes.
- Aligns Bicep, service discovery, summaries, and dashboard naming.
- Adds long-name regression coverage.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
AzureAppServiceTests.cs |
Tests long resource names. |
AzureAppServiceWebSiteResource.cs |
Updates deployment-summary naming. |
AzureAppServiceWebsiteContext.cs |
Updates generated site names. |
AzureAppServiceEnvironmentUtility.cs |
Updates dashboard naming. |
AzureAppServiceEnvironmentResource.cs |
Aligns service-discovery hostnames. |
Comments suppressed due to low confidence (2)
src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebsiteContext.cs:41
- This changes every generated website-name expression, but the existing
.verified.bicepsnapshots still expecttake('${toLower(name)}-${uniqueString(...) }', 60). Snapshot-backed tests such asAddAppServiceWithDeploymentSlotand the delegated-subnet cases will therefore fail until their verified artifacts are regenerated and reviewed.
private BicepValue<string> HostName => BicepFunction.Interpolate(
$"{BicepFunction.Take(BicepFunction.ToLower(resource.Name), AzureAppServiceWebSiteResource.MaxWebSiteNamePrefixLength)}-{AzureAppServiceEnvironmentResource.GetWebSiteSuffixBicep()}");
src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentUtility.cs:22
- The dashboard Bicep expression has changed shape, but all existing dashboard
.verified.bicepsnapshots still contain the old outertake(..., 60)expression. Every snapshot test that provisions the App Service dashboard will fail until those verified artifacts are regenerated and reviewed.
var dashboardPrefix = BicepFunction.Interpolate($"{BicepFunction.ToLower(aspireResourceName)}-{BicepFunction.ToLower(ResourceName)}");
return BicepFunction.Interpolate(
$"{BicepFunction.Take(dashboardPrefix, AzureAppServiceWebSiteResource.MaxWebSiteNamePrefixLength)}-{BicepFunction.GetUniqueString(BicepFunction.GetResourceGroup().Id)}");
| private BicepValue<string> HostName => BicepFunction.Interpolate( | ||
| $"{BicepFunction.Take(BicepFunction.ToLower(resource.Name), AzureAppServiceWebSiteResource.MaxWebSiteNamePrefixLength)}-{AzureAppServiceEnvironmentResource.GetWebSiteSuffixBicep()}"); |
| var dashboardPrefix = BicepFunction.Interpolate($"{BicepFunction.ToLower(aspireResourceName)}-{BicepFunction.ToLower(ResourceName)}"); | ||
| return BicepFunction.Interpolate( | ||
| $"{BicepFunction.Take(dashboardPrefix, AzureAppServiceWebSiteResource.MaxWebSiteNamePrefixLength)}-{BicepFunction.GetUniqueString(BicepFunction.GetResourceGroup().Id)}"); |
| [Fact] | ||
| public async Task AppServiceWebsiteName_PreservesUniqueSuffixForLongResourceNames() | ||
| { | ||
| const string resourceName = "project-with-a-name-longer-than-forty-six-characters"; |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 41 out of 41 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (5)
src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebsiteContext.cs:54
GetSlotHostNamenow assumes the parent site was namedtake(resourceName, 26)-uniqueSuffix, butBuildWebSitestill creates that parent withHostName(take(resourceName, 46)-uniqueSuffix, up to 60 characters). App Service derives the slot host from the parent site name, and the existing deployment-summary helper models that astake(parentName, 40)-slot. For resource names over 26 characters this expression therefore points service discovery at a host different from the deployed slot, while the deployed host still loses the suffix. Make the parent site's physical name slot-aware (at most 40 characters with the suffix retained) and use that same value for outputs and summaries.
var websitePrefix = BicepFunction.Interpolate(
$"{BicepFunction.Take(BicepFunction.ToLower(resource.Name), AzureAppServiceWebSiteResource.MaxWebSiteNamePrefixLengthWithSlotUniqueSuffix)}-{AzureAppServiceEnvironmentResource.GetWebSiteSuffixBicep(resource.Name)}");
return BicepFunction.Take(
BicepFunction.Interpolate($"{websitePrefix}-{BicepFunction.ToLower(deploymentSlot)}"), AzureAppServiceWebSiteResource.MaxHostPrefixLengthWithSlot);
src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentResource.cs:512
- This introduces lifecycle ordering into
GetHostAddressExpression: the deployment target annotation is only installed by the before-start hook, so callers that request the compute-environment expression while constructing or inspecting the model now throw. The previous implementation returned a deferred expression immediately, and the updated test now has to build the app and run hooks to avoid this failure. Keep this API usable before lifecycle hooks, rather than requiring an annotation that does not yet exist.
var deploymentTarget = resource.GetDeploymentTargetAnnotation(this)?.DeploymentTarget;
if (deploymentTarget is not AzureAppServiceWebSiteResource website)
{
throw new InvalidOperationException($"Resource '{resource.Name}' does not have an Azure App Service deployment target.");
src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentExtensions.cs:199
- Removing this output changes every generated environment module, but three tracked Verify snapshots still expect
output webSiteSuffix:AzureAppServiceTests.AddAppServiceToEnvironmentWithoutAutoScale,AzureAppServiceTests.AddAppServiceToEnvironmentWithAutomaticScaling, andAzureAppServiceEnvironmentExtensionsTests.CrossResourceGroupRegistry_UsesStandaloneAcrPullIdentityForFinalRegistry. Those snapshot tests will fail until their.verified.bicepfiles are regenerated (including the dashboard-name changes in the first two).
infra.Add(new ProvisioningOutput("AZURE_CONTAINER_REGISTRY_NAME", typeof(string))
src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebSiteResource.cs:115
- The deploy pipeline tests are still wired to the removed environment-level
webSiteSuffixoutput and do not return the new per-websitenameoutput. InAzureDeployerTests.DeployAsync_WithAppServiceExternalEndpoint_IncludesPortalLinksInSummary, the fake returns[]for theapi-websitedeployment, so this lookup resolves no name and the generated summary cannot match the assertedapi-website123URL. Update the deployment fakes/assertions (and the multiple-compute-environments fake) to provide and consume each website'snameoutput.
private async Task<string> GetAppServiceWebsiteBaseNameAsync(PipelineStepContext context)
{
return (await NameOutputReference.GetValueAsync(context.CancellationToken).ConfigureAwait(false))!;
src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebsiteContext.cs:41
- The
AddAppServiceWithoutTargetPortUsesDefaultPortVerify snapshot was not regenerated for this naming change; it still expectsname: take('${toLower('project1')}-${uniqueString(resourceGroup().id)}', 60)and has no websitenameoutput. That test will fail against the new generated Bicep.
This issue also appears on line 50 of the same file.
private BicepValue<string> HostName => BicepFunction.Interpolate(
$"{BicepFunction.Take(BicepFunction.ToLower(resource.Name), AzureAppServiceWebSiteResource.MaxWebSiteNamePrefixLength)}-{AzureAppServiceEnvironmentResource.GetWebSiteSuffixBicep(resource.Name)}");
| internal static BicepValue<string> GetWebSiteSuffixBicep(string resourceName) => | ||
| BicepFunction.GetUniqueString(BicepFunction.ToLower(resourceName), BicepFunction.GetResourceGroup().Id); |
Summary
Fixes #18750
Validation
dotnet build tests/Aspire.Hosting.Azure.Tests/Aspire.Hosting.Azure.Tests.csproj --no-restoreMicrosoft.TestPlatform.CommunicationUtilities.