Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Add push command #365

Merged
merged 1 commit into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions src/tye/Program.PushCommand.cs
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions src/tye/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static Task<int> Main(string[] args)
command.AddCommand(CreateGenerateCommand());
command.AddCommand(CreateRunCommand(args));
command.AddCommand(CreateBuildCommand());
command.AddCommand(CreatePushCommand());
command.AddCommand(CreateDeployCommand());

// Show commandline help unless a subcommand was used.
Expand Down