10000 Account for standard environment variable prefixes when simulating launch profile by ReubenBond · Pull Request #7698 · dotnet/aspire · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Account for standard environment variable prefixes when simulating launch profile #7698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 21, 2025

Conversation

ReubenBond
Copy link
Member

Description

Environment variables prefixed with DOTNET_ or ASPNETCORE_ should be propagated into configuration in non-prefixed form. For example, setting DOTNET_ENVIRONMENT=Testing via an environment variable should set ENVIRONMENT=Testing in configuration.

In the Aspire.Hosting.Testing package, we simulate loading the app host's launch profile, including environment variables. We do not set environment variables in the process since that would leak between concurrently running tests. Instead, we read the environment variables from the launch profile into configuration. This PR changes how we propagate the environment variables into configuration so that we check for those two well-known prefixes and flow them into configuration without those prefixes with the precedence order of no prefix > DOTNET_ > ASPNETCORE_.

In particular, this allows setting the environment name from launch profile to work as expected.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

Copy link
Contributor
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs:164

  • Removing this default environment assignment may lead to unexpected behavior if no environment variable is provided in the launch profile. Please ensure that the intended default (Development) is set when neither a plain nor a prefixed environment variable is present.
hostBuilderOptions.EnvironmentName = Environments.Development;

tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs:110

  • Consider adding tests that explicitly verify how environment variables with the 'DOTNET_' and 'ASPNETCORE_' prefixes propagate into configuration, ensuring that the precedence order (no prefix > DOTNET_ > ASPNETCORE_) is correctly enforced.
[Fact]

@@ -162,7 +162,6 @@ private static void PreConfigureBuilderOptions(
};
applicationOptions.Args = hostBuilderOptions.Args;

hostBuilderOptions.EnvironmentName = Environments.Development;
Copy link
Member Author
@ReubenBond ReubenBond Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnvironmentName is nullable. When not set, it defaults to Production. Our launch profiles set it to Development. If there is no launch profile, therefore, the new behavior would be to set it to Production by default. This would most likely come up in the ad-hoc testing case where the developer has no app host specified (the overloads of DistributedApplicationTestingBuilder.CreateAsync(...) which do not accept a type arg)

ReubenBond and others added 2 commits February 21, 2025 08:27
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
@ReubenBond ReubenBond enabled auto-merge (squash) February 21, 2025 16:28
Copy link
Member
@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ReubenBond ReubenBond merged commit 423d678 into main Feb 21, 2025
69 of 70 checks passed
@ReubenBond ReubenBond deleted the rebond/envvar-to-config-pipeline branch February 21, 2025 16:57
@ReubenBond ReubenBond added the Servicing-consider Issue for next servicing release review label Feb 21, 2025
@eerhardt eerhardt mentioned this pull request Feb 21, 2025
eerhardt added a commit that referenced this pull request Feb 21, 2025
These tests assumed that the test environment was always "development" which is no longer the case after #7698.
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Mar 10, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Apr 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners Servicing-consider Issue for next servicing release review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0