Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -18,6 +18,12 @@ public class AzureContainerAppEnvironmentResource(string name, Action<AzureResou
#pragma warning restore ASPIRECOMPUTE001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
{
internal bool UseAzdNamingConvention { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the Aspire dashboard should be included in the container app environment.
/// Default is true.
/// </summary>
internal bool EnableDashboard { get; set; } = true;

/// <summary>
/// Gets the unique identifier of the Container App Environment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,17 @@ public static IResourceBuilder<AzureContainerAppEnvironmentResource> AddAzureCon

infra.Add(containerAppEnvironment);

var dashboard = new ContainerAppEnvironmentDotnetComponentResource("aspireDashboard", "2024-10-02-preview")
if (appEnvResource.EnableDashboard)
{
Name = "aspire-dashboard",
ComponentType = "AspireDashboard",
Parent = containerAppEnvironment
};
var dashboard = new ContainerAppEnvironmentDotnetComponentResource("aspireDashboard", "2024-10-02-preview")
{
Name = "aspire-dashboard",
ComponentType = "AspireDashboard",
Parent = containerAppEnvironment
};

infra.Add(dashboard);
infra.Add(dashboard);
}

var managedStorages = new Dictionary<string, ContainerAppManagedEnvironmentStorage>();

Expand Down Expand Up @@ -348,4 +351,16 @@ public static IResourceBuilder<AzureContainerAppEnvironmentResource> WithAzdReso
builder.Resource.UseAzdNamingConvention = true;
return builder;
}

/// <summary>
/// Configures whether the Aspire dashboard should be included in the container app environment.
/// </summary>
/// <param name="builder">The AzureContainerAppEnvironmentResource to configure.</param>
/// <param name="enable">Whether to include the Aspire dashboard. Default is true.</param>
/// <returns><see cref="IResourceBuilder{T}"/></returns>
public static IResourceBuilder<AzureContainerAppEnvironmentResource> WithDashboard(this IResourceBuilder<AzureContainerAppEnvironmentResource> builder, bool enable = true)
{
builder.Resource.EnableDashboard = enable;
return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static partial class AzureContainerAppExtensions
public static IDistributedApplicationBuilder AddAzureContainerAppsInfrastructure(this IDistributedApplicationBuilder builder) { throw null; }

public static ApplicationModel.IResourceBuilder<Azure.AppContainers.AzureContainerAppEnvironmentResource> WithAzdResourceNaming(this ApplicationModel.IResourceBuilder<Azure.AppContainers.AzureContainerAppEnvironmentResource> builder) { throw null; }

public static ApplicationModel.IResourceBuilder<Azure.AppContainers.AzureContainerAppEnvironmentResource> WithDashboard(this ApplicationModel.IResourceBuilder<Azure.AppContainers.AzureContainerAppEnvironmentResource> builder, bool enable = true) { throw null; }
}

public static partial class AzureContainerAppProjectExtensions
Expand Down
44 changes: 44 additions & 0 deletions tests/Aspire.Hosting.Azure.Tests/AzureContainerAppsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,50 @@ await Verify(manifest.ToString(), "json")
.AppendContentAsFile(bicep, "bicep");
}

[Fact]
public async Task ContainerAppEnvironmentWithDashboardEnabled()
{
var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish);

builder.AddAzureContainerAppEnvironment("env")
.WithDashboard(true);

using var app = builder.Build();

await ExecuteBeforeStartHooksAsync(app, default);

var model = app.Services.GetRequiredService<DistributedApplicationModel>();

var containerAppEnvResource = Assert.Single(model.Resources.OfType<AzureContainerAppEnvironmentResource>());

var (manifest, bicep) = await GetManifestWithBicep(containerAppEnvResource);

await Verify(manifest.ToString(), "json")
.AppendContentAsFile(bicep, "bicep");
}

[Fact]
public async Task ContainerAppEnvironmentWithDashboardDisabled()
{
var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish);

builder.AddAzureContainerAppEnvironment("env")
.WithDashboard(false);

using var app = builder.Build();

await ExecuteBeforeStartHooksAsync(app, default);

var model = app.Services.GetRequiredService<DistributedApplicationModel>();

var containerAppEnvResource = Assert.Single(model.Resources.OfType<AzureContainerAppEnvironmentResource>());

var (manifest, bicep) = await GetManifestWithBicep(containerAppEnvResource);

await Verify(manifest.ToString(), "json")
.AppendContentAsFile(bicep, "bicep");
}

private static Task<(JsonNode ManifestNode, string BicepText)> GetManifestWithBicep(IResource resource) =>
AzureManifestUtils.GetManifestWithBicep(resource, skipPreparer: true);

Expand Down
Loading