Add origin labels to containers
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
Would it be useful to add some origin labels to containers spun up by Aspire to help identify where they came form? (e.g. the project name & the resource name). Whilst I imagine this wouldn't be of much help in regular use, it could be of help in diagnostic scenarios to know where containers came from.
These labels could also be used with the "long running" container idea been thrown around, in which you can identify if an existing isntance is running by looking for containers with these labels
For example, the following could be done in `IDistributedApplicationLifecycleHook.BeforeStartAsync`
```cs
var projectLabel = $"net.dot.aspire.project={Assembly.GetEntryAssembly()?.GetName().Name}";
foreach (var container in appModel.GetContainerResources())
{
var resourceLabel = $"net.dot.aspire.resource={container.Name}";
container.Annotations.Add(new ContainerRunArgsCallbackAnnotation(x => {
x.Add($"--label");
x.Add(projectLabel);
x.Add($"--label");
x.Add(resourceLabel);
}));
}
```
(For context, this idea comes out of https://github.com/dotnet/aspire/issues/4066#issuecomment-2155877090 )
Contributor guide
Assessment
This issue has not been assessed yet.