Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static IResourceBuilder<T> PublishAsAzureContainerApp<T>(this IResourceBu
return container;
}

container.ApplicationBuilder.AddAzureContainerAppsInfrastructure();
container.ApplicationBuilder.AddAzureContainerAppsInfrastructureCore();

container.WithAnnotation(new AzureContainerAppCustomizationAnnotation(configure));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,15 @@ IManifestExpressionProvider IAzureContainerAppEnvironment.GetSecretOutputKeyVaul

IManifestExpressionProvider IAzureContainerAppEnvironment.GetVolumeStorage(IResource resource, ContainerMountAnnotation volume, int volumeIndex)
{
var prefix = volume.Type switch
{
ContainerMountType.BindMount => "bindmounts",
ContainerMountType.Volume => "volumes",
_ => throw new NotSupportedException()
};

// REVIEW: Should we use the same naming algorithm as azd?
var outputName = $"volumes_{resource.Name}_{volumeIndex}";
var outputName = $"{prefix}_{resource.Name}_{volumeIndex}";

if (!VolumeNames.TryGetValue(outputName, out var volumeName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static IResourceBuilder<T> PublishAsAzureContainerApp<T>(this IResourceBu
return executable;
}

executable.ApplicationBuilder.AddAzureContainerAppsInfrastructure();
executable.ApplicationBuilder.AddAzureContainerAppsInfrastructureCore();

return executable.WithAnnotation(new AzureContainerAppCustomizationAnnotation(configure));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public static class AzureContainerAppExtensions
/// Adds the necessary infrastructure for Azure Container Apps to the distributed application builder.
/// </summary>
/// <param name="builder">The distributed application builder.</param>
public static IDistributedApplicationBuilder AddAzureContainerAppsInfrastructure(this IDistributedApplicationBuilder builder)
[Obsolete($"Use {nameof(AddAzureContainerAppEnvironment)} instead. This method will be removed in a future version.")]
public static IDistributedApplicationBuilder AddAzureContainerAppsInfrastructure(this IDistributedApplicationBuilder builder) =>
AddAzureContainerAppsInfrastructureCore(builder);

internal static IDistributedApplicationBuilder AddAzureContainerAppsInfrastructureCore(this IDistributedApplicationBuilder builder)
{
ArgumentNullException.ThrowIfNull(builder);

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

// Only support one temporarily until we can support multiple environments
// and allowing each container app to be explicit about which environment it uses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static IResourceBuilder<T> PublishAsAzureContainerApp<T>(this IResourceBu
return project;
}

project.ApplicationBuilder.AddAzureContainerAppsInfrastructure();
project.ApplicationBuilder.AddAzureContainerAppsInfrastructureCore();

project.WithAnnotation(new AzureContainerAppCustomizationAnnotation(configure));

Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Hosting.Azure/AzureResourcePreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static void EnsureNoRoleAssignmentAnnotations(DistributedApplicationMode
{
if (resource.HasAnnotationOfType<RoleAssignmentAnnotation>())
{
throw new InvalidOperationException("The application model does not support role assignments. Ensure you are using a publisher that supports role assignments, for example AddAzureContainerAppsInfrastructure.");
throw new InvalidOperationException("The application model does not support role assignments. Ensure you are using an environment that supports role assignments, for example AddAzureContainerAppEnvironment.");
}
}
}
Expand Down
434 changes: 220 additions & 214 deletions tests/Aspire.Hosting.Azure.Tests/AzureContainerAppsTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public async Task AddAzureCosmosDB(bool useAcaInfrastructure)

if (useAcaInfrastructure)
{
builder.AddAzureContainerAppsInfrastructure();
builder.AddAzureContainerAppEnvironment("env");
}

var cosmos = builder.AddAzureCosmosDB("cosmos");
Expand Down
8 changes: 4 additions & 4 deletions tests/Aspire.Hosting.Azure.Tests/AzureFunctionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public async Task AddAzureFunctionsProject_CanGetStorageManifestSuccessfully()
public async Task AddAzureFunctionsProject_WorksWithAddAzureContainerAppsInfrastructure()
{
using var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish);
builder.AddAzureContainerAppsInfrastructure();
builder.AddAzureContainerAppEnvironment("env");

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

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

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

// hardcoded sha256 to make the storage name deterministic
var storage = builder.AddAzureStorage("my-own-storage").RunAsEmulator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task AddAzurePostgresFlexibleServer(bool publishMode, bool useAcaIn

if (useAcaInfrastructure)
{
builder.AddAzureContainerAppsInfrastructure();
builder.AddAzureContainerAppEnvironment("env");

// on ACA infrastructure, if there are no references to the postgres resource,
// then there won't be any roles created. So add a reference here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task AddAzureRedis(bool useAcaInfrastructure)

if (useAcaInfrastructure)
{
builder.AddAzureContainerAppsInfrastructure();
builder.AddAzureContainerAppEnvironment("env");
}

var redis = builder.AddAzureRedis("redis-cache");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task AppliesDefaultRoleAssignmentsInRunModeIfReferenced(bool addCon
using var builder = TestDistributedApplicationBuilder.Create(operation);
if (addContainerAppsInfra)
{
builder.AddAzureContainerAppsInfrastructure();
builder.AddAzureContainerAppEnvironment("env");
}

var storage = builder.AddAzureStorage("storage");
Expand Down Expand Up @@ -125,7 +125,7 @@ param principalId string
public async Task AppliesRoleAssignmentsInRunMode(DistributedApplicationOperation operation)
{
using var builder = TestDistributedApplicationBuilder.Create(operation);
builder.AddAzureContainerAppsInfrastructure();
builder.AddAzureContainerAppEnvironment("env");

var storage = builder.AddAzureStorage("storage");
var blobs = storage.AddBlobs("blobs");
Expand Down Expand Up @@ -216,7 +216,7 @@ param principalId string
public async Task FindsAzureReferencesFromArguments()
{
using var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish);
builder.AddAzureContainerAppsInfrastructure();
builder.AddAzureContainerAppEnvironment("env");

var storage = builder.AddAzureStorage("storage");
var blobs = storage.AddBlobs("blobs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task AddAzureSqlServer(bool publishMode, bool useAcaInfrastructure)

if (useAcaInfrastructure)
{
builder.AddAzureContainerAppsInfrastructure();
builder.AddAzureContainerAppEnvironment("env");

// on ACA infrastructure, if there are no references to the resource,
// then there won't be any roles created. So add a reference here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public void AddAzureContainerAppsInfrastructureShouldThrowWhenBuilderIsNull()

var action = () =>
{
#pragma warning disable CS0618 // Type or member is obsolete
builder.AddAzureContainerAppsInfrastructure();
#pragma warning restore CS0618 // Type or member is obsolete
};

var exception = Assert.Throws<ArgumentNullException>(action);
Expand Down
2 changes: 1 addition & 1 deletion tests/Aspire.Hosting.Azure.Tests/RoleAssignmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ private async Task RoleAssignmentTest(
bool includePrincipalName = false)
{
var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish);
builder.AddAzureContainerAppsInfrastructure();
builder.AddAzureContainerAppEnvironment("env");

configureBuilder(builder);

Expand Down
Loading