Skip to content

.env files being resorted by Docker Compose publisher #14577

@Falco20019

Description

@Falco20019

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Partially related to #12703
We have some additional environment variables that depend on each other:

DOCKER_REGISTRY_HOSTNAME=registry.myhost.com
MIRRORS_DOCKER_REPOSITORY=${DOCKER_REGISTRY_HOSTNAME}/devops/container-images/mirrors/
ASPIRE_DOCKER_REPOSITORY=${MIRRORS_DOCKER_REPOSITORY}aspire-dashboard

Due to EnvFile using SortedDictionary<string, EnvEntry>, the loaded lines get out of order. ASPIRE_DOCKER_REPOSITORY will be on top before MIRRORS_DOCKER_REPOSITORY is declared, leading to an error on startup.

Expected Behavior

At least when already loading the existing file (publish-compose), make sure to not mess up the existing file. On prepare-compose, it's not loaded and just freshly written either way, which sadly blocks us from using it in the first place due to not being able to get sorting in there. But this would at least unblock publish-compse for us. Right now, we manually merge the changes to be able to at least manually start our environment.

Sadly DockerComposeEnvironmentResource.AddEnvironmentVariable is only reachable through DockerComposeServiceExtensions.AsEnvironmentPlaceholder, so it's not possible to just add our variables to the environment. If DockerComposeEnvironmentResource would offer to add self-defined environment variables directly AND have the SortedDictionary being replaced by a Dictionary, prepare-compose would also start working.

This sadly makes usage of most aspire do commands unusable. We COULD avoid using composed values, but this would make the generated docker-compose file less flexible for quick manipulation on customer systems.

Steps To Reproduce

  1. Create an Aspire project using environment variables
  2. Add the above mentioned variables
  3. Call aspire do publish-compose
  4. Check the sorting in .env

Exceptions (if any)

No response

.NET Version info

.NET SDK:
Version: 10.0.103
Commit: c2435c3e0f
Workload version: 10.0.100-manifests.a62d7899
MSBuild version: 18.0.11+c2435c3e0

Runtime Environment:
OS Name: Mac OS X
OS Version: 26.3
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/10.0.103/

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.3
Architecture: arm64
Commit: c2435c3e0f

.NET SDKs installed:
9.0.311 [/usr/local/share/dotnet/sdk]
10.0.103 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 9.0.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 9.0.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
DOTNET_INSTALL_DIR [/usr/local/share/dotnet/]

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Anything else?

Aspire version: 13.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions