dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.88k stars 467 forks source link

Enable support for capturing the Deployment Environment #6593

Open dansiegel opened 1 week ago

dansiegel commented 1 week ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

When deploying applications it is common to deploy to multiple environments. For instance I might deploy to a QA environment, a Staging environment and a Production environment. Currently there is no way to capture this in the AppHost. Depending on the environment I may want to tweak my configuration in any number of ways. For instance I may want a less expensive Sku that is good for a QA/Stage environment while I may want a more expensive Sku for Production.

Describe the solution you'd like

Note that this assumes azd doesn't want to fix the fact that it's building a debug build with the Development environment settings being read in...

if (builder.DeploymentEnvironment == "Production" || builder.IsProduction())
{
    // configure resources for production
}
else if (builder.DeploymentEnvironment == "Staging" || builder.IsStaging())
{
    // configure resources for Stage
}
// When building in Debug with an attached debugger
else if (builder.DeploymentEnvironment == "Local" || builder.IsLocal())
{
    // add any configurations that are specific to local debugging
}

Additional context

No response

joperezr commented 1 week ago

Thanks for logging the issue. In general, the model that we've tried with Aspire is not to pivot based on the deployment environment, but instead configure individual resources to how you want them to be deployed. For example, builder.AddRedis().PublishAs...(). Do you think that would satisfy your scenarios?