Skip to content

Commit bd6da41

Browse files
authored
Allow multiple compute environment resources in an app model (#8820)
* Allow multiple compute environment resources in an app model Contributes to #8786 * Add tests * Add IComputeResource and implement it on Project, Container, and Executable. * Tweak tests * PR feedback
1 parent 7cec38b commit bd6da41

File tree

15 files changed

+175
-19
lines changed

15 files changed

+175
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Aspire.Hosting.Azure.AppContainers;
1212
/// <param name="configureInfrastructure">The callback to configure the Azure infrastructure for this resource.</param>
1313
public class AzureContainerAppEnvironmentResource(string name, Action<AzureResourceInfrastructure> configureInfrastructure) :
1414
#pragma warning disable ASPIRECOMPUTE001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
15-
AzureProvisioningResource(name, configureInfrastructure), IAzureContainerAppEnvironment, IAzureContainerRegistry
15+
AzureProvisioningResource(name, configureInfrastructure), IComputeEnvironmentResource, IAzureContainerAppEnvironment, IAzureContainerRegistry
1616
#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.
1717
{
1818
internal bool UseAzdNamingConvention { get; set; }

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public async Task BeforeStartAsync(DistributedApplicationModel appModel, Cancell
6868
#pragma warning disable ASPIRECOMPUTE001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
6969
r.Annotations.Add(new DeploymentTargetAnnotation(containerApp)
7070
{
71-
ContainerRegistryInfo = caes.FirstOrDefault()
71+
ContainerRegistryInfo = caes.FirstOrDefault(),
72+
ComputeEnvironment = environment as IComputeEnvironmentResource // will be null if azd
7273
});
7374
#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.
7475
}

src/Aspire.Hosting.Azure/AzurePublishingContext.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ static BicepValue<string> ResolveValue(object val)
219219

220220
foreach (var resource in model.Resources)
221221
{
222-
if (resource.TryGetLastAnnotation<DeploymentTargetAnnotation>(out var targetAnnotation) &&
223-
targetAnnotation.DeploymentTarget is AzureBicepResource br)
222+
if (resource.GetDeploymentTargetAnnotation()?.DeploymentTarget is AzureBicepResource br)
224223
{
225224
var moduleDirectory = outputDirectory.CreateSubdirectory(resource.Name);
226225

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
namespace Aspire.Hosting.ApplicationModel;
7+
8+
[Experimental("ASPIRECOMPUTE001")]
9+
internal sealed class ComputeEnvironmentAnnotation(IComputeEnvironmentResource computeEnvironment) : IResourceAnnotation
10+
{
11+
public IComputeEnvironmentResource ComputeEnvironment { get; } = computeEnvironment;
12+
}

src/Aspire.Hosting/ApplicationModel/ContainerResource.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ namespace Aspire.Hosting.ApplicationModel;
88
/// </summary>
99
/// <param name="name">The name of the resource.</param>
1010
/// <param name="entrypoint">An optional container entrypoint.</param>
11-
public class ContainerResource(string name, string? entrypoint = null) : Resource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithEndpoints, IResourceWithWaitSupport
11+
public class ContainerResource(string name, string? entrypoint = null)
12+
: Resource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithEndpoints, IResourceWithWaitSupport,
13+
#pragma warning disable ASPIRECOMPUTE001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
14+
IComputeResource
15+
#pragma warning restore ASPIRECOMPUTE001
1216
{
1317
/// <summary>
1418
/// The container Entrypoint.

src/Aspire.Hosting/ApplicationModel/DeploymentTargetAnnotation.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ public sealed class DeploymentTargetAnnotation(IResource target) : IResourceAnno
2121
/// </summary>
2222
[Experimental("ASPIRECOMPUTE001")]
2323
public IContainerRegistry? ContainerRegistryInfo { get; set; }
24+
25+
/// <summary>
26+
/// Gets or sets the compute environment resource associated with the deployment target.
27+
/// </summary>
28+
[Experimental("ASPIRECOMPUTE001")]
29+
public IComputeEnvironmentResource? ComputeEnvironment { get; set; }
2430
}

src/Aspire.Hosting/ApplicationModel/ExecutableResource.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ namespace Aspire.Hosting.ApplicationModel;
1313
/// <param name="command">The command to execute.</param>
1414
/// <param name="workingDirectory">The working directory of the executable.</param>
1515
public class ExecutableResource(string name, string command, string workingDirectory)
16-
: Resource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithEndpoints, IResourceWithWaitSupport
16+
: Resource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithEndpoints, IResourceWithWaitSupport,
17+
#pragma warning disable ASPIRECOMPUTE001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
18+
IComputeResource
19+
#pragma warning restore ASPIRECOMPUTE001
1720
{
1821
/// <summary>
1922
/// Gets the command associated with this executable resource.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
namespace Aspire.Hosting.ApplicationModel;
7+
8+
/// <summary>
9+
/// Represents a compute environment resource.
10+
/// </summary>
11+
[Experimental("ASPIRECOMPUTE001")]
12+
public interface IComputeEnvironmentResource : IResource
13+
{
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
namespace Aspire.Hosting.ApplicationModel;
7+
8+
/// <summary>
9+
/// Represents a compute resource.
10+
/// </summary>
11+
/// <remarks>
12+
/// A compute resource is a resource that can be hosted/executed on an <see cref="IComputeEnvironmentResource"/>. Examples
13+
/// include projects, containers, and other resources that can be executed on a compute environment.
14+
/// </remarks>
15+
[Experimental("ASPIRECOMPUTE001")]
16+
public interface IComputeResource : IResource
17+
{
18+
}

src/Aspire.Hosting/ApplicationModel/ProjectResource.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ namespace Aspire.Hosting.ApplicationModel;
77
/// A resource that represents a specified .NET project.
88
/// </summary>
99
/// <param name="name">The name of the resource.</param>
10-
public class ProjectResource(string name) : Resource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithServiceDiscovery, IResourceWithWaitSupport
10+
public class ProjectResource(string name)
11+
: Resource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithServiceDiscovery, IResourceWithWaitSupport,
12+
#pragma warning disable ASPIRECOMPUTE001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
13+
IComputeResource
14+
#pragma warning restore ASPIRECOMPUTE001
1115
{
1216
// Keep track of the config host for each Kestrel endpoint annotation
1317
internal Dictionary<EndpointAnnotation, string> KestrelEndpointAnnotationHosts { get; } = new();

0 commit comments

Comments
 (0)