microsoft / microsoft/aspire

Publishing docker compose fails if ProjectResource is excluded from manifest

Open
#9,905 1 comment 0 reactions 0 assignees View on GitHub
area-deployment docker-compose
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

Docker compose publisher fails when ProjectResource is configured to be excluded from manifest (via `ExcludeFromManifest()`).

Error: `Failed to publish the distributed application. System.Collections.Generic.KeyNotFoundException: The given key 'Aspire.Hosting.ApplicationModel.ProjectResource' was not present in the dictionary.`

### Expected Behavior

Resources which are excluded from manifest should be ignored by Docker Compose publisher.

### Steps To Reproduce

```
builder.AddProject("foo").ExcludeFromManifest();
builder.AddDockerComposeEnvironment("compose");
```
Execute `aspire publish -o docker-compose-artifacts` command.

### Exceptions (if any)

```
info: Aspire.Hosting.DistributedApplication[0]

info: Aspire.Hosting.Publishing.Publisher[807050189]
Generating Compose output
fail: Aspire.Hosting.DistributedApplicationRunner[0]
Failed to publish the distributed application.
System.Collections.Generic.KeyNotFoundException: The given key 'Aspire.Hosting.ApplicationModel.ProjectResource' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at DockerComposeServiceResourceExtensions.ProcessValue(DockerComposeServiceResource resource, Object value) in
/_/src/Aspire.Hosting.Docker/DockerComposeServiceResourceExtensions.cs:line 22
at Aspire.Hosting.Docker.DockerComposeServiceResource.AddEnvironmentVariablesAndCommandLineArgs(Service composeService) in
/_/src/Aspire.Hosting.Docker/DockerComposeServiceResource.cs:line 167
at Aspire.Hosting.Docker.DockerComposeServiceResource.BuildComposeService() in /_/src/Aspire.Hosting.Docker/DockerComposeServiceResource.cs:line
79
at Aspire.Hosting.Docker.DockerComposePublishingContext.WriteDockerComposeOutputAsync(DistributedApplicationModel model,
DockerComposeEnvironmentResource environment) in /_/src/Aspire.Hosting.Docker/DockerComposePublishingContext.cs:line 77
at Aspire.Hosting.Docker.DockerComposePublishingContext.WriteModelAsync(DistributedApplicationModel model, DockerComposeEnvironmentResource
environment) in /_/src/Aspire.Hosting.Docker/DockerComposePublishingContext.cs:line 52
at Aspire.Hosting.ApplicationModel.PublishingContext.WriteModelAsync(DistributedApplicationModel model) in
/_/src/Aspire.Hosting/Publishing/PublishingContext.cs:line 68
at Aspire.Hosting.DistributedApplicationRunner.ExecuteAsync(CancellationToken stoppingToken) in
/_/src/Aspire.Hosting/DistributedApplicationRunner.cs:line 46
```

### .NET Version info

9.0.300

### Anything else?

Aspire version: 9.3.1+5bc26c78ff8c7be825d0ae33633a1ae9f1d64a67
Aspire.Hosting.Docker Version 9.3.1-preview.1.25305.6

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.