mirror of https://github.com/dotnet/tye.git
committed by
GitHub
16 changed files with 0 additions and 526 deletions
@ -1,15 +0,0 @@ |
|||
// 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.
|
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
public sealed class ApplicationGlobals |
|||
{ |
|||
public DeploymentKind DeploymentKind { get; set; } = DeploymentKind.Kubernetes; |
|||
|
|||
public string? Name { get; set; } |
|||
|
|||
public ContainerRegistry? Registry { get; set; } |
|||
} |
|||
} |
|||
@ -1,85 +0,0 @@ |
|||
// 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; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
internal static class DirectorySearch |
|||
{ |
|||
public static string? AscendingSearch(string directoryPath, string fileName) |
|||
{ |
|||
if (directoryPath is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(directoryPath)); |
|||
} |
|||
|
|||
if (fileName is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(fileName)); |
|||
} |
|||
|
|||
var directory = new DirectoryInfo(directoryPath); |
|||
|
|||
while (true) |
|||
{ |
|||
var filePath = Path.Combine(directory.FullName, fileName); |
|||
if (File.Exists(filePath)) |
|||
{ |
|||
return filePath; |
|||
} |
|||
|
|||
if (directory == directory.Root) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
if (directory.Parent == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
directory = directory.Parent; |
|||
} |
|||
} |
|||
|
|||
public static IEnumerable<FileInfo> AscendingWildcardSearch(string directoryPath, string searchPattern) |
|||
{ |
|||
if (directoryPath is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(directoryPath)); |
|||
} |
|||
|
|||
if (searchPattern is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(searchPattern)); |
|||
} |
|||
|
|||
var directory = new DirectoryInfo(directoryPath); |
|||
|
|||
while (true) |
|||
{ |
|||
if (directory.EnumerateFiles(searchPattern).Any()) |
|||
{ |
|||
return directory.EnumerateFiles(searchPattern); |
|||
} |
|||
|
|||
if (directory == directory.Root) |
|||
{ |
|||
return Array.Empty<FileInfo>(); |
|||
} |
|||
|
|||
if (directory.Parent == null) |
|||
{ |
|||
return Array.Empty<FileInfo>(); |
|||
} |
|||
|
|||
directory = directory.Parent; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
// 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; |
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
public class EnvironmentAttribute : Attribute |
|||
{ |
|||
public EnvironmentAttribute(string environmentName) |
|||
{ |
|||
if (environmentName is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(environmentName)); |
|||
} |
|||
|
|||
EnvironmentName = environmentName; |
|||
} |
|||
|
|||
public string EnvironmentName { get; } |
|||
} |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
// 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.
|
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
public static class Environments |
|||
{ |
|||
public const string Development = "Development"; |
|||
|
|||
public const string Production = "Production"; |
|||
} |
|||
} |
|||
@ -1,11 +0,0 @@ |
|||
// 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.
|
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
public sealed class GeneratedAssets |
|||
{ |
|||
public ContainerInfo? Container { get; set; } |
|||
} |
|||
} |
|||
@ -1,82 +0,0 @@ |
|||
// 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; |
|||
using System.CommandLine.Invocation; |
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
internal static class HelmChartBuilder |
|||
{ |
|||
public static async Task BuildHelmChartAsync(OutputContext output, ApplicationBuilder application, ProjectServiceBuilder project, ContainerInfo container, HelmChartStep chart) |
|||
{ |
|||
if (output is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(output)); |
|||
} |
|||
|
|||
if (application is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(application)); |
|||
} |
|||
|
|||
if (project is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(project)); |
|||
} |
|||
|
|||
if (container is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(container)); |
|||
} |
|||
|
|||
if (chart is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(chart)); |
|||
} |
|||
|
|||
var projectDirectory = project.ProjectFile.DirectoryName; |
|||
var outputDirectoryPath = Path.Combine(projectDirectory, "bin"); |
|||
using var tempDirectory = TempDirectory.Create(); |
|||
|
|||
HelmChartGenerator.ApplyHelmChartDefaults(application, project, container, chart); |
|||
|
|||
var chartRoot = Path.Combine(projectDirectory, "charts"); |
|||
var chartPath = Path.Combine(chartRoot, chart.ChartName); |
|||
|
|||
output.WriteDebugLine($"Looking for existing chart in '{chartPath}'."); |
|||
if (Directory.Exists(chartPath)) |
|||
{ |
|||
output.WriteDebugLine($"Found existing chart in '{chartPath}'."); |
|||
} |
|||
else |
|||
{ |
|||
chartRoot = tempDirectory.DirectoryPath; |
|||
chartPath = Path.Combine(chartRoot, chart.ChartName); |
|||
output.WriteDebugLine($"Generating chart in '{chartPath}'."); |
|||
await HelmChartGenerator.GenerateAsync(output, application, project, container, chart, new DirectoryInfo(tempDirectory.DirectoryPath)); |
|||
} |
|||
|
|||
output.WriteDebugLine("Running 'helm package'."); |
|||
output.WriteCommandLine("helm", $"package -d \"{outputDirectoryPath}\" --version {project.Version.Replace('+', '-')} --app-version {project.Version.Replace('+', '-')}"); |
|||
var capture = output.Capture(); |
|||
var exitCode = await Process.ExecuteAsync( |
|||
"helm", |
|||
$"package . -d \"{outputDirectoryPath}\" --version {project.Version.Replace('+', '-')} --app-version {project.Version.Replace('+', '-')}", |
|||
workingDir: chartPath, |
|||
stdOut: capture.StdOut, |
|||
stdErr: capture.StdErr); |
|||
|
|||
output.WriteDebugLine($"Running 'helm package' exit code: {exitCode}"); |
|||
if (exitCode != 0) |
|||
{ |
|||
throw new CommandException("Running 'helm package' failed."); |
|||
} |
|||
|
|||
output.WriteInfoLine($"Created Helm Chart: {Path.Combine(outputDirectoryPath, chart.ChartName + "-" + project.Version.Replace('+', '-') + ".tgz")}"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,56 +0,0 @@ |
|||
// 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; |
|||
using System.CommandLine.Invocation; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
internal static class HelmPush |
|||
{ |
|||
public static async Task ExecuteAsync(OutputContext output, string registryHostname, string chartFilePath) |
|||
{ |
|||
if (output is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(output)); |
|||
} |
|||
|
|||
if (registryHostname is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(registryHostname)); |
|||
} |
|||
|
|||
if (chartFilePath is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(chartFilePath)); |
|||
} |
|||
|
|||
// NOTE: this is currently hardcoded to use ACR and uses the azure CLI to do
|
|||
// the push operation. Helm 3 has support for pushing to OCI repositories,
|
|||
// but it's not documented that it works yet for azure.
|
|||
if (!registryHostname.EndsWith(".azurecr.io")) |
|||
{ |
|||
throw new CommandException("Currently pushing of helm charts is limited to '*.azurecr.io'."); |
|||
} |
|||
|
|||
var registryName = registryHostname.Substring(0, registryHostname.Length - ".azurecr.io".Length); |
|||
|
|||
output.WriteDebugLine("Running 'az acr helm push'."); |
|||
output.WriteCommandLine("az", $"acr helm push --name {registryName} \"{chartFilePath}\""); |
|||
var capture = output.Capture(); |
|||
var exitCode = await Process.ExecuteAsync( |
|||
$"az", |
|||
$"acr helm push --name {registryName} \"{chartFilePath}\"", |
|||
stdOut: capture.StdOut, |
|||
stdErr: capture.StdErr); |
|||
|
|||
output.WriteDebugLine($"Done running 'az acr helm push' exit code: {exitCode}"); |
|||
if (exitCode != 0) |
|||
{ |
|||
throw new CommandException("'az acr helm push' failed."); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
// 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; |
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
public static class NameSanitizer |
|||
{ |
|||
// Converts an arbitrary string into something usable as a C# identifier.
|
|||
//
|
|||
// For instance the project file might be `test-project.csproj` but `test-project` is
|
|||
// not what will appear in `launchSettings.json`. We need to convert to
|
|||
// `test_project`
|
|||
public static string SanitizeToIdentifier(string name) |
|||
{ |
|||
if (name is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(name)); |
|||
} |
|||
|
|||
// This is not perfect. For now it just handles cases we've encountered.
|
|||
return name.Replace("-", "_"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,36 +0,0 @@ |
|||
// 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; |
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
internal static class Names |
|||
{ |
|||
public static string NormalizeToDns(string name) |
|||
{ |
|||
if (name is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(name)); |
|||
} |
|||
|
|||
name = name.ToLowerInvariant(); |
|||
name = name.Replace('.', '-'); |
|||
name = name.Replace('_', '-'); |
|||
return name; |
|||
} |
|||
|
|||
public static string NormalizeToFriendly(string name) |
|||
{ |
|||
if (name is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(name)); |
|||
} |
|||
|
|||
name = name.Replace('.', '_'); |
|||
name = name.Replace('-', '_'); |
|||
return name; |
|||
} |
|||
} |
|||
} |
|||
@ -1,80 +0,0 @@ |
|||
// 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; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using YamlDotNet.RepresentationModel; |
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
internal static class OamApplicationGenerator |
|||
{ |
|||
public static Task WriteOamApplicationAsync(TextWriter writer, OutputContext output, ApplicationBuilder application, string environment) |
|||
{ |
|||
if (writer is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(writer)); |
|||
} |
|||
|
|||
if (output is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(output)); |
|||
} |
|||
|
|||
if (application is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(application)); |
|||
} |
|||
|
|||
if (environment is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(environment)); |
|||
} |
|||
|
|||
var componentManifests = new List<OamComponentOutput>(); |
|||
var documents = new List<YamlDocument>(); |
|||
|
|||
foreach (var service in application.Services) |
|||
{ |
|||
componentManifests.AddRange(service.Outputs.OfType<OamComponentOutput>()); |
|||
} |
|||
|
|||
var root = new YamlMappingNode(); |
|||
|
|||
root.Add("kind", "ApplicationConfiguration"); |
|||
root.Add("apiVersion", "core.oam.dev/v1alpha1"); |
|||
|
|||
var metadata = new YamlMappingNode(); |
|||
root.Add("metadata", metadata); |
|||
metadata.Add("name", application.Name); |
|||
|
|||
var spec = new YamlMappingNode(); |
|||
root.Add("spec", spec); |
|||
|
|||
var components = new YamlSequenceNode(); |
|||
spec.Add("components", components); |
|||
|
|||
foreach (var manifest in componentManifests) |
|||
{ |
|||
documents.Add(manifest.Yaml); |
|||
|
|||
var component = new YamlMappingNode(); |
|||
components.Add(component); |
|||
|
|||
component.Add("componentName", manifest.Name); |
|||
component.Add("instanceName", $"{environment.ToLowerInvariant()}-{manifest.Name}"); |
|||
} |
|||
|
|||
documents.Add(new YamlDocument(root)); |
|||
|
|||
var stream = new YamlStream(documents.ToArray()); |
|||
stream.Save(writer, assignAnchors: false); |
|||
|
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
// 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; |
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
public sealed class PipelineHolder |
|||
{ |
|||
public PipelineHolder(Pipeline pipeline) |
|||
{ |
|||
if (pipeline is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(pipeline)); |
|||
} |
|||
|
|||
__Pipeline = pipeline; |
|||
} |
|||
|
|||
public Pipeline __Pipeline { get; } |
|||
} |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
// 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.
|
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
static class Program |
|||
{ |
|||
public static void Main() |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,21 +0,0 @@ |
|||
// 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.
|
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
public class ServiceBinding |
|||
{ |
|||
public ServiceBinding(string name) |
|||
{ |
|||
Name = name; |
|||
} |
|||
|
|||
public string Name { get; } |
|||
public string? Host { get; set; } |
|||
public string? Protocol { get; set; } |
|||
public int? Port { get; set; } |
|||
public string? ConnectionString { get; set; } |
|||
public Secret? Secret { get; set; } |
|||
} |
|||
} |
|||
@ -1,11 +0,0 @@ |
|||
// 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.
|
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
internal class StepView |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -1,29 +0,0 @@ |
|||
// 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.IO; |
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
internal static class Templates |
|||
{ |
|||
public static string RootDirectoryPath |
|||
{ |
|||
get |
|||
{ |
|||
return Path.Combine( |
|||
Path.GetDirectoryName(typeof(HelmChartGenerator).Assembly.Location)!, |
|||
"Templates"); |
|||
} |
|||
} |
|||
|
|||
public static string HelmChartsDirectoryPath |
|||
{ |
|||
get |
|||
{ |
|||
return Path.Combine(RootDirectoryPath, "Helm"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue