Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
@@ -1,5 +1,3 @@
using CommunityToolkit.Aspire.Hosting.Deno;

var builder = DistributedApplication.CreateBuilder(args);

builder.AddDenoTask("vite-demo", taskName: "dev")
Expand Down
23 changes: 19 additions & 4 deletions src/CommunityToolkit.Aspire.Hosting.Bun/BunAppExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Lifecycle;
using CommunityToolkit.Aspire.Hosting.Bun;
using CommunityToolkit.Aspire.Utils;
using Microsoft.Extensions.Hosting;

Expand Down Expand Up @@ -46,10 +44,27 @@ public static IResourceBuilder<BunAppResource> AddBunApp(
/// Ensures the Bun packages are installed before the application starts using Bun as the package manager.
/// </summary>
/// <param name="resource">The Bun app resource.</param>
/// <param name="configureInstaller">Configure the Bun installer resource.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<BunAppResource> WithBunPackageInstallation(this IResourceBuilder<BunAppResource> resource)
public static IResourceBuilder<BunAppResource> WithBunPackageInstallation(this IResourceBuilder<BunAppResource> resource, Action<IResourceBuilder<BunInstallerResource>>? configureInstaller = null)
{
resource.ApplicationBuilder.Services.TryAddLifecycleHook<BunPackageInstallerLifecycleHook>();
// Only install packages during development, not in publish mode
if (!resource.ApplicationBuilder.ExecutionContext.IsPublishMode)
{
var installerName = $"{resource.Resource.Name}-bun-install";
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

But this is moving away from the event model for doing this to the same model used for npm/pnpm/etc. installing.

var installer = new BunInstallerResource(installerName, resource.Resource.WorkingDirectory);

var installerBuilder = resource.ApplicationBuilder.AddResource(installer)
.WithArgs("install")
.WithParentRelationship(resource.Resource)
.ExcludeFromManifest();

// Make the parent resource wait for the installer to complete
resource.WaitForCompletion(installerBuilder);

configureInstaller?.Invoke(installerBuilder);
}

return resource;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Aspire.Hosting.ApplicationModel;

/// <summary>
/// A resource that represents a Bun package installer.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="workingDirectory">The working directory to use for the command.</param>
public class BunInstallerResource(string name, string workingDirectory)
: ExecutableResource(name, "bun", workingDirectory);

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
using Aspire.Hosting.Lifecycle;
using Aspire.Hosting.Utils;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Net.Sockets;
using System.Threading.Tasks;
using static CommunityToolkit.Aspire.Hosting.Dapr.CommandLineArgs;

namespace CommunityToolkit.Aspire.Hosting.Dapr;
Expand All @@ -23,14 +21,21 @@ internal sealed class DaprDistributedApplicationLifecycleHook(
IConfiguration configuration,
IHostEnvironment environment,
ILogger<DaprDistributedApplicationLifecycleHook> logger,
IOptions<DaprOptions> options) : IDistributedApplicationLifecycleHook, IDisposable
IOptions<DaprOptions> options) : IDistributedApplicationEventingSubscriber, IDisposable
{
private readonly DaprOptions _options = options.Value;

private string? _onDemandResourcesRootPath;

public async Task BeforeStartAsync(DistributedApplicationModel appModel, CancellationToken cancellationToken = default)
public Task SubscribeAsync(IDistributedApplicationEventing eventing, DistributedApplicationExecutionContext executionContext, CancellationToken cancellationToken)
{
eventing.Subscribe<BeforeStartEvent>(OnBeforeStartAsync);
return Task.CompletedTask;
}

private async Task OnBeforeStartAsync(BeforeStartEvent @event, CancellationToken cancellationToken = default)
{
var appModel = @event.Model;
string appHostDirectory = GetAppHostDirectory();

// Set up WaitAnnotations for Dapr components based on their value provider dependencies
Expand Down Expand Up @@ -91,7 +96,7 @@ public async Task BeforeStartAsync(DistributedApplicationModel appModel, Cancell
hasValueProviders = true;
}
}

// Check if there are any secrets that need to be added to the secret store
if (componentReferenceAnnotation.Component.TryGetAnnotationsOfType<DaprComponentSecretAnnotation>(out var secretAnnotations))
{
Expand All @@ -100,7 +105,7 @@ public async Task BeforeStartAsync(DistributedApplicationModel appModel, Cancell
secrets[secretAnnotation.Key] = (await secretAnnotation.Value.GetValueAsync(cancellationToken))!;
}
}

// If we have any secrets or value providers, ensure the secret store path is added
if ((secrets.Count > 0 || hasValueProviders) && onDemandResourcesPaths.TryGetValue("secretstore", out var secretStorePath))
{
Expand Down Expand Up @@ -139,7 +144,7 @@ public async Task BeforeStartAsync(DistributedApplicationModel appModel, Cancell
{
context.EnvironmentVariables.TryAdd(secret.Key, secret.Value);
}

// Add value provider references
foreach (var (envVarName, valueProvider) in endpointEnvironmentVars)
{
Expand Down Expand Up @@ -509,10 +514,10 @@ private async Task<IReadOnlyDictionary<string, string>> StartOnDemandDaprCompone
.ToList();

// If any of the components have secrets or value provider references, we will add an on-demand secret store component.
bool needsSecretStore = onDemandComponents.Any(component =>
bool needsSecretStore = onDemandComponents.Any(component =>
(component.TryGetAnnotationsOfType<DaprComponentSecretAnnotation>(out var secretAnnotations) && secretAnnotations.Any()) ||
(component.TryGetAnnotationsOfType<DaprComponentValueProviderAnnotation>(out var valueProviderAnnotations) && valueProviderAnnotations.Any()));

if (needsSecretStore)
{
onDemandComponents.Add(new DaprComponentResource("secretstore", DaprConstants.BuildingBlocks.SecretStore));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static IDistributedApplicationBuilder AddDapr(this IDistributedApplicatio
builder.Services.Configure(configure);
}

builder.Services.TryAddLifecycleHook<DaprDistributedApplicationLifecycleHook>();
builder.Services.TryAddEventingSubscriber<DaprDistributedApplicationLifecycleHook>();

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Lifecycle;
using Microsoft.Extensions.Hosting;
using CommunityToolkit.Aspire.Utils;
using CommunityToolkit.Aspire.Hosting.Deno;

namespace Aspire.Hosting;
/// <summary>
Expand Down Expand Up @@ -73,10 +71,27 @@ public static IResourceBuilder<DenoAppResource> AddDenoTask(this IDistributedApp
/// Ensures the Deno packages are installed before the application starts using Deno as the package manager.
/// </summary>
/// <param name="resource">The Deno app resource.</param>
/// <param name="configureInstaller">Configure the Deno installer resource.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<DenoAppResource> WithDenoPackageInstallation(this IResourceBuilder<DenoAppResource> resource)
public static IResourceBuilder<DenoAppResource> WithDenoPackageInstallation(this IResourceBuilder<DenoAppResource> resource, Action<IResourceBuilder<DenoInstallerResource>>? configureInstaller = null)
{
resource.ApplicationBuilder.Services.TryAddLifecycleHook<DenoPackageInstallerLifecycleHook>();
// Only install packages during development, not in publish mode
if (!resource.ApplicationBuilder.ExecutionContext.IsPublishMode)
{
var installerName = $"{resource.Resource.Name}-deno-install";
var installer = new DenoInstallerResource(installerName, resource.Resource.WorkingDirectory);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above.


var installerBuilder = resource.ApplicationBuilder.AddResource(installer)
.WithArgs("install")
.WithParentRelationship(resource.Resource)
.ExcludeFromManifest();

// Make the parent resource wait for the installer to complete
resource.WaitForCompletion(installerBuilder);

configureInstaller?.Invoke(installerBuilder);
}

return resource;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Aspire.Hosting.ApplicationModel;

/// <summary>
/// A resource that represents a Deno package installer.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="workingDirectory">The working directory to use for the command.</param>
public class DenoInstallerResource(string name, string workingDirectory)
: ExecutableResource(name, "deno", workingDirectory);
Loading
Loading