Browse Source

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)
davidfowl/build-earlier
David Fowler 7 years ago
parent
commit
532386a39d
  1. 50
      src/Microsoft.Tye.Core/ApplicationBuilderExtensions.cs
  2. 7
      src/Microsoft.Tye.Core/ApplicationFactory.cs
  3. 27
      src/tye/Program.RunCommand.cs
  4. 2
      test/E2ETest/TyeRunTests.cs

50
src/Microsoft.Tye.Core/ApplicationBuilderExtensions.cs

@ -7,10 +7,8 @@ namespace Microsoft.Tye
{ {
public static class ApplicationBuilderExtensions public static class ApplicationBuilderExtensions
{ {
public static async Task<bool> 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++) for (var i = 0; i < application.Services.Count; i++)
{ {
var service = application.Services[i]; var service = application.Services[i];
@ -20,13 +18,6 @@ namespace Microsoft.Tye
continue; continue;
} }
if (!await ProjectReader.ReadProjectDetailsAsync(output, project, targets))
{
return false;
}
PopulateProjectDefaults(project);
static string DetermineContainerImage(ProjectServiceBuilder project) static string DetermineContainerImage(ProjectServiceBuilder project)
{ {
return $"mcr.microsoft.com/dotnet/core/sdk:{project.TargetFrameworkVersion}"; return $"mcr.microsoft.com/dotnet/core/sdk:{project.TargetFrameworkVersion}";
@ -53,45 +44,6 @@ namespace Microsoft.Tye
application.Services[i] = containerService; application.Services[i] = containerService;
} }
return true;
}
public static async Task<bool> 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"
});
}
} }
} }
} }

7
src/Microsoft.Tye.Core/ApplicationFactory.cs

@ -14,7 +14,7 @@ namespace Microsoft.Tye
{ {
public static class ApplicationFactory public static class ApplicationFactory
{ {
public static async Task<ApplicationBuilder> CreateAsync(OutputContext output, FileInfo source, bool populateProjectInformation = true) public static async Task<ApplicationBuilder> CreateAsync(OutputContext output, FileInfo source, string[]? targets = null)
{ {
if (source is null) if (source is null)
{ {
@ -60,10 +60,7 @@ namespace Microsoft.Tye
project.Args = configService.Args; project.Args = configService.Args;
project.Replicas = configService.Replicas ?? 1; project.Replicas = configService.Replicas ?? 1;
if (populateProjectInformation) await ProjectReader.ReadProjectDetailsAsync(output, project, targets);
{
await ProjectReader.ReadProjectDetailsAsync(output, project);
}
// We don't apply more container defaults here because we might need // We don't apply more container defaults here because we might need
// to prompt for the registry name. // to prompt for the registry name.

27
src/tye/Program.RunCommand.cs

@ -74,23 +74,28 @@ namespace Microsoft.Tye
} }
// Populate project information if docker is false and we're not building // Populate project information if docker is false and we're not building
var populateProjectInformation = nobuild && !docker;
var output = new OutputContext(console, Verbosity.Debug); var output = new OutputContext(console, Verbosity.Debug);
var application = await ApplicationFactory.CreateAsync(output, path, populateProjectInformation);
string[]? targets = null;
if (docker) if (docker)
{ {
if (!await application.TransformProjectsIntoContainersAync(output)) targets = new[] { "Restore", "Publish" };
{ }
return; 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)) application.TransformProjectsIntoContainers();
{
return;
}
} }
await application.ProcessExtensionsAsync(ExtensionContext.OperationKind.LocalRun); await application.ProcessExtensionsAsync(ExtensionContext.OperationKind.LocalRun);

2
test/E2ETest/TyeRunTests.cs

@ -540,7 +540,7 @@ namespace E2ETest
{ {
if (args.Contains("--docker")) if (args.Contains("--docker"))
{ {
await application.TransformProjectsIntoContainersAync(outputContext); application.TransformProjectsIntoContainers();
} }
await using var host = new TyeHost(application.ToHostingApplication(), args) await using var host = new TyeHost(application.ToHostingApplication(), args)

Loading…
Cancel
Save