Compare commits
2 Commits
main
...
jkotalik/p
| Author | SHA1 | Date |
|---|---|---|
|
|
4dbbed9c7f | 6 years ago |
|
|
bc379f5e83 | 6 years ago |
6 changed files with 130 additions and 0 deletions
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue