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
40 changes: 40 additions & 0 deletions src/Aspire.Hosting/ApplicationModel/ContainerExecutableResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace Aspire.Hosting.ApplicationModel;

/// <summary>
/// Executable resource that runs in a container.
/// </summary>
internal class ContainerExecutableResource(string name, ContainerResource containerResource, string command, string? workingDirectory)
: Resource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithEndpoints, IResourceWithWaitSupport
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DeagleGross this merged in before I got a chance to fully review it - but one thing we should do here is ditch the TargetContainerResource property and make this resource implement the IResourceWithParent interface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also get rid of the Args property and instead make it work similar to the ExecutableResource. Because you are implementing IResourceWithArgs it means that this resource should be able to work with the WithArgs method - and it should honor all of the semantics around deferred evaluation etc.

{
/// <summary>
/// Gets the command associated with this executable resource.
/// </summary>
public string Command { get; } = ThrowIfNullOrEmpty(command);

/// <summary>
/// Gets the working directory for the executable resource.
/// </summary>
public string? WorkingDirectory { get; } = workingDirectory;

/// <summary>
/// Args of the command to run in the container.
/// </summary>
public ICollection<string>? Args { get; init; }

/// <summary>
/// Target container resource that this executable runs in.
/// </summary>
public ContainerResource? TargetContainerResource { get; } = containerResource ?? throw new ArgumentNullException(nameof(containerResource));

private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
return argument;
}
}
26 changes: 22 additions & 4 deletions src/Aspire.Hosting/AspireEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,20 @@ public void DcpContainersCreateStop()
}

[Event(23, Level = EventLevel.Informational, Message = "DCP Executable object creation starting...")]
public void DcpExecutablesCreateStart()
public void DcpExecutableCreateStart(string resourceName)
{
if (IsEnabled())
{
WriteEvent(23);
WriteEvent(23, resourceName);
}
}

[Event(24, Level = EventLevel.Informational, Message = "DCP Executable object creation completed")]
public void DcpExecutablesCreateStop()
public void DcpExecutableCreateStop(string resourceName)
{
if (IsEnabled())
{
WriteEvent(24);
WriteEvent(24, resourceName);
}
}

Expand Down Expand Up @@ -280,4 +280,22 @@ public void DcpVersionCheckStop()
WriteEvent(30);
}
}

[Event(31, Level = EventLevel.Informational, Message = "DCP Container Executable object creation starting...")]
public void DcpContainerExecutableCreateStart(string resourceName)
{
if (IsEnabled())
{
WriteEvent(31, resourceName);
}
}

[Event(32, Level = EventLevel.Informational, Message = "DCP Container Executable object creation completed")]
public void DcpContainerExecutableCreateStop(string resourceName)
{
if (IsEnabled())
{
WriteEvent(32, resourceName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public static Task InitializeDcpAnnotations(BeforeStartEvent beforeStartEvent, C
nameGenerator.EnsureDcpInstancesPopulated(executable);
}

foreach (var containerExec in beforeStartEvent.Model.GetContainerExecutableResources())
{
nameGenerator.EnsureDcpInstancesPopulated(containerExec);
}

foreach (var project in beforeStartEvent.Model.GetProjectResources())
{
nameGenerator.EnsureDcpInstancesPopulated(project);
Expand Down
24 changes: 24 additions & 0 deletions src/Aspire.Hosting/ContainerExecutableResourceExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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;

namespace Aspire.Hosting;

/// <summary>
/// Provides extension methods for working with <see cref="ExecutableResource"/> objects.
/// </summary>
internal static class ContainerExecutableResourceExtensions
{
/// <summary>
/// Returns an enumerable collection of executable resources from the specified distributed application model.
/// </summary>
/// <param name="model">The distributed application model to retrieve executable resources from.</param>
/// <returns>An enumerable collection of executable resources.</returns>
public static IEnumerable<ContainerExecutableResource> GetContainerExecutableResources(this DistributedApplicationModel model)
{
ArgumentNullException.ThrowIfNull(model);

return model.Resources.OfType<ContainerExecutableResource>();
}
}
Loading