diff --git a/src/Microsoft.Tye.Core/CombineStep.cs b/src/Microsoft.Tye.Core/CombineStep.cs index 12999fa3..914a923b 100644 --- a/src/Microsoft.Tye.Core/CombineStep.cs +++ b/src/Microsoft.Tye.Core/CombineStep.cs @@ -28,6 +28,7 @@ namespace Microsoft.Tye var port = binding.Port ?? 80; var urls = $"http://*{(port == 80 ? "" : (":" + port.ToString()))}"; service.Service.Environment.Add("ASPNETCORE_URLS", urls); + service.Service.Environment.Add("PORT", port); break; } } diff --git a/src/Microsoft.Tye.Hosting/DockerRunner.cs b/src/Microsoft.Tye.Hosting/DockerRunner.cs index 607bc48a..7c83bfed 100644 --- a/src/Microsoft.Tye.Hosting/DockerRunner.cs +++ b/src/Microsoft.Tye.Hosting/DockerRunner.cs @@ -107,15 +107,26 @@ namespace Microsoft.Tye.Hosting { status.Ports = ports.Select(p => p.Port); - // These ports should also be passed in not assuming ASP.NET Core - environment["ASPNETCORE_URLS"] = string.Join(";", ports.Select(p => $"{p.Protocol ?? "http"}://*:{p.InternalPort ?? p.Port}")); + // These are the ports that the application should use for binding + // 1. Tell the docker container what port to bind to portString = string.Join(" ", ports.Select(p => $"-p {p.Port}:{p.InternalPort ?? p.Port}")); + // 2. Configure ASP.NET Core to bind to those same ports + environment["ASPNETCORE_URLS"] = string.Join(";", ports.Select(p => $"{p.Protocol ?? "http"}://*:{p.InternalPort ?? p.Port}")); + + // Set the HTTPS port for the redirect middleware foreach (var p in ports) { - environment[$"{p.Protocol?.ToUpper() ?? "HTTP"}_PORT"] = p.BindingPort.ToString(); + if (string.Equals(p.Protocol, "https", StringComparison.OrdinalIgnoreCase)) + { + // We need to set the redirect URL to the exposed port so the redirect works cleanly + environment["HTTPS_PORT"] = p.BindingPort.ToString(); + } } + + // 3. For non-ASP.NET Core apps, pass the same information in the PORT env variable as a semicolon separated list. + environment["PORT"] = string.Join(";", ports.Select(p => $"{p.InternalPort ?? p.Port}")); } application.PopulateEnvironment(service, (key, value) => environment[key] = value, "host.docker.internal"); diff --git a/src/Microsoft.Tye.Hosting/ProcessRunner.cs b/src/Microsoft.Tye.Hosting/ProcessRunner.cs index 57ba96e8..e33613d3 100644 --- a/src/Microsoft.Tye.Hosting/ProcessRunner.cs +++ b/src/Microsoft.Tye.Hosting/ProcessRunner.cs @@ -153,13 +153,23 @@ namespace Microsoft.Tye.Hosting if (hasPorts) { - // These ports should also be passed in not assuming ASP.NET Core + // These are the ports that the application should use for binding + + // 1. Configure ASP.NET Core to bind to those same ports environment["ASPNETCORE_URLS"] = string.Join(";", ports.Select(p => $"{p.Protocol ?? "http"}://localhost:{p.Port}")); + // Set the HTTPS port for the redirect middleware foreach (var p in ports) { - environment[$"{p.Protocol?.ToUpper() ?? "HTTP"}_PORT"] = p.BindingPort.ToString(); + if (string.Equals(p.Protocol, "https", StringComparison.OrdinalIgnoreCase)) + { + // We need to set the redirect URL to the exposed port so the redirect works cleanly + environment["HTTPS_PORT"] = p.BindingPort.ToString(); + } } + + // 3. For non-ASP.NET Core apps, pass the same information in the PORT env variable as a semicolon separated list. + environment["PORT"] = string.Join(";", ports.Select(p => $"{p.Port}")); } while (!processInfo.StoppedTokenSource.IsCancellationRequested) diff --git a/src/Microsoft.Tye.Hosting/ProxyService.cs b/src/Microsoft.Tye.Hosting/ProxyService.cs index 0899e7ae..4cc888d3 100644 --- a/src/Microsoft.Tye.Hosting/ProxyService.cs +++ b/src/Microsoft.Tye.Hosting/ProxyService.cs @@ -69,6 +69,15 @@ namespace Microsoft.Tye.Hosting binding.Port = GetNextPort(); } + if (binding.Protocol == "http" || binding.Protocol == null) + { + binding.InternalPort = 80; + } + else if (binding.Protocol == "https") + { + binding.InternalPort = 443; + } + if (service.Description.Replicas == 1) { // No need to proxy diff --git a/src/Microsoft.Tye.Hosting/TyeDashboardApi.cs b/src/Microsoft.Tye.Hosting/TyeDashboardApi.cs index 1ebb1371..5f2db966 100644 --- a/src/Microsoft.Tye.Hosting/TyeDashboardApi.cs +++ b/src/Microsoft.Tye.Hosting/TyeDashboardApi.cs @@ -164,11 +164,26 @@ namespace Microsoft.Tye.Hosting var replicateDictionary = new Dictionary(); foreach (var replica in service.Replicas) { - replicateDictionary[replica.Key] = new V1ReplicaStatus() + var replicaStatus = new V1ReplicaStatus() { Name = replica.Value.Name, - Ports = replica.Value.Ports + Ports = replica.Value.Ports, }; + + replicateDictionary[replica.Key] = replicaStatus; + + if (replica.Value is ProcessStatus processStatus) + { + replicaStatus.Pid = processStatus.Pid; + replicaStatus.ExitCode = processStatus.ExitCode; + replicaStatus.Environment = processStatus.Environment; + } + else if (replica.Value is DockerStatus dockerStatus) + { + replicaStatus.DockerCommand = dockerStatus.DockerCommand; + replicaStatus.DockerLogsPid = dockerStatus.DockerLogsPid; + replicaStatus.ContainerId = dockerStatus.ContainerId; + } } var v1Status = new V1ServiceStatus()