mirror of https://github.com/dotnet/tye.git
committed by
Ryan Nowak
2 changed files with 77 additions and 0 deletions
@ -0,0 +1,76 @@ |
|||
// 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.
|
|||
|
|||
using System.Collections.Generic; |
|||
using System.CommandLine; |
|||
using System.CommandLine.Invocation; |
|||
using System.IO; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Tye.ConfigModel; |
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
static partial class Program |
|||
{ |
|||
public static Command CreatePushCommand() |
|||
{ |
|||
var command = new Command("push", "build and push application containers to registry") |
|||
{ |
|||
CommonArguments.Path_Required, |
|||
StandardOptions.Interactive, |
|||
StandardOptions.Verbosity, |
|||
}; |
|||
|
|||
command.AddOption(new Option(new[] { "-f", "--force" }) |
|||
{ |
|||
Description = "Override validation and force push.", |
|||
Required = false |
|||
}); |
|||
|
|||
command.Handler = CommandHandler.Create<IConsole, FileInfo, Verbosity, bool, bool>(async (console, path, verbosity, interactive, force) => |
|||
{ |
|||
// Workaround for https://github.com/dotnet/command-line-api/issues/723#issuecomment-593062654
|
|||
if (path is null) |
|||
{ |
|||
throw new CommandException("No project or solution file was found."); |
|||
} |
|||
|
|||
var output = new OutputContext(console, verbosity); |
|||
|
|||
output.WriteInfoLine("Loading Application Details..."); |
|||
var application = await ApplicationFactory.CreateAsync(output, path); |
|||
if (application.Services.Count == 0) |
|||
{ |
|||
throw new CommandException($"No services found in \"{application.Source.Name}\""); |
|||
} |
|||
|
|||
await ExecutePushAsync(new OutputContext(console, verbosity), application, environment: "production", interactive, force); |
|||
}); |
|||
|
|||
return command; |
|||
} |
|||
|
|||
private static async Task ExecutePushAsync(OutputContext output, ApplicationBuilder application, string environment, bool interactive, bool force) |
|||
{ |
|||
await application.ProcessExtensionsAsync(ExtensionContext.OperationKind.Deploy); |
|||
|
|||
var steps = new List<ServiceExecutor.Step>() |
|||
{ |
|||
new CombineStep() { Environment = environment, }, |
|||
new PublishProjectStep(), |
|||
new BuildDockerImageStep() { Environment = environment, }, |
|||
new PushDockerImageStep() { Environment = environment, }, |
|||
}; |
|||
|
|||
ApplyRegistryAndDefaults(output, application, interactive, requireRegistry: true); |
|||
|
|||
var executor = new ServiceExecutor(output, application, steps); |
|||
foreach (var service in application.Services) |
|||
{ |
|||
await executor.ExecuteAsync(service); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue