diff --git a/dotnet/Metaparticle.Package/DockerBuilder.cs b/dotnet/Metaparticle.Package/DockerBuilder.cs index fcaea3e..5de2c7c 100644 --- a/dotnet/Metaparticle.Package/DockerBuilder.cs +++ b/dotnet/Metaparticle.Package/DockerBuilder.cs @@ -4,24 +4,20 @@ namespace Metaparticle.Package { public class DockerBuilder : ImageBuilder { - public DockerBuilder() - { - } - public bool Build(string configFile, string imageName, TextWriter o, TextWriter e) { System.Console.WriteLine(configFile); var info = Directory.GetParent(configFile); - System.Console.WriteLine(string.Format("build -t {0} {1}", imageName, info.FullName)); + System.Console.WriteLine($"build -t {imageName} {info.FullName}"); var err = new StringWriter(); - var proc = Exec("docker", string.Format("build -t {0} {1}", imageName, info.FullName), stdout: o, stderr: err); + var proc = Exec("docker", $"build -t {imageName} {info.FullName}", o, err); System.Console.WriteLine(err.ToString()); return proc.ExitCode == 0; } public bool Push(string imageName, TextWriter stdout, TextWriter stderr) { - var proc = Exec("docker", string.Format("push {0}", imageName), stdout: stdout, stderr: stderr); + var proc = Exec("docker", $"push {imageName}", stdout, stderr); return proc.ExitCode == 0; } } diff --git a/dotnet/Metaparticle.Package/DockerfileWriter.cs b/dotnet/Metaparticle.Package/DockerfileWriter.cs new file mode 100644 index 0000000..f55dc42 --- /dev/null +++ b/dotnet/Metaparticle.Package/DockerfileWriter.cs @@ -0,0 +1,53 @@ +using System.Collections.Generic; +using System.IO; +using System.Text; +using dockerfile; + +namespace Metaparticle.Package +{ + public static class DockerfileWriter + { + /// + /// Creates the dockerfle and returns the name of the file + /// + /// Directory to create the file + /// Executable used to run command/s + /// args for the executable + /// + /// + public static string Write(string dir, string exe, string[] args, Config config) + { + var dockerfilename = dir + "/Dockerfile"; + if (!string.IsNullOrEmpty(config.Dockerfile)) { + File.Copy(config.Dockerfile, dockerfilename); + return dockerfilename; + } + var instructions = new List(); + instructions.Add(new Instruction("FROM", "debian:9")); + instructions.Add(new Instruction("RUN", " apt-get update && apt-get -qq -y install libunwind8 libicu57 libssl1.0 liblttng-ust0 libcurl3 libuuid1 libkrb5-3 zlib1g")); + // TODO: lots of things here are constant, figure out how to cache for perf? + instructions.Add(new Instruction("COPY", "* /exe/")); + instructions.Add(new Instruction("CMD", $"/exe/{exe} {GetArgs(args)}")); + + var df = new Dockerfile(instructions.ToArray(), new Comment[0]); + File.WriteAllText(dockerfilename, df.Contents()); + + return dockerfilename; + } + + private static string GetArgs(string[] args) + { + if (args == null || args.Length == 0) + { + return ""; + } + var b = new StringBuilder(); + foreach (var arg in args) + { + b.Append(arg); + b.Append(" "); + } + return b.ToString().Trim(); + } + } +} \ No newline at end of file diff --git a/dotnet/Metaparticle.Package/Metaparticle.Tests/Config.cs b/dotnet/Metaparticle.Package/Metaparticle.Tests/Config.cs index 6db13af..07ab72b 100644 --- a/dotnet/Metaparticle.Package/Metaparticle.Tests/Config.cs +++ b/dotnet/Metaparticle.Package/Metaparticle.Tests/Config.cs @@ -4,6 +4,9 @@ namespace Metaparticle.Tests { public class Config : Attribute { + /// + /// Directories containing the test projects. This may be absolute or relative to the current project. + /// public string[] Names { get;set; } } } \ No newline at end of file diff --git a/dotnet/Metaparticle.Package/Metaparticle.cs b/dotnet/Metaparticle.Package/Metaparticle.cs index 2a26bfd..2353444 100644 --- a/dotnet/Metaparticle.Package/Metaparticle.cs +++ b/dotnet/Metaparticle.Package/Metaparticle.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Text; -using dockerfile; using Metaparticle.Tests; using static Metaparticle.Package.Util; using RuntimeConfig = Metaparticle.Runtime.Config; @@ -11,20 +8,20 @@ namespace Metaparticle.Package { - public class Driver + public class Driver { - private Config config; - private RuntimeConfig runtimeConfig; - private TestConfig testConfig; + private readonly Config config; + private readonly RuntimeConfig runtimeConfig; + private readonly TestConfig testConfig; - public Driver(Config config, RuntimeConfig runtimeConfig, TestConfig testConfig) + public Driver(Config config, RuntimeConfig runtimeConfig, TestConfig testConfig) { this.config = config; this.runtimeConfig = runtimeConfig; this.testConfig = testConfig; } - private ImageBuilder getBuilder() + private ImageBuilder getBuilder() { switch (config.Builder.ToLowerInvariant()) { @@ -55,27 +52,12 @@ private ContainerExecutor getExecutor() } } - private static string getArgs(string[] args) - { - if (args == null || args.Length == 0) - { - return ""; - } - var b = new StringBuilder(); - foreach (var arg in args) - { - b.Append(arg); - b.Append(" "); - } - return b.ToString().Trim(); - } - public void Build(string[] args) { var proc = Process.GetCurrentProcess(); var procName = proc.ProcessName; string exe = null; - string dir = null; + string dir; TextWriter o = config.Verbose ? Console.Out : null; TextWriter e = config.Quiet ? Console.Error : null; if (procName == "dotnet") @@ -84,7 +66,6 @@ public void Build(string[] args) dir = "bin/release/netcoreapp2.0/debian.8-x64/publish"; Exec("dotnet", "publish -r debian.8-x64 -c release", stdout: o, stderr: e); - //var dirInfo = new UnixDirectoryInfo(dir); var files = Directory.GetFiles(dir); foreach (var filePath in files) { @@ -101,7 +82,7 @@ public void Build(string[] args) var prog = proc.MainModule.FileName; dir = Directory.GetParent(prog).FullName; } - var dockerfilename = writeDockerfile(dir, exe, args, config); + var dockerfilename = DockerfileWriter.Write(dir, exe, args, config); var builder = getBuilder(); string imgName = (string.IsNullOrEmpty(config.Repository) ? exe : config.Repository); @@ -151,31 +132,11 @@ private void RunTests() { throw new Exception("Tests Failed."); } - } - - private string writeDockerfile(string dir, string exe, string[] args, Config config) - { - var dockerfilename = dir + "/Dockerfile"; - if (!string.IsNullOrEmpty(config.Dockerfile)) { - File.Copy(config.Dockerfile, dockerfilename); - return dockerfilename; - } - var instructions = new List(); - instructions.Add(new Instruction("FROM", "debian:9")); - instructions.Add(new Instruction("RUN", " apt-get update && apt-get -qq -y install libunwind8 libicu57 libssl1.0 liblttng-ust0 libcurl3 libuuid1 libkrb5-3 zlib1g")); - // TODO: lots of things here are constant, figure out how to cache for perf? - instructions.Add(new Instruction("COPY", string.Format("* /exe/", dir))); - instructions.Add(new Instruction("CMD", string.Format("/exe/{0} {1}", exe, getArgs(args)))); - - var df = new Dockerfile(instructions.ToArray(), new Comment[0]); - File.WriteAllText(dockerfilename, df.Contents()); - - return dockerfilename; } - public static bool InDockerContainer() + public static bool InDockerContainer() { - switch (System.Environment.GetEnvironmentVariable("METAPARTICLE_IN_CONTAINER")) + switch (Environment.GetEnvironmentVariable("METAPARTICLE_IN_CONTAINER")) { case "true": case "1": @@ -189,7 +150,7 @@ public static bool InDockerContainer() if (File.Exists(cgroupPath)) { var info = File.ReadAllText(cgroupPath); // This is a little approximate... - return info.IndexOf("docker") != -1 || info.IndexOf("kubepods") != -1; + return info.IndexOf("docker", StringComparison.Ordinal) != -1 || info.IndexOf("kubepods", StringComparison.Ordinal) != -1; } return false; } diff --git a/dotnet/Metaparticle.Runtime/Config.cs b/dotnet/Metaparticle.Runtime/Config.cs index 039ac18..ad2280a 100644 --- a/dotnet/Metaparticle.Runtime/Config.cs +++ b/dotnet/Metaparticle.Runtime/Config.cs @@ -1,22 +1,25 @@ -namespace Metaparticle.Runtime { - public class Config : System.Attribute { - public int Replicas { get; set; } +namespace Metaparticle.Runtime +{ + public class Config : System.Attribute + { + public int Replicas { get; set; } - public int Shards { get; set; } + public int Shards { get; set; } - public int JobCount { get; set; } + public int JobCount { get; set; } - public string ShardExpression { get; set; } + public string ShardExpression { get; set; } - public string Executor { get; set; } + public string Executor { get; set; } - public int[] Ports { get; set; } + public int[] Ports { get; set; } - public bool Public { get; set; } + public bool Public { get; set; } - public Config() { - Executor = "docker"; - Replicas = 1; - } - } + public Config() + { + Executor = "docker"; + Replicas = 1; + } + } } \ No newline at end of file diff --git a/dotnet/dotnet.sln b/dotnet/dotnet.sln new file mode 100644 index 0000000..279d3ba --- /dev/null +++ b/dotnet/dotnet.sln @@ -0,0 +1,62 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Metaparticle.Package", "Metaparticle.Package\Metaparticle.Package.csproj", "{37E6F49B-77B6-49D6-86C1-2EBC17080D8C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Metaparticle.Runtime", "Metaparticle.Runtime\Metaparticle.Runtime.csproj", "{4167A6E1-C7C2-4186-8AA1-88DAB52D753B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Metaparticle.Package.Tests", "Metaparticle.Package.Tests\Metaparticle.Package.Tests.csproj", "{108E0A37-6F7E-49A1-AA81-35A540E91588}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {37E6F49B-77B6-49D6-86C1-2EBC17080D8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {37E6F49B-77B6-49D6-86C1-2EBC17080D8C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37E6F49B-77B6-49D6-86C1-2EBC17080D8C}.Debug|x64.ActiveCfg = Debug|Any CPU + {37E6F49B-77B6-49D6-86C1-2EBC17080D8C}.Debug|x64.Build.0 = Debug|Any CPU + {37E6F49B-77B6-49D6-86C1-2EBC17080D8C}.Debug|x86.ActiveCfg = Debug|Any CPU + {37E6F49B-77B6-49D6-86C1-2EBC17080D8C}.Debug|x86.Build.0 = Debug|Any CPU + {37E6F49B-77B6-49D6-86C1-2EBC17080D8C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {37E6F49B-77B6-49D6-86C1-2EBC17080D8C}.Release|Any CPU.Build.0 = Release|Any CPU + {37E6F49B-77B6-49D6-86C1-2EBC17080D8C}.Release|x64.ActiveCfg = Release|Any CPU + {37E6F49B-77B6-49D6-86C1-2EBC17080D8C}.Release|x64.Build.0 = Release|Any CPU + {37E6F49B-77B6-49D6-86C1-2EBC17080D8C}.Release|x86.ActiveCfg = Release|Any CPU + {37E6F49B-77B6-49D6-86C1-2EBC17080D8C}.Release|x86.Build.0 = Release|Any CPU + {4167A6E1-C7C2-4186-8AA1-88DAB52D753B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4167A6E1-C7C2-4186-8AA1-88DAB52D753B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4167A6E1-C7C2-4186-8AA1-88DAB52D753B}.Debug|x64.ActiveCfg = Debug|Any CPU + {4167A6E1-C7C2-4186-8AA1-88DAB52D753B}.Debug|x64.Build.0 = Debug|Any CPU + {4167A6E1-C7C2-4186-8AA1-88DAB52D753B}.Debug|x86.ActiveCfg = Debug|Any CPU + {4167A6E1-C7C2-4186-8AA1-88DAB52D753B}.Debug|x86.Build.0 = Debug|Any CPU + {4167A6E1-C7C2-4186-8AA1-88DAB52D753B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4167A6E1-C7C2-4186-8AA1-88DAB52D753B}.Release|Any CPU.Build.0 = Release|Any CPU + {4167A6E1-C7C2-4186-8AA1-88DAB52D753B}.Release|x64.ActiveCfg = Release|Any CPU + {4167A6E1-C7C2-4186-8AA1-88DAB52D753B}.Release|x64.Build.0 = Release|Any CPU + {4167A6E1-C7C2-4186-8AA1-88DAB52D753B}.Release|x86.ActiveCfg = Release|Any CPU + {4167A6E1-C7C2-4186-8AA1-88DAB52D753B}.Release|x86.Build.0 = Release|Any CPU + {108E0A37-6F7E-49A1-AA81-35A540E91588}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {108E0A37-6F7E-49A1-AA81-35A540E91588}.Debug|Any CPU.Build.0 = Debug|Any CPU + {108E0A37-6F7E-49A1-AA81-35A540E91588}.Debug|x64.ActiveCfg = Debug|Any CPU + {108E0A37-6F7E-49A1-AA81-35A540E91588}.Debug|x64.Build.0 = Debug|Any CPU + {108E0A37-6F7E-49A1-AA81-35A540E91588}.Debug|x86.ActiveCfg = Debug|Any CPU + {108E0A37-6F7E-49A1-AA81-35A540E91588}.Debug|x86.Build.0 = Debug|Any CPU + {108E0A37-6F7E-49A1-AA81-35A540E91588}.Release|Any CPU.ActiveCfg = Release|Any CPU + {108E0A37-6F7E-49A1-AA81-35A540E91588}.Release|Any CPU.Build.0 = Release|Any CPU + {108E0A37-6F7E-49A1-AA81-35A540E91588}.Release|x64.ActiveCfg = Release|Any CPU + {108E0A37-6F7E-49A1-AA81-35A540E91588}.Release|x64.Build.0 = Release|Any CPU + {108E0A37-6F7E-49A1-AA81-35A540E91588}.Release|x86.ActiveCfg = Release|Any CPU + {108E0A37-6F7E-49A1-AA81-35A540E91588}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal