prom3theu5 / aspirational-manifests

Handle deployments of .NET Aspire AppHost Projects
MIT License
702 stars 36 forks source link

Multiple images build for same project #212

Open mguirao opened 6 months ago

mguirao commented 6 months ago

🔥 Bug Description

A project is instantiated multiple times but with different environmental variables. When running aspirate build, I can see the project WorkerProject being built 3 times, with 3 images generated in the registry.

🔍 Steps to Reproduce the Bug

var itemTypes = new string[] { "a", "b", "c" };

foreach (var itemType in itemTypes)
{
    builder.AddProject<Projects.WorkerProject>($"run-{itemType}")
        .WithEnvironment("ITEM_TYPE", itemType)
        .WithReference(xxx)
}

🧯 Possible Solution

prom3theu5 commented 6 months ago

Hi

This is an edge case that hasn't come up yet The problem here is in manifest.json which aspire outputs, if you have three projects like that, you're gonna have three entries in the manifest each with different resource names

Its this set of keys (resource names) which is used as the composite key for the image name, and the manifest completely drives aspir8.

You might be better handling this differently based on what you are actually doing, running vs publishing.

mguirao commented 5 months ago

I understand, but since the manifest shows that all the projects are using the same dotnet project (.csproj), this is why I expected the build of this project (and the image generation) to happen only once.

Maybe the composite key for the image should rely more on the 'path', which is more relevant for the building phase.