Skip to content

Commit 8569a54

Browse files
authored
Obsolete AddAzureContainerAppsInfrastructure (#8639)
* Obsolete AddAzureContainerAppsInfrastructure This method is no longer meant to be used. Instead developers should be calling AddAzureContainerAppEnvironment. Covert the tests using this API to the new API * Fix volume output naming issue We weren't discriminating between volumes and bindmounts, which caused a cache collision. * Switch the prefix at the beginning
1 parent eff11fe commit 8569a54

15 files changed

+252
-233
lines changed

src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppContainerExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static IResourceBuilder<T> PublishAsAzureContainerApp<T>(this IResourceBu
4242
return container;
4343
}
4444

45-
container.ApplicationBuilder.AddAzureContainerAppsInfrastructure();
45+
container.ApplicationBuilder.AddAzureContainerAppsInfrastructureCore();
4646

4747
container.WithAnnotation(new AzureContainerAppCustomizationAnnotation(configure));
4848

src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppEnvironmentResource.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,15 @@ IManifestExpressionProvider IAzureContainerAppEnvironment.GetSecretOutputKeyVaul
8080

8181
IManifestExpressionProvider IAzureContainerAppEnvironment.GetVolumeStorage(IResource resource, ContainerMountAnnotation volume, int volumeIndex)
8282
{
83+
var prefix = volume.Type switch
84+
{
85+
ContainerMountType.BindMount => "bindmounts",
86+
ContainerMountType.Volume => "volumes",
87+
_ => throw new NotSupportedException()
88+
};
89+
8390
// REVIEW: Should we use the same naming algorithm as azd?
84-
var outputName = $"volumes_{resource.Name}_{volumeIndex}";
91+
var outputName = $"{prefix}_{resource.Name}_{volumeIndex}";
8592

8693
if (!VolumeNames.TryGetValue(outputName, out var volumeName))
8794
{

src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExecutableExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static IResourceBuilder<T> PublishAsAzureContainerApp<T>(this IResourceBu
4242
return executable;
4343
}
4444

45-
executable.ApplicationBuilder.AddAzureContainerAppsInfrastructure();
45+
executable.ApplicationBuilder.AddAzureContainerAppsInfrastructureCore();
4646

4747
return executable.WithAnnotation(new AzureContainerAppCustomizationAnnotation(configure));
4848
}

src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ public static class AzureContainerAppExtensions
2828
/// Adds the necessary infrastructure for Azure Container Apps to the distributed application builder.
2929
/// </summary>
3030
/// <param name="builder">The distributed application builder.</param>
31-
public static IDistributedApplicationBuilder AddAzureContainerAppsInfrastructure(this IDistributedApplicationBuilder builder)
31+
[Obsolete($"Use {nameof(AddAzureContainerAppEnvironment)} instead. This method will be removed in a future version.")]
32+
public static IDistributedApplicationBuilder AddAzureContainerAppsInfrastructure(this IDistributedApplicationBuilder builder) =>
33+
AddAzureContainerAppsInfrastructureCore(builder);
34+
35+
internal static IDistributedApplicationBuilder AddAzureContainerAppsInfrastructureCore(this IDistributedApplicationBuilder builder)
3236
{
3337
ArgumentNullException.ThrowIfNull(builder);
3438

@@ -52,7 +56,7 @@ public static IDistributedApplicationBuilder AddAzureContainerAppsInfrastructure
5256
/// <returns><see cref="IResourceBuilder{T}"/></returns>
5357
public static IResourceBuilder<AzureContainerAppEnvironmentResource> AddAzureContainerAppEnvironment(this IDistributedApplicationBuilder builder, string name)
5458
{
55-
builder.AddAzureContainerAppsInfrastructure();
59+
builder.AddAzureContainerAppsInfrastructureCore();
5660

5761
// Only support one temporarily until we can support multiple environments
5862
// and allowing each container app to be explicit about which environment it uses

src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppProjectExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static IResourceBuilder<T> PublishAsAzureContainerApp<T>(this IResourceBu
4242
return project;
4343
}
4444

45-
project.ApplicationBuilder.AddAzureContainerAppsInfrastructure();
45+
project.ApplicationBuilder.AddAzureContainerAppsInfrastructureCore();
4646

4747
project.WithAnnotation(new AzureContainerAppCustomizationAnnotation(configure));
4848

src/Aspire.Hosting.Azure/AzureResourcePreparer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private static void EnsureNoRoleAssignmentAnnotations(DistributedApplicationMode
8585
{
8686
if (resource.HasAnnotationOfType<RoleAssignmentAnnotation>())
8787
{
88-
throw new InvalidOperationException("The application model does not support role assignments. Ensure you are using a publisher that supports role assignments, for example AddAzureContainerAppsInfrastructure.");
88+
throw new InvalidOperationException("The application model does not support role assignments. Ensure you are using an environment that supports role assignments, for example AddAzureContainerAppEnvironment.");
8989
}
9090
}
9191
}

tests/Aspire.Hosting.Azure.Tests/AzureContainerAppsTests.cs

Lines changed: 220 additions & 214 deletions
Large diffs are not rendered by default.

tests/Aspire.Hosting.Azure.Tests/AzureCosmosDBExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public async Task AddAzureCosmosDB(bool useAcaInfrastructure)
189189

190190
if (useAcaInfrastructure)
191191
{
192-
builder.AddAzureContainerAppsInfrastructure();
192+
builder.AddAzureContainerAppEnvironment("env");
193193
}
194194

195195
var cosmos = builder.AddAzureCosmosDB("cosmos");

tests/Aspire.Hosting.Azure.Tests/AzureFunctionsTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public async Task AddAzureFunctionsProject_CanGetStorageManifestSuccessfully()
288288
public async Task AddAzureFunctionsProject_WorksWithAddAzureContainerAppsInfrastructure()
289289
{
290290
using var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish);
291-
builder.AddAzureContainerAppsInfrastructure();
291+
builder.AddAzureContainerAppEnvironment("env");
292292

293293
// hardcoded sha256 to make the storage name deterministic
294294
builder.Configuration["AppHost:Sha256"] = "634f8";
@@ -378,7 +378,7 @@ param principalId string
378378
public async Task AddAzureFunctionsProject_WorksWithAddAzureContainerAppsInfrastructure_WithHostStorage()
379379
{
380380
using var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish);
381-
builder.AddAzureContainerAppsInfrastructure();
381+
builder.AddAzureContainerAppEnvironment("env");
382382

383383
// hardcoded sha256 to make the storage name deterministic
384384
var storage = builder.AddAzureStorage("my-own-storage").RunAsEmulator();
@@ -460,7 +460,7 @@ param principalId string
460460
public async Task AddAzureFunctionsProject_WorksWithAddAzureContainerAppsInfrastructure_WithHostStorage_WithRoleAssignments()
461461
{
462462
using var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish);
463-
builder.AddAzureContainerAppsInfrastructure();
463+
builder.AddAzureContainerAppEnvironment("env");
464464

465465
// hardcoded sha256 to make the storage name deterministic
466466
var storage = builder.AddAzureStorage("my-own-storage").RunAsEmulator();
@@ -523,7 +523,7 @@ param principalId string
523523
public async Task MultipleAddAzureFunctionsProject_WorksWithAddAzureContainerAppsInfrastructure_WithHostStorage_WithRoleAssignments()
524524
{
525525
using var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish);
526-
builder.AddAzureContainerAppsInfrastructure();
526+
builder.AddAzureContainerAppEnvironment("env");
527527

528528
// hardcoded sha256 to make the storage name deterministic
529529
var storage = builder.AddAzureStorage("my-own-storage").RunAsEmulator();

tests/Aspire.Hosting.Azure.Tests/AzurePostgresExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public async Task AddAzurePostgresFlexibleServer(bool publishMode, bool useAcaIn
2424

2525
if (useAcaInfrastructure)
2626
{
27-
builder.AddAzureContainerAppsInfrastructure();
27+
builder.AddAzureContainerAppEnvironment("env");
2828

2929
// on ACA infrastructure, if there are no references to the postgres resource,
3030
// then there won't be any roles created. So add a reference here.

0 commit comments

Comments
 (0)