From 765575313dadec4dbde8b053ca2f98acc4227b47 Mon Sep 17 00:00:00 2001 From: Phillip Hoff Date: Fri, 23 Jul 2021 10:10:27 -0700 Subject: [PATCH] Sketch enabling debugging and pushing metadata to clients. --- src/Microsoft.Tye.Core/ApplicationFactory.cs | 8 +++++++- src/Microsoft.Tye.Core/BindingBuilder.cs | 3 ++- src/Microsoft.Tye.Core/NodeServiceBuilder.cs | 2 +- src/Microsoft.Tye.Hosting/Model/NodeRunInfo.cs | 17 +++++++++++++++++ .../Model/V1/V1RunInfoType.cs | 3 ++- src/Microsoft.Tye.Hosting/ProcessRunner.cs | 10 +++++++++- src/Microsoft.Tye.Hosting/TyeDashboardApi.cs | 6 ++++++ src/tye/ApplicationBuilderExtensions.cs | 5 ++--- 8 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 src/Microsoft.Tye.Hosting/Model/NodeRunInfo.cs diff --git a/src/Microsoft.Tye.Core/ApplicationFactory.cs b/src/Microsoft.Tye.Core/ApplicationFactory.cs index 52d63cc9..b560194b 100644 --- a/src/Microsoft.Tye.Core/ApplicationFactory.cs +++ b/src/Microsoft.Tye.Core/ApplicationFactory.cs @@ -343,11 +343,17 @@ namespace Microsoft.Tye var node = new NodeServiceBuilder(configService.Name, packagePath, ServiceSource.Configuration) { - EnableDebugging = configService.Node.EnableDebugging, + EnableDebugging = !configService.Node.EnableDebugging.HasValue || configService.Node.EnableDebugging.Value, Replicas = configService.Replicas ?? 1, Script = configService.Node.Script }; + // If debugging but no explicit binding to the Node.js inspector port has been defined, add one... + if (node.EnableDebugging && !node.Bindings.Any(binding => StringComparer.OrdinalIgnoreCase.Equals(binding.Protocol, "inspector"))) + { + node.Bindings.Add(new BindingBuilder { Protocol = "inspector" }); + } + service = node; } else diff --git a/src/Microsoft.Tye.Core/BindingBuilder.cs b/src/Microsoft.Tye.Core/BindingBuilder.cs index 8e795075..202710f2 100644 --- a/src/Microsoft.Tye.Core/BindingBuilder.cs +++ b/src/Microsoft.Tye.Core/BindingBuilder.cs @@ -4,7 +4,8 @@ namespace Microsoft.Tye { - public sealed class BindingBuilder + public sealed class + BindingBuilder { public string? Name { get; set; } public string? ConnectionString { get; set; } diff --git a/src/Microsoft.Tye.Core/NodeServiceBuilder.cs b/src/Microsoft.Tye.Core/NodeServiceBuilder.cs index f2a42354..bb9c16cd 100644 --- a/src/Microsoft.Tye.Core/NodeServiceBuilder.cs +++ b/src/Microsoft.Tye.Core/NodeServiceBuilder.cs @@ -14,7 +14,7 @@ namespace Microsoft.Tye PackagePath = packagePath; } - public bool? EnableDebugging { get; set; } + public bool EnableDebugging { get; set; } = true; public string PackagePath { get; set; } diff --git a/src/Microsoft.Tye.Hosting/Model/NodeRunInfo.cs b/src/Microsoft.Tye.Hosting/Model/NodeRunInfo.cs new file mode 100644 index 00000000..e9f10bad --- /dev/null +++ b/src/Microsoft.Tye.Hosting/Model/NodeRunInfo.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Microsoft.Tye.Hosting.Model +{ + public class NodeRunInfo : ExecutableRunInfo + { + public NodeRunInfo(string executable, string? workingDirectory, string? args, bool enableDebugging) + : base(executable, workingDirectory, args) + { + EnableDebugging = enableDebugging; + } + + public bool EnableDebugging { get; } + } +} diff --git a/src/Microsoft.Tye.Hosting/Model/V1/V1RunInfoType.cs b/src/Microsoft.Tye.Hosting/Model/V1/V1RunInfoType.cs index 66d53359..10d337a7 100644 --- a/src/Microsoft.Tye.Hosting/Model/V1/V1RunInfoType.cs +++ b/src/Microsoft.Tye.Hosting/Model/V1/V1RunInfoType.cs @@ -8,6 +8,7 @@ namespace Microsoft.Tye.Hosting.Model.V1 { Project, Executable, - Docker + Docker, + Node } } diff --git a/src/Microsoft.Tye.Hosting/ProcessRunner.cs b/src/Microsoft.Tye.Hosting/ProcessRunner.cs index 57920dad..811fe32e 100644 --- a/src/Microsoft.Tye.Hosting/ProcessRunner.cs +++ b/src/Microsoft.Tye.Hosting/ProcessRunner.cs @@ -233,7 +233,8 @@ namespace Microsoft.Tye.Hosting } // 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}")); + var webPorts = ports.Where(port => StringComparer.OrdinalIgnoreCase.Equals(port.Protocol, "http") || StringComparer.OrdinalIgnoreCase.Equals(port.Protocol, "https")); + environment["PORT"] = string.Join(";", webPorts.Select(p => $"{p.Port}")); if (service.ServiceType == ServiceType.Function) { @@ -245,6 +246,13 @@ namespace Microsoft.Tye.Hosting copiedArgs += " --useHttps"; } } + + if (service.Description.RunInfo is NodeRunInfo info && info.EnableDebugging) + { + var binding = ports.First(port => StringComparer.OrdinalIgnoreCase.Equals(port.Protocol, "inspector")); + + copiedArgs = $"--inspect={binding.Port} {copiedArgs}"; + } } var backOff = TimeSpan.FromSeconds(5); diff --git a/src/Microsoft.Tye.Hosting/TyeDashboardApi.cs b/src/Microsoft.Tye.Hosting/TyeDashboardApi.cs index 6f7caa92..1cff76d2 100644 --- a/src/Microsoft.Tye.Hosting/TyeDashboardApi.cs +++ b/src/Microsoft.Tye.Hosting/TyeDashboardApi.cs @@ -167,6 +167,12 @@ namespace Microsoft.Tye.Hosting v1RunInfo.WorkingDirectory = dockerRunInfo.WorkingDirectory; v1RunInfo.Args = dockerRunInfo.Args; break; + case NodeRunInfo nodeRunInfo: + v1RunInfo.Type = V1RunInfoType.Node; + v1RunInfo.Args = nodeRunInfo.Args; + v1RunInfo.Executable = nodeRunInfo.Executable; + v1RunInfo.WorkingDirectory = nodeRunInfo.WorkingDirectory; + break; case ExecutableRunInfo executableRunInfo: v1RunInfo.Type = V1RunInfoType.Executable; v1RunInfo.Args = executableRunInfo.Args; diff --git a/src/tye/ApplicationBuilderExtensions.cs b/src/tye/ApplicationBuilderExtensions.cs index 3a11e4ae..b044edd4 100644 --- a/src/tye/ApplicationBuilderExtensions.cs +++ b/src/tye/ApplicationBuilderExtensions.cs @@ -169,10 +169,9 @@ namespace Microsoft.Tye var main = mainNode.Value; - string enableDebuggingArg = !node.EnableDebugging.HasValue || node.EnableDebugging.Value ? "--inspect ": ""; - string args = $"{enableDebuggingArg}{main}"; + string args = $"{main}"; - runInfo = new ExecutableRunInfo(executablePath, workingDirectory, args); + runInfo = new NodeRunInfo(executablePath, workingDirectory, args, node.EnableDebugging); replicas = node.Replicas; liveness = null; readiness = null;