Skip to content

Commit

Permalink
Missing applicationUrl does not inherit dashboard url (#1169)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanConroy authored Dec 4, 2023
1 parent c0fac59 commit d1753a2
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.MySqlConnector.Tests
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestProject.IntegrationServiceA", "tests\testproject\TestProject.IntegrationServiceA\TestProject.IntegrationServiceA.csproj", "{DCF2D47A-921A-4900-B5B2-CF97B3531CE8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject.LaunchSettings", "tests\testproject\TestProject.LaunchSettings\TestProject.LaunchSettings.csproj", "{A734177E-213B-4D68-98A4-6F5C00234053}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -430,6 +432,10 @@ Global
{DCF2D47A-921A-4900-B5B2-CF97B3531CE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DCF2D47A-921A-4900-B5B2-CF97B3531CE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DCF2D47A-921A-4900-B5B2-CF97B3531CE8}.Release|Any CPU.Build.0 = Release|Any CPU
{A734177E-213B-4D68-98A4-6F5C00234053}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A734177E-213B-4D68-98A4-6F5C00234053}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A734177E-213B-4D68-98A4-6F5C00234053}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A734177E-213B-4D68-98A4-6F5C00234053}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -505,6 +511,7 @@ Global
{CA283D7F-EB95-4353-B196-C409965D2B42} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
{C8079F06-304F-49B1-A0C1-45AA3782A923} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{DCF2D47A-921A-4900-B5B2-CF97B3531CE8} = {975F6F41-B455-451D-A312-098DE4A167B6}
{A734177E-213B-4D68-98A4-6F5C00234053} = {975F6F41-B455-451D-A312-098DE4A167B6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C}
Expand Down
12 changes: 6 additions & 6 deletions src/Aspire.Hosting/Dcp/ApplicationExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,6 @@ private async Task CreateExecutablesAsync(IEnumerable<AppResource> executableRes
}
else
{
// If there is no launch profile, we want to make sure that certain environment variables are NOT inherited
foreach (var envVar in s_doNotInheritEnvironmentVars)
{
config.Add(envVar, "");
}

if (er.ServicesProduced.Count > 0)
{
if (er.ModelResource is ProjectResource)
Expand Down Expand Up @@ -451,6 +445,12 @@ private async Task CreateExecutablesAsync(IEnumerable<AppResource> executableRes
}
}

// We want to make sure that certain environment variables are NOT inherited
foreach (var envVar in s_doNotInheritEnvironmentVars)
{
config.TryAdd(envVar, "");
}

spec.Env = new();
foreach (var c in config)
{
Expand Down
26 changes: 26 additions & 0 deletions tests/Aspire.Hosting.Tests/DistributedApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,32 @@ public async Task VerifyDockerAppWorks()
await app.StopAsync();
}

[LocalOnlyFact]
public async Task NoUrlInLaunchSettings()
{
var testProgram = CreateTestProgram();
testProgram.AppBuilder.Services.AddLogging(b => b.AddXunit(_testOutputHelper));

testProgram.AppBuilder.AddProject("launch", new Projects.TestProject_LaunchSettings().ProjectPath);

await using var app = testProgram.Build();

await app.StartAsync();

var s = app.Services.GetRequiredService<KubernetesService>();
var list = await s.ListAsync<Executable>();

var proj = list.FirstOrDefault(x => x.Spec.WorkingDirectory?.Contains("LaunchSettings") == true);

Assert.NotNull(proj);
Assert.NotNull(proj.Spec.Env);

// URLs isn't set in launch settings, and shouldn't be inherited from dashboard
Assert.Null(proj.Spec.Env.First(x => x.Name == "ASPNETCORE_URLS").Value);

await app.StopAsync();
}

private static TestProgram CreateTestProgram(string[]? args = null, bool includeIntegrationServices = false, bool includeNodeApp = false) =>
TestProgram.Create<DistributedApplicationTests>(args, includeIntegrationServices: includeIntegrationServices, includeNodeApp: includeNodeApp);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ProjectReference Include="..\TestProject.ServiceB\TestProject.ServiceB.csproj" ServiceNameOverride="ServiceB" />
<ProjectReference Include="..\TestProject.ServiceC\TestProject.ServiceC.csproj" ServiceNameOverride="ServiceC" />
<ProjectReference Include="..\TestProject.WorkerA\TestProject.WorkerA.csproj" ServiceNameOverride="WorkerA" />
<ProjectReference Include="..\TestProject.LaunchSettings\TestProject.LaunchSettings.csproj" ServiceNameOverride="LaunchSettings" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions tests/testproject/TestProject.LaunchSettings/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello World!");
app.MapGet("/pid", () => Environment.ProcessId);

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"TestProject.LaunchSettings": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
//"applicationUrl": Purposefully not included
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions tests/testproject/TestProject.LaunchSettings/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

0 comments on commit d1753a2

Please sign in to comment.