Compare commits

...

2 Commits

Author SHA1 Message Date
Justin Kotalik 4dbbed9c7f Update manifest 6 years ago
Justin Kotalik bc379f5e83 Start of support for porter for CNAB 6 years ago
  1. 6
      src/Microsoft.Tye.Core/ApplicationExecutor.cs
  2. 1
      src/Microsoft.Tye.Core/DeployApplicationKubernetesManifestStep.cs
  3. 61
      src/Microsoft.Tye.Core/PorterManifestGenerator.cs
  4. 32
      src/Microsoft.Tye.Core/PorterPublisher.cs
  5. 26
      src/Microsoft.Tye.Core/PublishPorterStep.cs
  6. 4
      src/tye/Program.PushCommand.cs

6
src/Microsoft.Tye.Core/ApplicationExecutor.cs

@ -27,6 +27,8 @@ namespace Microsoft.Tye
public async Task ExecuteAsync(ApplicationBuilder application) public async Task ExecuteAsync(ApplicationBuilder application)
{ {
var serviceOutputs = new List<ServiceOutput>();
foreach (var service in application.Services) foreach (var service in application.Services)
{ {
using var tracker = output.BeginStep($"Processing Service '{service.Name}'..."); using var tracker = output.BeginStep($"Processing Service '{service.Name}'...");
@ -36,9 +38,12 @@ namespace Microsoft.Tye
await step.ExecuteAsync(output, application, service); await step.ExecuteAsync(output, application, service);
stepTracker.MarkComplete(); stepTracker.MarkComplete();
} }
serviceOutputs.AddRange(service.Outputs);
tracker.MarkComplete(); tracker.MarkComplete();
} }
var ingressOutputs = new List<IngressOutput>();
foreach (var ingress in application.Ingress) foreach (var ingress in application.Ingress)
{ {
using var tracker = output.BeginStep($"Processing Ingress '{ingress.Name}'..."); using var tracker = output.BeginStep($"Processing Ingress '{ingress.Name}'...");
@ -48,6 +53,7 @@ namespace Microsoft.Tye
await step.ExecuteAsync(output, application, ingress); await step.ExecuteAsync(output, application, ingress);
stepTracker.MarkComplete(); stepTracker.MarkComplete();
} }
ingressOutputs.AddRange(ingress.Outputs);
tracker.MarkComplete(); tracker.MarkComplete();
} }

1
src/Microsoft.Tye.Core/DeployApplicationKubernetesManifestStep.cs

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.CommandLine.Invocation; using System.CommandLine.Invocation;
using System.IO; using System.IO;
using System.Text; using System.Text;

61
src/Microsoft.Tye.Core/PorterManifestGenerator.cs

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Tye;
using YamlDotNet.RepresentationModel;
namespace Microsoft.Tye
{
public class PorterManifestGenerator
{
public static YamlDocument CreatePorterManifest(OutputContext output, IEnumerable<DockerImageOutput> dockerImages, ApplicationBuilder application)
{
// write to temp directory for this step, make sure we allow generating to current directory
var root = new YamlMappingNode();
root.Add("name", application.Name);
root.Add("description", "test");
// TODO versioning
root.Add("version", "0.1.0");
root.Add("tag", $"{application.Registry}/{application.Name}:0.1.0");
if (dockerImages.Count() > 0)
{
var images = new YamlMappingNode();
root.Add("images", images);
foreach (var image in dockerImages)
{
var mapping = new YamlMappingNode();
images.Add(image.ImageName, mapping);
mapping.Add("imageType", "docker");
mapping.Add("repository", image.ImageName); // TODO may need repository here.
mapping.Add("tag", image.ImageTag);
}
}
var mixins = new YamlSequenceNode();
root.Add("mixins", mixins);
mixins.Add("exec");
var installSeq = new YamlSequenceNode();
root.Add("install", installSeq);
var installExec = new YamlMappingNode();
installSeq.Add(installExec);
var args = new YamlMappingNode();
installExec.Add("exec", args);
args.Add("command", "ls");
args.Add("description", "ls");
//root.Add("upgrade", "");
var uninstallSeq = new YamlSequenceNode();
root.Add("uninstall", uninstallSeq);
var uninstallExec = new YamlMappingNode();
uninstallSeq.Add(uninstallExec);
var unargs = new YamlMappingNode();
uninstallExec.Add("exec", unargs);
unargs.Add("command", "ls");
unargs.Add("description", "ls");
return new YamlDocument(root);
}
}
}

32
src/Microsoft.Tye.Core/PorterPublisher.cs

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using YamlDotNet.RepresentationModel;
namespace Microsoft.Tye
{
public static class PorterPublisher
{
public static async Task PublishAsync(OutputContext output, YamlDocument document, ApplicationBuilder builder)
{
using var tempFile = TempFile.Create();
{
await using var stream = File.OpenWrite(tempFile.FilePath);
await using var writer = new StreamWriter(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), leaveOpen: true);
var yamlStream = new YamlStream(document);
yamlStream.Save(writer, assignAnchors: false);
}
var res = await ProcessUtil.RunAsync("porter", $"publish -f {tempFile.FilePath}", throwOnError: false);
if (res.ExitCode != 0)
{
output.WriteInfoLine(res.StandardError);
output.WriteInfoLine(res.StandardOutput);
}
}
}
}

26
src/Microsoft.Tye.Core/PublishPorterStep.cs

@ -0,0 +1,26 @@
// 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.Linq;
using System.Threading.Tasks;
namespace Microsoft.Tye
{
public class PublishPorterStep : ApplicationExecutor.ApplicationStep
{
public override string DisplayText => "Publishing Porter Bundle ...";
public string Environment { get; set; } = "production";
public override async Task ExecuteAsync(OutputContext output, ApplicationBuilder application)
{
var dockerImages = application.Services.SelectMany(s => s.Outputs.OfType<DockerImageOutput>());
// TODO Check if existing porter.yaml file exists.
var document = PorterManifestGenerator.CreatePorterManifest(output, dockerImages, application);
await PorterPublisher.PublishAsync(output, document, application);
}
}
}

4
src/tye/Program.PushCommand.cs

@ -64,6 +64,10 @@ namespace Microsoft.Tye
new BuildDockerImageStep() { Environment = environment, }, new BuildDockerImageStep() { Environment = environment, },
new PushDockerImageStep() { Environment = environment, }, new PushDockerImageStep() { Environment = environment, },
}, },
ApplicationSteps =
{
new PublishPorterStep()
}
}; };
await executor.ExecuteAsync(application); await executor.ExecuteAsync(application);

Loading…
Cancel
Save