This repository has been archived by the owner on Nov 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters