Skip to content

Commit e1aa82a

Browse files
Copilotdavidfowl
andcommitted
Set default OutputPath and add IntermediateOutputPath at PipelineContext level
Co-authored-by: davidfowl <[email protected]>
1 parent edf8260 commit e1aa82a

File tree

7 files changed

+37
-12
lines changed

7 files changed

+37
-12
lines changed

src/Aspire.Cli/Commands/PublishCommand.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ protected override string[] GetRunArguments(string? fullyQualifiedOutputPath, st
4949
{
5050
var baseArgs = new List<string> { "--operation", "publish", "--step", "publish" };
5151

52-
var targetPath = fullyQualifiedOutputPath is not null
53-
? fullyQualifiedOutputPath
54-
: Path.Combine(Environment.CurrentDirectory, "aspire-output");
55-
56-
baseArgs.AddRange(["--output-path", targetPath]);
52+
if (fullyQualifiedOutputPath is not null)
53+
{
54+
baseArgs.AddRange(["--output-path", fullyQualifiedOutputPath]);
55+
}
5756

5857
// Add --log-level and --envionment flags if specified
5958
var logLevel = parseResult.GetValue(_logLevelOption);

src/Aspire.Hosting.Azure/AzureEnvironmentResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private Task PublishAsync(PipelineStepContext context)
122122
{
123123
var azureProvisioningOptions = context.Services.GetRequiredService<IOptions<AzureProvisioningOptions>>();
124124
var publishingContext = new AzurePublishingContext(
125-
context.OutputPath ?? throw new InvalidOperationException("OutputPath is required for Azure publishing."),
125+
context.OutputPath,
126126
azureProvisioningOptions.Value,
127127
context.Services,
128128
context.Logger,

src/Aspire.Hosting.Docker/DockerComposePublishingContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal sealed class DockerComposePublishingContext(
3737
UnixFileMode.OtherRead | UnixFileMode.OtherWrite;
3838

3939
public readonly IResourceContainerImageBuilder ImageBuilder = imageBuilder;
40-
public readonly string OutputPath = outputPath ?? throw new InvalidOperationException("OutputPath is required for Docker Compose publishing.");
40+
public readonly string OutputPath = outputPath;
4141

4242
internal async Task WriteModelAsync(DistributedApplicationModel model, DockerComposeEnvironmentResource environment)
4343
{

src/Aspire.Hosting.Kubernetes/KubernetesPublishingContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal sealed class KubernetesPublishingContext(
2020
ILogger logger,
2121
CancellationToken cancellationToken = default)
2222
{
23-
public readonly string OutputPath = outputPath ?? throw new InvalidOperationException("OutputPath is required for Kubernetes publishing.");
23+
public readonly string OutputPath = outputPath;
2424

2525
private readonly Dictionary<string, Dictionary<string, object>> _helmValues = new()
2626
{

src/Aspire.Hosting/Pipelines/PipelineContext.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
using System.Diagnostics.CodeAnalysis;
55
using Aspire.Hosting.ApplicationModel;
6+
using Microsoft.Extensions.Configuration;
7+
using Microsoft.Extensions.DependencyInjection;
68
using Microsoft.Extensions.Logging;
79

810
namespace Aspire.Hosting.Pipelines;
@@ -53,5 +55,24 @@ public sealed class PipelineContext(
5355
/// <summary>
5456
/// Gets the output path for deployment artifacts.
5557
/// </summary>
56-
public string? OutputPath { get; } = outputPath;
58+
public string OutputPath { get; } = outputPath ?? Path.Combine(Environment.CurrentDirectory, "aspire-output");
59+
60+
/// <summary>
61+
/// Gets the intermediate output path for temporary build artifacts.
62+
/// </summary>
63+
public string IntermediateOutputPath { get; } = GetIntermediateOutputPath(serviceProvider);
64+
65+
private static string GetIntermediateOutputPath(IServiceProvider serviceProvider)
66+
{
67+
var configuration = serviceProvider.GetRequiredService<IConfiguration>();
68+
var appHostSha = configuration["AppHost:PathSha256"];
69+
70+
if (!string.IsNullOrEmpty(appHostSha))
71+
{
72+
return Directory.CreateTempSubdirectory($"aspire-{appHostSha}").FullName;
73+
}
74+
75+
// Fallback if AppHost:PathSha256 is not available
76+
return Directory.CreateTempSubdirectory("aspire").FullName;
77+
}
5778
}

src/Aspire.Hosting/Pipelines/PipelineStepContext.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,10 @@ public sealed class PipelineStepContext
5858
/// <summary>
5959
/// Gets the output path for deployment artifacts.
6060
/// </summary>
61-
public string? OutputPath => PipelineContext.OutputPath;
61+
public string OutputPath => PipelineContext.OutputPath;
62+
63+
/// <summary>
64+
/// Gets the intermediate output path for temporary build artifacts.
65+
/// </summary>
66+
public string IntermediateOutputPath => PipelineContext.IntermediateOutputPath;
6267
}

src/Shared/PublishingContextUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public static string GetEnvironmentOutputPath(PipelineStepContext context, IComp
1515
if (context.Model.Resources.OfType<IComputeEnvironmentResource>().Count() > 1)
1616
{
1717
// If there are multiple compute environments, append the environment name to the output path
18-
return Path.Combine(context.OutputPath!, environment.Name);
18+
return Path.Combine(context.OutputPath, environment.Name);
1919
}
2020

2121
// If there is only one compute environment, use the root output path
22-
return context.OutputPath!;
22+
return context.OutputPath;
2323
}
2424
}

0 commit comments

Comments
 (0)