Browse Source

add push command

pull/368/head
Stafford Williams 6 years ago
committed by Ryan Nowak
parent
commit
255d9d6637
  1. 76
      src/tye/Program.PushCommand.cs
  2. 1
      src/tye/Program.cs

76
src/tye/Program.PushCommand.cs

@ -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);
}
}
}
}

1
src/tye/Program.cs

@ -27,6 +27,7 @@ namespace Microsoft.Tye
command.AddCommand(CreateGenerateCommand());
command.AddCommand(CreateRunCommand(args));
command.AddCommand(CreateBuildCommand());
command.AddCommand(CreatePushCommand());
command.AddCommand(CreateDeployCommand());
// Show commandline help unless a subcommand was used.

Loading…
Cancel
Save