Skip to content

Commit

Permalink
Added support for customizing container apps in ACA via the CDK
Browse files Browse the repository at this point in the history
- Added Aspire.Hosting.Azure.ContainerApps. This exposes 3 APIs used to configure and customize container app resources.
- Added deployment target support to project and container resources in the manifest writer. This allows developers to express that a project/container gets deployed using the nested resource type. This requires a branch of azd to wire up and test.
  • Loading branch information
davidfowl committed Sep 25, 2024
1 parent 56b44c5 commit 78c9d21
Show file tree
Hide file tree
Showing 12 changed files with 1,175 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.Sdk.Tests",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.RuntimeIdentifier.Tool", "src\Aspire.Hosting.Sdk\Aspire.RuntimeIdentifier.Tool\Aspire.RuntimeIdentifier.Tool.csproj", "{FF2895FC-A613-43DC-96B8-E5DFA69125CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.Azure.ContainerApps", "src\Aspire.Hosting.Azure.ContainerApps\Aspire.Hosting.Azure.ContainerApps.csproj", "{21FBDB19-0B8B-4F0F-8ED6-98560AD5DDA7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1661,6 +1663,10 @@ Global
{FF2895FC-A613-43DC-96B8-E5DFA69125CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF2895FC-A613-43DC-96B8-E5DFA69125CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF2895FC-A613-43DC-96B8-E5DFA69125CA}.Release|Any CPU.Build.0 = Release|Any CPU
{21FBDB19-0B8B-4F0F-8ED6-98560AD5DDA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{21FBDB19-0B8B-4F0F-8ED6-98560AD5DDA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{21FBDB19-0B8B-4F0F-8ED6-98560AD5DDA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21FBDB19-0B8B-4F0F-8ED6-98560AD5DDA7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1965,6 +1971,7 @@ Global
{F21F921E-1930-4BD5-B665-5EF1B82BD4D2} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
{AEF07BC6-76D8-4A45-89D5-54FC4483863F} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{FF2895FC-A613-43DC-96B8-E5DFA69125CA} = {F534D4F8-5E3A-42FC-BCD7-4C2D6060F9C8}
{21FBDB19-0B8B-4F0F-8ED6-98560AD5DDA7} = {77CFE74A-32EE-400C-8930-5025E8555256}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C}
Expand Down
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
<PackageVersion Include="Azure.Provisioning.AppConfiguration" Version="$(AzureProvisiongVersion)" />
<PackageVersion Include="Azure.Provisioning.ApplicationInsights" Version="1.0.0-alpha.20240918.1" />
<PackageVersion Include="Azure.Provisioning.CognitiveServices" Version="$(AzureProvisiongVersion)" />
<PackageVersion Include="Azure.Provisioning.ContainerRegistry" Version="1.0.0-alpha.20240912.5" />
<PackageVersion Include="Azure.Provisioning.AppContainers" Version="1.0.0-alpha.20240912.5" />
<PackageVersion Include="Azure.Provisioning.CosmosDB" Version="$(AzureProvisiongVersion)" />
<PackageVersion Include="Azure.Provisioning.EventHubs" Version="$(AzureProvisiongVersion)" />
<PackageVersion Include="Azure.Provisioning.KeyVault" Version="$(AzureProvisiongVersion)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(DefaultTargetFramework)</TargetFramework>
<IsPackable>true</IsPackable>
<PackageTags>aspire hosting azure</PackageTags>
<Description>Azure container apps resource types for .NET Aspire.</Description>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PackageIconFullPath>$(SharedDir)Azure_256x.png</PackageIconFullPath>
</PropertyGroup>

<PropertyGroup>
<MinCodeCoverage>0</MinCodeCoverage>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Provisioning.AppContainers" />
<ProjectReference Include="..\Aspire.Hosting.Azure\Aspire.Hosting.Azure.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#pragma warning disable AZPROVISION001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Lifecycle;
using Azure.Provisioning.AppContainers;

namespace Aspire.Hosting.Azure;

/// <summary>
///
/// </summary>
public static class AzureContainerAppExtensions
{
/// <summary>
///
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static IDistributedApplicationBuilder AddContainerAppsInfrastructure(this IDistributedApplicationBuilder builder)
{
builder.Services.TryAddLifecycleHook<AzureContainerAppsInfastructure>();

return builder;
}

/// <summary>
///
/// </summary>
/// <param name="project"></param>
/// <param name="configure"></param>
/// <returns></returns>
public static IResourceBuilder<ProjectResource> PublishAsContainerApp(this IResourceBuilder<ProjectResource> project, Action<ResourceModuleConstruct, ContainerApp> configure)
{
if (!project.ApplicationBuilder.ExecutionContext.IsPublishMode)
{
return project;
}

project.ApplicationBuilder.AddContainerAppsInfrastructure();

project.WithAnnotation(new ContainerAppCustomizationAnnotation(configure));

return project;
}

/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="container"></param>
/// <param name="configure"></param>
/// <returns></returns>
public static IResourceBuilder<T> PublishAsContainerApp<T>(this IResourceBuilder<T> container, Action<ResourceModuleConstruct, ContainerApp> configure) where T : ContainerResource
{
if (!container.ApplicationBuilder.ExecutionContext.IsPublishMode)
{
return container;
}

container.ApplicationBuilder.AddContainerAppsInfrastructure();

container.WithAnnotation(new ContainerAppCustomizationAnnotation(configure));

return container;
}
}

internal sealed class ContainerAppCustomizationAnnotation(Action<ResourceModuleConstruct, ContainerApp> configure) : IResourceAnnotation
{
public Action<ResourceModuleConstruct, ContainerApp> Configure { get; } = configure;
}
Loading

0 comments on commit 78c9d21

Please sign in to comment.