From 532386a39d00a5b5d6575c08d12a2048924aa177 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 5 Apr 2020 15:24:16 -0700 Subject: [PATCH] Do msbuild things once - This is a WIP to figure out if this pattern makes sense. Consolidate the msbuild operations into a single place - Move transform projects into containers to the applicationbuilder stage. - Dump out lots of debug information before running (temporary) --- .../ApplicationBuilderExtensions.cs | 50 +------------------ src/Microsoft.Tye.Core/ApplicationFactory.cs | 7 +-- src/tye/Program.RunCommand.cs | 27 ++++++---- test/E2ETest/TyeRunTests.cs | 2 +- 4 files changed, 20 insertions(+), 66 deletions(-) diff --git a/src/Microsoft.Tye.Core/ApplicationBuilderExtensions.cs b/src/Microsoft.Tye.Core/ApplicationBuilderExtensions.cs index e38a36e7..b099321e 100644 --- a/src/Microsoft.Tye.Core/ApplicationBuilderExtensions.cs +++ b/src/Microsoft.Tye.Core/ApplicationBuilderExtensions.cs @@ -7,10 +7,8 @@ namespace Microsoft.Tye { public static class ApplicationBuilderExtensions { - public static async Task TransformProjectsIntoContainersAync(this ApplicationBuilder application, OutputContext output) + public static void TransformProjectsIntoContainers(this ApplicationBuilder application) { - var targets = new[] { "Restore", "Publish" }; - for (var i = 0; i < application.Services.Count; i++) { var service = application.Services[i]; @@ -20,13 +18,6 @@ namespace Microsoft.Tye continue; } - if (!await ProjectReader.ReadProjectDetailsAsync(output, project, targets)) - { - return false; - } - - PopulateProjectDefaults(project); - static string DetermineContainerImage(ProjectServiceBuilder project) { return $"mcr.microsoft.com/dotnet/core/sdk:{project.TargetFrameworkVersion}"; @@ -53,45 +44,6 @@ namespace Microsoft.Tye application.Services[i] = containerService; } - - return true; - } - - public static async Task BuildProjectsAsync(this ApplicationBuilder application, OutputContext output) - { - var targets = new string[] { "Restore", "Build" }; - foreach (var service in application.Services) - { - if (service is ProjectServiceBuilder project) - { - if (!await ProjectReader.ReadProjectDetailsAsync(output, project, targets)) - { - return false; - } - - PopulateProjectDefaults(project); - } - } - - return true; - } - - private static void PopulateProjectDefaults(ProjectServiceBuilder project) - { - if (project.Bindings.Count == 0 && project.IsAspNet) - { - // HTTP is the default binding - project.Bindings.Add(new BindingBuilder() - { - Protocol = "http" - }); - - project.Bindings.Add(new BindingBuilder() - { - Name = "https", - Protocol = "https" - }); - } } } } diff --git a/src/Microsoft.Tye.Core/ApplicationFactory.cs b/src/Microsoft.Tye.Core/ApplicationFactory.cs index 96322280..5d4d24b0 100644 --- a/src/Microsoft.Tye.Core/ApplicationFactory.cs +++ b/src/Microsoft.Tye.Core/ApplicationFactory.cs @@ -14,7 +14,7 @@ namespace Microsoft.Tye { public static class ApplicationFactory { - public static async Task CreateAsync(OutputContext output, FileInfo source, bool populateProjectInformation = true) + public static async Task CreateAsync(OutputContext output, FileInfo source, string[]? targets = null) { if (source is null) { @@ -60,10 +60,7 @@ namespace Microsoft.Tye project.Args = configService.Args; project.Replicas = configService.Replicas ?? 1; - if (populateProjectInformation) - { - await ProjectReader.ReadProjectDetailsAsync(output, project); - } + await ProjectReader.ReadProjectDetailsAsync(output, project, targets); // We don't apply more container defaults here because we might need // to prompt for the registry name. diff --git a/src/tye/Program.RunCommand.cs b/src/tye/Program.RunCommand.cs index 77f6e456..42372a5c 100644 --- a/src/tye/Program.RunCommand.cs +++ b/src/tye/Program.RunCommand.cs @@ -74,23 +74,28 @@ namespace Microsoft.Tye } // Populate project information if docker is false and we're not building - var populateProjectInformation = nobuild && !docker; var output = new OutputContext(console, Verbosity.Debug); - var application = await ApplicationFactory.CreateAsync(output, path, populateProjectInformation); + + string[]? targets = null; if (docker) { - if (!await application.TransformProjectsIntoContainersAync(output)) - { - return; - } + targets = new[] { "Restore", "Publish" }; + } + else if (nobuild) + { + targets = null; + } + else + { + targets = new[] { "Restore", "Build" }; } - else if (!populateProjectInformation) + + var application = await ApplicationFactory.CreateAsync(output, path, targets); + + if (docker) { - if (!await application.BuildProjectsAsync(output)) - { - return; - } + application.TransformProjectsIntoContainers(); } await application.ProcessExtensionsAsync(ExtensionContext.OperationKind.LocalRun); diff --git a/test/E2ETest/TyeRunTests.cs b/test/E2ETest/TyeRunTests.cs index d38e71b1..5000adb8 100644 --- a/test/E2ETest/TyeRunTests.cs +++ b/test/E2ETest/TyeRunTests.cs @@ -540,7 +540,7 @@ namespace E2ETest { if (args.Contains("--docker")) { - await application.TransformProjectsIntoContainersAync(outputContext); + application.TransformProjectsIntoContainers(); } await using var host = new TyeHost(application.ToHostingApplication(), args)