Skip to content

Commit 0a182d5

Browse files
authored
Make manifest publisher available to aspire publish command. (#8399)
1 parent cba3a47 commit 0a182d5

File tree

6 files changed

+26
-6
lines changed

6 files changed

+26
-6
lines changed

playground/waitfor/WaitForSandbox.AppHost/pg-kv-roles.module.bicep

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ resource pg_kv 'Microsoft.KeyVault/vaults@2023-07-01' existing = {
1111
name: pg_kv_outputs_name
1212
}
1313

14-
resource pg_kv_KeyVaultAdministrator 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
15-
name: guid(pg_kv.id, principalId, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '00482a5a-887f-4fb3-b363-3b7fe8e74483'))
14+
resource pg_kv_KeyVaultSecretsUser 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
15+
name: guid(pg_kv.id, principalId, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '4633458b-17de-408a-b874-0445c86b69e6'))
1616
properties: {
1717
principalId: principalId
18-
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '00482a5a-887f-4fb3-b363-3b7fe8e74483')
18+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '4633458b-17de-408a-b874-0445c86b69e6')
1919
principalType: principalType
2020
}
2121
scope: pg_kv

src/Aspire.Cli/DotNetCliRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ private async Task StartBackchannelAsync(Process process, string socketPath, Tas
400400
logger.LogDebug("Connected to AppHost backchannel at {SocketPath}", socketPath);
401401
return;
402402
}
403-
catch (SocketException ex) when (process.HasExited)
403+
catch (SocketException ex) when (process.HasExited && process.ExitCode != 0)
404404
{
405405
logger.LogError(ex, "AppHost process has exited. Unable to connect to backchannel at {SocketPath}", socketPath);
406406
var backchannelException = new InvalidOperationException($"AppHost process has exited unexpectedly. Use --debug to see more deails.");

src/Aspire.Hosting/DistributedApplicationBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options)
366366

367367
// Publishing support
368368
Eventing.Subscribe<BeforeStartEvent>(BuiltInDistributedApplicationEventSubscriptionHandlers.MutateHttp2TransportAsync);
369-
_innerBuilder.Services.AddKeyedSingleton<IDistributedApplicationPublisher, ManifestPublisher>("manifest");
369+
this.AddPublisher<ManifestPublisher, PublishingOptions>("manifest");
370370
_innerBuilder.Services.AddKeyedSingleton<IContainerRuntime, DockerContainerRuntime>("docker");
371371
_innerBuilder.Services.AddKeyedSingleton<IContainerRuntime, PodmanContainerRuntime>("podman");
372372
_innerBuilder.Services.AddSingleton<IResourceContainerImageBuilder, ResourceContainerImageBuilder>();

src/Aspire.Hosting/Publishing/ManifestPublisher.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ protected virtual async Task PublishInternalAsync(DistributedApplicationModel mo
3232
);
3333
}
3434

35+
if (!_options.Value.OutputPath.EndsWith(".json"))
36+
{
37+
// If the manifest path ends with .json we assume that the output path was specified
38+
// as a filename. If not, we assume that the output path was specified as a directory
39+
// and append aspire-manifest.json to the path. This is so that we retain backwards
40+
// compatibility with AZD, but also support manifest publishing via the Aspire CLI
41+
// where the output path is a directory (since not all publishers use a manifest).
42+
_options.Value.OutputPath = Path.Combine(_options.Value.OutputPath, "aspire-manifest.json");
43+
}
44+
45+
var parentDirectory = Directory.GetParent(_options.Value.OutputPath);
46+
if (!Directory.Exists(parentDirectory!.FullName))
47+
{
48+
// Create the directory if it does not exist
49+
Directory.CreateDirectory(parentDirectory.FullName);
50+
}
51+
3552
using var stream = new FileStream(_options.Value.OutputPath, FileMode.Create);
3653
using var jsonWriter = JsonWriter ?? new Utf8JsonWriter(stream, new JsonWriterOptions { Indented = true });
3754

@@ -44,6 +61,7 @@ protected virtual async Task PublishInternalAsync(DistributedApplicationModel mo
4461
protected async Task WriteManifestAsync(DistributedApplicationModel model, Utf8JsonWriter jsonWriter, CancellationToken cancellationToken)
4562
{
4663
var manifestPath = _options.Value.OutputPath ?? throw new DistributedApplicationException("The '--output-path [path]' option was not specified even though '--publisher manifest' argument was used.");
64+
4765
var context = new ManifestPublishingContext(_executionContext, manifestPath, jsonWriter, cancellationToken);
4866

4967
await context.WriteModel(model, cancellationToken).ConfigureAwait(false);

tests/Aspire.Hosting.Tests/Backchannel/AppHostBackchannelTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public async Task CanRequestPublishersAsync()
171171

172172
Assert.Collection(
173173
publishers,
174+
x => Assert.Equal("manifest", x),
174175
x => Assert.Equal("dummy1", x),
175176
x => Assert.Equal("dummy2", x)
176177
);
@@ -215,6 +216,7 @@ public async Task CanRequestPublishersAsyncInInspectMode()
215216

216217
Assert.Collection(
217218
publishers,
219+
x => Assert.Equal("manifest", x),
218220
x => Assert.Equal("dummy1", x),
219221
x => Assert.Equal("dummy2", x)
220222
);

tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ private static TestProgram CreateTestProgramJsonDocumentManifestPublisher(bool i
534534

535535
private static string[] GetManifestArgs()
536536
{
537-
var manifestPath = Path.GetTempFileName();
537+
var manifestPath = Path.Combine(Path.GetTempPath(), "tempmanifests", Guid.NewGuid().ToString(), "manifest.json");
538538
return ["--publisher", "manifest", "--output-path", manifestPath];
539539
}
540540
}

0 commit comments

Comments
 (0)