From fc560d3d7e30421fe1521a7dd763a30b11d054eb Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Fri, 25 Oct 2024 07:36:12 +0000 Subject: [PATCH 01/16] DevContainer initial commit. --- .devcontainer/devcontainer.json | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000000..a45fa7ca369 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,43 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet +{ + "name": "C# (.NET)", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/dotnet:1-9.0", + "features": { + "ghcr.io/devcontainers/features/azure-cli:1": {}, + "ghcr.io/azure/azure-dev/azd:0": {}, + "ghcr.io/devcontainers/features/docker-in-docker": {} + }, + + "containerEnv": { + "DOTNET_ROOT": "/workspaces/aspire/.dotnet" + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [5000, 5001], + // "portsAttributes": { + // "5001": { + // "protocol": "https" + // } + // } + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "rm -rf .dotnet && sudo chmod +x dotnet.sh && ./dotnet.sh restore", + "customizations": { + "vscode": { + "extensions": [ + "ms-dotnettools.csdevkit" + ] + } + } + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} From 956663b8dbb3984bcf5a37ff6b4cd7a45de38148 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Fri, 25 Oct 2024 08:50:08 +0000 Subject: [PATCH 02/16] WIP --- .devcontainer/devcontainer.json | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a45fa7ca369..219301a5ca5 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,7 +7,12 @@ "features": { "ghcr.io/devcontainers/features/azure-cli:1": {}, "ghcr.io/azure/azure-dev/azd:0": {}, - "ghcr.io/devcontainers/features/docker-in-docker": {} + "ghcr.io/devcontainers/features/docker-in-docker": {}, + "ghcr.io/devcontainers/features/dotnet": { + "additionalVersions": [ + "8.0.403" + ] + } }, "containerEnv": { @@ -18,12 +23,25 @@ // "features": {}, // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [5000, 5001], - // "portsAttributes": { - // "5001": { - // "protocol": "https" - // } - // } + "forwardPorts": [ + 15887, // playground/waitfor/WaitForSandbox.AppHost + 5180, // playground/waitfor/WaitForSandbox.ApiService + 7024 // playground/waitfor/WaitFor.Frontend + ], + "portsAttributes": { + "15887": { + "label": "WaitForSandbox.AppHost", + "protocol": "https" + }, + "5180": { + "label": "WaitForSandbox.ApiService", + "protocol": "http" + }, + "7024": { + "label": "WaitFor.Frontend", + "protocol": "https" + } + }, // Use 'postCreateCommand' to run commands after the container is created. "postCreateCommand": "rm -rf .dotnet && sudo chmod +x dotnet.sh && ./dotnet.sh restore", From 6afb5443224715f119bad3b9e1ee2bae3d94e7fc Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Fri, 25 Oct 2024 10:28:45 +0000 Subject: [PATCH 03/16] WIP: devcontainer walkthrough. --- .devcontainer/devcontainer.json | 37 ++++++++++++------- .../waitfor/WaitForSandbox.AppHost/Program.cs | 10 ++++- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 219301a5ca5..85cd50838e5 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,43 +15,52 @@ } }, - "containerEnv": { - "DOTNET_ROOT": "/workspaces/aspire/.dotnet" - }, - // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, // Use 'forwardPorts' to make a list of ports inside the container available locally. "forwardPorts": [ - 15887, // playground/waitfor/WaitForSandbox.AppHost - 5180, // playground/waitfor/WaitForSandbox.ApiService - 7024 // playground/waitfor/WaitFor.Frontend + 15887, // playground/waitfor AppHost + 5180, // playground/waitfor ApiService + 7024, // playground/waitfor Frontend + 15551 // playground/waitfor PGAdmin ], "portsAttributes": { "15887": { - "label": "WaitForSandbox.AppHost", + "label": "WaitFor Playground: AppHost", "protocol": "https" }, "5180": { - "label": "WaitForSandbox.ApiService", + "label": "WaitFor Playground: ApiService", "protocol": "http" }, "7024": { - "label": "WaitFor.Frontend", + "label": "WaitFor Playground: Frontend", "protocol": "https" + }, + "15551": { + "label": "WaitFor Playground: PGAdmin", + "protocol": "http" } }, + "otherPortsAttributes": { + "onAutoForward": "ignore" + }, // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "rm -rf .dotnet && sudo chmod +x dotnet.sh && ./dotnet.sh restore", "customizations": { "vscode": { "extensions": [ - "ms-dotnettools.csdevkit" - ] + "ms-dotnettools.csdevkit", + "ms-azuretools.vscode-bicep", + "ms-azuretools.azure-dev" + ], + "settings": { + "remote.autoForwardPorts": false + } } - } + }, + "postStartCommand": "dotnet dev-certs https --trust" // Configure tool-specific properties. // "customizations": {}, diff --git a/playground/waitfor/WaitForSandbox.AppHost/Program.cs b/playground/waitfor/WaitForSandbox.AppHost/Program.cs index 6ee1f5ac792..f5cc278748f 100644 --- a/playground/waitfor/WaitForSandbox.AppHost/Program.cs +++ b/playground/waitfor/WaitForSandbox.AppHost/Program.cs @@ -7,7 +7,15 @@ .WithPasswordAuthentication() .RunAsContainer(c => { - c.WithPgAdmin(); + c.WithPgAdmin(c => + { + c.WithHostPort(15551); + + // Variables that we are going to need to set when we detect that + // we are run run mode with codespaces. + c.WithEnvironment("PGADMIN_CONFIG_PROXY_X_HOST_COUNT", "1"); + c.WithEnvironment("PGADMIN_CONFIG_PROXY_X_PREFIX_COUNT", "1"); + }); }) .AddDatabase("db"); From 0637d5e0064e95b232f2841597c09d59fe5d66a6 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Fri, 25 Oct 2024 11:52:34 +0000 Subject: [PATCH 04/16] Changes. --- .devcontainer/devcontainer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 85cd50838e5..4f7220d1b13 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -56,10 +56,12 @@ "ms-azuretools.azure-dev" ], "settings": { - "remote.autoForwardPorts": false + "remote.autoForwardPorts": false, + "dotnet.defaultSolution": "Aspire.sln" } } }, + "postCreateCommand": "dotnet restore", "postStartCommand": "dotnet dev-certs https --trust" // Configure tool-specific properties. From 51e8389fc6c416151890db6fb63e7fac232d278d Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Mon, 28 Oct 2024 00:00:52 +0000 Subject: [PATCH 05/16] Set host requirements. --- .devcontainer/devcontainer.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4f7220d1b13..65f36e2cdf1 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,6 +15,12 @@ } }, + "hostRequirements": { + "cpus": 8, + "memory": "32gb", + "storage": "64gb" + }, + // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, From 91ea30d1d694cec189900c4aa9be8c0272ebed19 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Mon, 28 Oct 2024 00:22:28 +0000 Subject: [PATCH 06/16] Fix codespace test so it can run under codespaces. --- .../Codespaces/CodespacesUrlRewriterTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Aspire.Hosting.Tests/Codespaces/CodespacesUrlRewriterTests.cs b/tests/Aspire.Hosting.Tests/Codespaces/CodespacesUrlRewriterTests.cs index b004b8bdf2b..e8444a24960 100644 --- a/tests/Aspire.Hosting.Tests/Codespaces/CodespacesUrlRewriterTests.cs +++ b/tests/Aspire.Hosting.Tests/Codespaces/CodespacesUrlRewriterTests.cs @@ -15,6 +15,10 @@ public class CodespacesUrlRewriterTests(ITestOutputHelper testOutputHelper) public async Task VerifyUrlsRewriterStopsWhenNotInCodespaces() { using var builder = TestDistributedApplicationBuilder.Create(testOutputHelper); + + // Explicitly disable codespace behavior for this test. + builder.Configuration["CODESPACES"] = "false"; + builder.Services.AddLogging(logging => { logging.AddFakeLogging(); From 56fa24284b30427af74801c743c282a162d53c6e Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Mon, 28 Oct 2024 06:34:44 +0000 Subject: [PATCH 07/16] Introduce Codespaces options. --- .../waitfor/WaitForSandbox.AppHost/Program.cs | 5 -- .../PostgresBuilderExtensions.cs | 12 ++++ .../Codespaces/CodespacesOptions.cs | 66 +++++++++++++++++++ .../Codespaces/CodespacesUrlRewriter.cs | 21 ++---- .../DistributedApplicationBuilder.cs | 1 + src/Aspire.Hosting/PublicAPI.Unshipped.txt | 8 +++ 6 files changed, 91 insertions(+), 22 deletions(-) create mode 100644 src/Aspire.Hosting/Codespaces/CodespacesOptions.cs diff --git a/playground/waitfor/WaitForSandbox.AppHost/Program.cs b/playground/waitfor/WaitForSandbox.AppHost/Program.cs index f5cc278748f..e7ad817dd6f 100644 --- a/playground/waitfor/WaitForSandbox.AppHost/Program.cs +++ b/playground/waitfor/WaitForSandbox.AppHost/Program.cs @@ -10,11 +10,6 @@ c.WithPgAdmin(c => { c.WithHostPort(15551); - - // Variables that we are going to need to set when we detect that - // we are run run mode with codespaces. - c.WithEnvironment("PGADMIN_CONFIG_PROXY_X_HOST_COUNT", "1"); - c.WithEnvironment("PGADMIN_CONFIG_PROXY_X_PREFIX_COUNT", "1"); }); }) .AddDatabase("db"); diff --git a/src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs b/src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs index 7ba25586460..b8a83cb7362 100644 --- a/src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs +++ b/src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs @@ -4,9 +4,11 @@ using System.Text; using System.Text.Json; using Aspire.Hosting.ApplicationModel; +using Aspire.Hosting.Codespaces; using Aspire.Hosting.Postgres; using Aspire.Hosting.Utils; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; namespace Aspire.Hosting; @@ -333,6 +335,16 @@ private static void SetPgAdminEnvironmentVariables(EnvironmentCallbackContext co // You need to define the PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD or PGADMIN_DEFAULT_PASSWORD_FILE environment variables. context.EnvironmentVariables.Add("PGADMIN_DEFAULT_EMAIL", "admin@domain.com"); context.EnvironmentVariables.Add("PGADMIN_DEFAULT_PASSWORD", "admin"); + + // When running in the context of Codespaces we need to set some additional environment + // varialbes so that PGAdmin will trust the forwarded headers that Codespaces port + // forwarding will send. + var codespaceOptions = context.ExecutionContext.ServiceProvider.GetRequiredService>(); + if (context.ExecutionContext.IsRunMode && codespaceOptions.Value.IsCodespace) + { + context.EnvironmentVariables["PGADMIN_CONFIG_PROXY_X_HOST_COUNT"] = "1"; + context.EnvironmentVariables["PGADMIN_CONFIG_PROXY_X_PREFIX_COUNT"] = "1"; + } } /// diff --git a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs new file mode 100644 index 00000000000..27abab344e8 --- /dev/null +++ b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs @@ -0,0 +1,66 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Diagnostics.CodeAnalysis; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; + +namespace Aspire.Hosting.Codespaces; + +/// +/// GitHub Codespaces configuration valies. +/// +public class CodespacesOptions +{ + /// + /// When set to true, the app host is running in a GitHub Codespace. + /// + /// + /// Maps to the CODESPACE environment variable. + /// + public bool IsCodespace { get; set; } + + /// + /// When set it is the domain suffix used when port forwarding services hosted on the Codespace. + /// + /// + /// Maps to the GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN environment variable. + /// + [MemberNotNullWhenAttribute(true, nameof(IsCodespace))] + public string? PortForwardingDomain { get; set; } = null; + + /// + /// When set it is the name of the GitHub Codespace in which the app host is running. + /// + /// + /// Maps to the CODESPACE_NAME environment variable. + /// + [MemberNotNullWhenAttribute(true, nameof(IsCodespace))] + public string? CodespaceName { get; set; } = null; +} + +internal class ConfigureCodespacesOptions(IConfiguration configuration) : IConfigureOptions +{ + private const string CodespacesEnvironmentVariable = "CODESPACES"; + private const string CodespaceNameEnvironmentVariable = "CODESPACE_NAME"; + private const string GitHubCodespacesPortForwardingDomain = "GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN"; + + private string GetRequiredCodespacesConfigurationValue(string key) + { + ArgumentNullException.ThrowIfNullOrEmpty(key); + return configuration.GetValue(key) ?? throw new DistributedApplicationException($"Codespaces was detected but {key} environment missing."); + } + + public void Configure(CodespacesOptions options) + { + if (!configuration.GetValue(CodespacesEnvironmentVariable, false)) + { + options.IsCodespace = false; + return; + } + + options.IsCodespace = true; + options.PortForwardingDomain = GetRequiredCodespacesConfigurationValue(GitHubCodespacesPortForwardingDomain); + options.CodespaceName = GetRequiredCodespacesConfigurationValue(CodespaceNameEnvironmentVariable); + } +} \ No newline at end of file diff --git a/src/Aspire.Hosting/Codespaces/CodespacesUrlRewriter.cs b/src/Aspire.Hosting/Codespaces/CodespacesUrlRewriter.cs index e72c3657c2d..4d6a113c72b 100644 --- a/src/Aspire.Hosting/Codespaces/CodespacesUrlRewriter.cs +++ b/src/Aspire.Hosting/Codespaces/CodespacesUrlRewriter.cs @@ -3,35 +3,22 @@ using System.Collections.Immutable; using Aspire.Hosting.ApplicationModel; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; namespace Aspire.Hosting.Codespaces; -internal sealed class CodespacesUrlRewriter(ILogger logger, IConfiguration configuration, ResourceNotificationService resourceNotificationService) : BackgroundService +internal sealed class CodespacesUrlRewriter(ILogger logger, IOptions options, ResourceNotificationService resourceNotificationService) : BackgroundService { - private const string CodespacesEnvironmentVariable = "CODESPACES"; - private const string CodespaceNameEnvironmentVariable = "CODESPACE_NAME"; - private const string GitHubCodespacesPortForwardingDomain = "GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN"; - - private string GetRequiredCodespacesConfigurationValue(string key) - { - ArgumentNullException.ThrowIfNullOrEmpty(key); - return configuration.GetValue(key) ?? throw new DistributedApplicationException($"Codespaces was detected but {key} environment missing."); - } - protected override async Task ExecuteAsync(CancellationToken stoppingToken) { - if (!configuration.GetValue(CodespacesEnvironmentVariable, false)) + if (!options.Value.IsCodespace) { logger.LogTrace("Not running in Codespaces, skipping URL rewriting."); return; } - var gitHubCodespacesPortForwardingDomain = GetRequiredCodespacesConfigurationValue(GitHubCodespacesPortForwardingDomain); - var codespaceName = GetRequiredCodespacesConfigurationValue(CodespaceNameEnvironmentVariable); - do { try @@ -58,7 +45,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) // which is typically ".app.github.dev". The VSCode instance is typically // hosted at codespacename.github.dev whereas the forwarded ports // would be at codespacename-port.app.github.dev. - Url = $"{uri.Scheme}://{codespaceName}-{uri.Port}.{gitHubCodespacesPortForwardingDomain}{uri.AbsolutePath}" + Url = $"{uri.Scheme}://{options.Value.CodespaceName}-{uri.Port}.{options.Value.PortForwardingDomain}{uri.AbsolutePath}" }; remappedUrls.Add(originalUrlSnapshot, newUrlSnapshot); diff --git a/src/Aspire.Hosting/DistributedApplicationBuilder.cs b/src/Aspire.Hosting/DistributedApplicationBuilder.cs index cf2d5824f12..c1ced8265c2 100644 --- a/src/Aspire.Hosting/DistributedApplicationBuilder.cs +++ b/src/Aspire.Hosting/DistributedApplicationBuilder.cs @@ -269,6 +269,7 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options) _innerBuilder.Services.AddSingleton(); // Codespaces + _innerBuilder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, ConfigureCodespacesOptions>()); _innerBuilder.Services.AddHostedService(); Eventing.Subscribe(BuiltInDistributedApplicationEventSubscriptionHandlers.InitializeDcpAnnotations); diff --git a/src/Aspire.Hosting/PublicAPI.Unshipped.txt b/src/Aspire.Hosting/PublicAPI.Unshipped.txt index 0c67fb7aaf8..17cf0546025 100644 --- a/src/Aspire.Hosting/PublicAPI.Unshipped.txt +++ b/src/Aspire.Hosting/PublicAPI.Unshipped.txt @@ -160,6 +160,14 @@ Aspire.Hosting.ApplicationModel.WaitAnnotation.WaitType.get -> Aspire.Hosting.Ap Aspire.Hosting.ApplicationModel.WaitType Aspire.Hosting.ApplicationModel.WaitType.WaitForCompletion = 1 -> Aspire.Hosting.ApplicationModel.WaitType Aspire.Hosting.ApplicationModel.WaitType.WaitUntilHealthy = 0 -> Aspire.Hosting.ApplicationModel.WaitType +Aspire.Hosting.Codespaces.CodespacesOptions +Aspire.Hosting.Codespaces.CodespacesOptions.CodespaceName.get -> string? +Aspire.Hosting.Codespaces.CodespacesOptions.CodespaceName.set -> void +Aspire.Hosting.Codespaces.CodespacesOptions.CodespacesOptions() -> void +Aspire.Hosting.Codespaces.CodespacesOptions.IsCodespace.get -> bool +Aspire.Hosting.Codespaces.CodespacesOptions.IsCodespace.set -> void +Aspire.Hosting.Codespaces.CodespacesOptions.PortForwardingDomain.get -> string? +Aspire.Hosting.Codespaces.CodespacesOptions.PortForwardingDomain.set -> void Aspire.Hosting.DistributedApplicationBuilder.AppHostPath.get -> string! Aspire.Hosting.DistributedApplicationBuilder.Eventing.get -> Aspire.Hosting.Eventing.IDistributedApplicationEventing! Aspire.Hosting.Eventing.DistributedApplicationEventing From c87e7d98ffade143c6773ce27cc0589bb61afff6 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Mon, 28 Oct 2024 13:05:31 +0000 Subject: [PATCH 08/16] Map Redis playground ports. --- .devcontainer/devcontainer.json | 32 +++++++++++++++++------ playground/Redis/Redis.AppHost/Program.cs | 4 +-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 65f36e2cdf1..763d5c599ec 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -26,27 +26,43 @@ // Use 'forwardPorts' to make a list of ports inside the container available locally. "forwardPorts": [ - 15887, // playground/waitfor AppHost - 5180, // playground/waitfor ApiService - 7024, // playground/waitfor Frontend - 15551 // playground/waitfor PGAdmin + 15887, + 5180, + 7024, + 15551, + 33803, + 5350, + 41567, + 15306 ], "portsAttributes": { - "15887": { - "label": "WaitFor Playground: AppHost", - "protocol": "https" - }, "5180": { "label": "WaitFor Playground: ApiService", "protocol": "http" }, + "5350": { + "label": "Redis Playground: Api Service" + }, "7024": { "label": "WaitFor Playground: Frontend", "protocol": "https" }, + "15306": { + "label": "Redis Playground: App Host" + }, "15551": { "label": "WaitFor Playground: PGAdmin", "protocol": "http" + }, + "15887": { + "label": "WaitFor Playground: AppHost", + "protocol": "https" + }, + "33803": { + "label": "Redis Playground: Redis Commander" + }, + "41567": { + "label": "Redis Playground: Redis Insight" } }, "otherPortsAttributes": { diff --git a/playground/Redis/Redis.AppHost/Program.cs b/playground/Redis/Redis.AppHost/Program.cs index b2cbe95d6a1..93669bc6be9 100644 --- a/playground/Redis/Redis.AppHost/Program.cs +++ b/playground/Redis/Redis.AppHost/Program.cs @@ -2,8 +2,8 @@ var redis = builder.AddRedis("redis") .WithDataVolume() - .WithRedisCommander() - .WithRedisInsight(); + .WithRedisCommander(c => c.WithHostPort(33803)) + .WithRedisInsight(c => c.WithHostPort(41567)); var garnet = builder.AddGarnet("garnet") .WithDataVolume(); From b23ccb12d0b67756297f222b53c3834075fe45df Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Tue, 29 Oct 2024 10:41:56 +1100 Subject: [PATCH 09/16] Update src/Aspire.Hosting/Codespaces/CodespacesOptions.cs Co-authored-by: Eric Erhardt --- src/Aspire.Hosting/Codespaces/CodespacesOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs index 27abab344e8..e9e6322b181 100644 --- a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs +++ b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs @@ -26,7 +26,7 @@ public class CodespacesOptions /// /// Maps to the GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN environment variable. /// - [MemberNotNullWhenAttribute(true, nameof(IsCodespace))] + [MemberNotNullWhen(true, nameof(IsCodespace))] public string? PortForwardingDomain { get; set; } = null; /// From d3ff8951c05b09cda6edc25c954cc4f483fcb488 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Tue, 29 Oct 2024 10:42:03 +1100 Subject: [PATCH 10/16] Update src/Aspire.Hosting/Codespaces/CodespacesOptions.cs Co-authored-by: Eric Erhardt --- src/Aspire.Hosting/Codespaces/CodespacesOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs index e9e6322b181..2a37c31d2e6 100644 --- a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs +++ b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs @@ -27,7 +27,7 @@ public class CodespacesOptions /// Maps to the GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN environment variable. /// [MemberNotNullWhen(true, nameof(IsCodespace))] - public string? PortForwardingDomain { get; set; } = null; + public string? PortForwardingDomain { get; set; }; /// /// When set it is the name of the GitHub Codespace in which the app host is running. From b0edc56098168c659cfb3173f4c178fc27ffcaa7 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Tue, 29 Oct 2024 10:42:11 +1100 Subject: [PATCH 11/16] Update src/Aspire.Hosting/Codespaces/CodespacesOptions.cs Co-authored-by: Eric Erhardt --- src/Aspire.Hosting/Codespaces/CodespacesOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs index 2a37c31d2e6..47553f05c54 100644 --- a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs +++ b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs @@ -36,7 +36,7 @@ public class CodespacesOptions /// Maps to the CODESPACE_NAME environment variable. /// [MemberNotNullWhenAttribute(true, nameof(IsCodespace))] - public string? CodespaceName { get; set; } = null; + public string? CodespaceName { get; set; }; } internal class ConfigureCodespacesOptions(IConfiguration configuration) : IConfigureOptions From 5bde6d62fd91787515872c4463890a801c2dcba4 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Tue, 29 Oct 2024 10:42:18 +1100 Subject: [PATCH 12/16] Update src/Aspire.Hosting/Codespaces/CodespacesOptions.cs Co-authored-by: Eric Erhardt --- src/Aspire.Hosting/Codespaces/CodespacesOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs index 47553f05c54..53090223fc9 100644 --- a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs +++ b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs @@ -8,7 +8,7 @@ namespace Aspire.Hosting.Codespaces; /// -/// GitHub Codespaces configuration valies. +/// GitHub Codespaces configuration values. /// public class CodespacesOptions { From b1f3fdbe6ad4a33938c9148feab31fec5c92d800 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Tue, 29 Oct 2024 11:01:40 +1100 Subject: [PATCH 13/16] Update src/Aspire.Hosting/Codespaces/CodespacesOptions.cs Co-authored-by: Eric Erhardt --- src/Aspire.Hosting/Codespaces/CodespacesOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs index 53090223fc9..5c588f9e26b 100644 --- a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs +++ b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs @@ -35,7 +35,7 @@ public class CodespacesOptions /// /// Maps to the CODESPACE_NAME environment variable. /// - [MemberNotNullWhenAttribute(true, nameof(IsCodespace))] + [MemberNotNullWhen(true, nameof(IsCodespace))] public string? CodespaceName { get; set; }; } From 8ae2a44cf2fee7b7e657064d99dfc26fe971a942 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Tue, 29 Oct 2024 00:08:56 +0000 Subject: [PATCH 14/16] Change when command runs to improve reliability. --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 763d5c599ec..f4d1001aba4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -83,7 +83,7 @@ } } }, - "postCreateCommand": "dotnet restore", + "onCreateCommand": "dotnet restore", "postStartCommand": "dotnet dev-certs https --trust" // Configure tool-specific properties. From ec128aa537d394799d098b9c16dc8e7e7f819445 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Tue, 29 Oct 2024 00:21:54 +0000 Subject: [PATCH 15/16] Syntax error. --- src/Aspire.Hosting/Codespaces/CodespacesOptions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs index 5c588f9e26b..f9db7fd49b8 100644 --- a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs +++ b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs @@ -27,7 +27,7 @@ public class CodespacesOptions /// Maps to the GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN environment variable. /// [MemberNotNullWhen(true, nameof(IsCodespace))] - public string? PortForwardingDomain { get; set; }; + public string? PortForwardingDomain { get; set; } /// /// When set it is the name of the GitHub Codespace in which the app host is running. @@ -36,7 +36,7 @@ public class CodespacesOptions /// Maps to the CODESPACE_NAME environment variable. /// [MemberNotNullWhen(true, nameof(IsCodespace))] - public string? CodespaceName { get; set; }; + public string? CodespaceName { get; set; } } internal class ConfigureCodespacesOptions(IConfiguration configuration) : IConfigureOptions From c96a2a0e86e0b47150414b8717384dcfa3821c48 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Tue, 29 Oct 2024 02:53:30 +0000 Subject: [PATCH 16/16] Remove public API. --- .../PostgresBuilderExtensions.cs | 7 +++---- src/Aspire.Hosting/Codespaces/CodespacesOptions.cs | 2 +- src/Aspire.Hosting/PublicAPI.Unshipped.txt | 8 -------- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs b/src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs index b8a83cb7362..e588c37c517 100644 --- a/src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs +++ b/src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs @@ -4,11 +4,10 @@ using System.Text; using System.Text.Json; using Aspire.Hosting.ApplicationModel; -using Aspire.Hosting.Codespaces; using Aspire.Hosting.Postgres; using Aspire.Hosting.Utils; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; namespace Aspire.Hosting; @@ -339,8 +338,8 @@ private static void SetPgAdminEnvironmentVariables(EnvironmentCallbackContext co // When running in the context of Codespaces we need to set some additional environment // varialbes so that PGAdmin will trust the forwarded headers that Codespaces port // forwarding will send. - var codespaceOptions = context.ExecutionContext.ServiceProvider.GetRequiredService>(); - if (context.ExecutionContext.IsRunMode && codespaceOptions.Value.IsCodespace) + var config = context.ExecutionContext.ServiceProvider.GetRequiredService(); + if (context.ExecutionContext.IsRunMode && config.GetValue("CODESPACES", false)) { context.EnvironmentVariables["PGADMIN_CONFIG_PROXY_X_HOST_COUNT"] = "1"; context.EnvironmentVariables["PGADMIN_CONFIG_PROXY_X_PREFIX_COUNT"] = "1"; diff --git a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs index f9db7fd49b8..8e54dbf6951 100644 --- a/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs +++ b/src/Aspire.Hosting/Codespaces/CodespacesOptions.cs @@ -10,7 +10,7 @@ namespace Aspire.Hosting.Codespaces; /// /// GitHub Codespaces configuration values. /// -public class CodespacesOptions +internal class CodespacesOptions { /// /// When set to true, the app host is running in a GitHub Codespace. diff --git a/src/Aspire.Hosting/PublicAPI.Unshipped.txt b/src/Aspire.Hosting/PublicAPI.Unshipped.txt index 17cf0546025..0c67fb7aaf8 100644 --- a/src/Aspire.Hosting/PublicAPI.Unshipped.txt +++ b/src/Aspire.Hosting/PublicAPI.Unshipped.txt @@ -160,14 +160,6 @@ Aspire.Hosting.ApplicationModel.WaitAnnotation.WaitType.get -> Aspire.Hosting.Ap Aspire.Hosting.ApplicationModel.WaitType Aspire.Hosting.ApplicationModel.WaitType.WaitForCompletion = 1 -> Aspire.Hosting.ApplicationModel.WaitType Aspire.Hosting.ApplicationModel.WaitType.WaitUntilHealthy = 0 -> Aspire.Hosting.ApplicationModel.WaitType -Aspire.Hosting.Codespaces.CodespacesOptions -Aspire.Hosting.Codespaces.CodespacesOptions.CodespaceName.get -> string? -Aspire.Hosting.Codespaces.CodespacesOptions.CodespaceName.set -> void -Aspire.Hosting.Codespaces.CodespacesOptions.CodespacesOptions() -> void -Aspire.Hosting.Codespaces.CodespacesOptions.IsCodespace.get -> bool -Aspire.Hosting.Codespaces.CodespacesOptions.IsCodespace.set -> void -Aspire.Hosting.Codespaces.CodespacesOptions.PortForwardingDomain.get -> string? -Aspire.Hosting.Codespaces.CodespacesOptions.PortForwardingDomain.set -> void Aspire.Hosting.DistributedApplicationBuilder.AppHostPath.get -> string! Aspire.Hosting.DistributedApplicationBuilder.Eventing.get -> Aspire.Hosting.Eventing.IDistributedApplicationEventing! Aspire.Hosting.Eventing.DistributedApplicationEventing