Browse Source

remove some unused classes (#218)

pull/220/head
Simon Cropp 7 years ago
committed by GitHub
parent
commit
8cb9a1778d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/Microsoft.Tye.Core/ApplicationGlobals.cs
  2. 85
      src/Microsoft.Tye.Core/DirectorySearch.cs
  3. 23
      src/Microsoft.Tye.Core/EnvironmentAttribute.cs
  4. 13
      src/Microsoft.Tye.Core/Environments.cs
  5. 11
      src/Microsoft.Tye.Core/GeneratedAssets.cs
  6. 82
      src/Microsoft.Tye.Core/HelmChartBuilder.cs
  7. 56
      src/Microsoft.Tye.Core/HelmPush.cs
  8. 27
      src/Microsoft.Tye.Core/NameSanitizer.cs
  9. 36
      src/Microsoft.Tye.Core/Names.cs
  10. 80
      src/Microsoft.Tye.Core/OamApplicationGenerator.cs
  11. 23
      src/Microsoft.Tye.Core/PipelineHolder.cs
  12. 13
      src/Microsoft.Tye.Core/Program.cs
  13. 21
      src/Microsoft.Tye.Core/ServiceBinding.cs
  14. 11
      src/Microsoft.Tye.Core/StepView.cs
  15. 29
      src/Microsoft.Tye.Core/Templates.cs
  16. 1
      src/tye/tye.csproj

15
src/Microsoft.Tye.Core/ApplicationGlobals.cs

@ -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; }
}
}

85
src/Microsoft.Tye.Core/DirectorySearch.cs

@ -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;
}
}
}
}

23
src/Microsoft.Tye.Core/EnvironmentAttribute.cs

@ -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; }
}
}

13
src/Microsoft.Tye.Core/Environments.cs

@ -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";
}
}

11
src/Microsoft.Tye.Core/GeneratedAssets.cs

@ -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; }
}
}

82
src/Microsoft.Tye.Core/HelmChartBuilder.cs

@ -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")}");
}
}
}

56
src/Microsoft.Tye.Core/HelmPush.cs

@ -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.");
}
}
}
}

27
src/Microsoft.Tye.Core/NameSanitizer.cs

@ -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("-", "_");
}
}
}

36
src/Microsoft.Tye.Core/Names.cs

@ -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;
}
}
}

80
src/Microsoft.Tye.Core/OamApplicationGenerator.cs

@ -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;
}
}
}

23
src/Microsoft.Tye.Core/PipelineHolder.cs

@ -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; }
}
}

13
src/Microsoft.Tye.Core/Program.cs

@ -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()
{
}
}
}

21
src/Microsoft.Tye.Core/ServiceBinding.cs

@ -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; }
}
}

11
src/Microsoft.Tye.Core/StepView.cs

@ -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
{
}
}

29
src/Microsoft.Tye.Core/Templates.cs

@ -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");
}
}
}
}

1
src/tye/tye.csproj

@ -13,7 +13,6 @@
<ItemGroup>
<Compile Include="..\shared\KubectlDetector.cs" Link="KubectlDetector.cs" />
<Compile Include="..\shared\TempDirectory.cs" Link="TempDirectory.cs" />
<Compile Include="..\shared\TempFile.cs" Link="TempFile.cs" />
</ItemGroup>

Loading…
Cancel
Save