From e6c5ade169c63f414bdd46e70cd198b7d3c19fa5 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Fri, 1 Sep 2017 11:11:54 -0700 Subject: [PATCH] Docker needs more work --- .../Utilities/RepoTestFixture.cs | 1 - .../Commands/DockerBuildCommand.cs | 121 ------------------ .../Commands/DockerFiles/jessie.dockerfile | 13 -- .../KoreBuild.Console/Commands/RootCommand.cs | 1 - 4 files changed, 136 deletions(-) delete mode 100644 tools/KoreBuild.Console/Commands/DockerBuildCommand.cs delete mode 100644 tools/KoreBuild.Console/Commands/DockerFiles/jessie.dockerfile diff --git a/test/KoreBuild.FunctionalTests/Utilities/RepoTestFixture.cs b/test/KoreBuild.FunctionalTests/Utilities/RepoTestFixture.cs index f08a4d7..a83d986 100644 --- a/test/KoreBuild.FunctionalTests/Utilities/RepoTestFixture.cs +++ b/test/KoreBuild.FunctionalTests/Utilities/RepoTestFixture.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.IO; using Xunit; diff --git a/tools/KoreBuild.Console/Commands/DockerBuildCommand.cs b/tools/KoreBuild.Console/Commands/DockerBuildCommand.cs deleted file mode 100644 index 984c5fc..0000000 --- a/tools/KoreBuild.Console/Commands/DockerBuildCommand.cs +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Reflection; -using Microsoft.Extensions.CommandLineUtils; - -namespace KoreBuild.Console.Commands -{ - internal class DockerBuildCommand : SubCommandBase - { - private const string DockerfileExtension = ".dockerfile"; - - public CommandArgument Platform { get; set; } - - public List Arguments {get; set; } - - public string ContainerName { get; set; } = "testcontainer"; - - public override void Configure(CommandLineApplication application) - { - Platform = application.Argument("platform", "The docker platform to run on."); - Arguments = application.RemainingArguments; - - base.Configure(application); - } - - protected override bool IsValid() - { - if(string.IsNullOrEmpty(Platform?.Value)) - { - Reporter.Error("Platform is a required argument."); - return false; - } - - return true; - } - - protected override int Execute() - { - var dockerFileSource = GetDockerFileSource(Platform.Value); - var dockerFileDestination = Path.Combine(RepoPath, GetDockerFileName(Platform.Value)); - - File.Copy(dockerFileSource, dockerFileDestination, true); - - try - { - var buildArgs = new List { "build" }; - - buildArgs.AddRange(new string[] { "-t", ContainerName, "-f", dockerFileDestination, RepoPath }); - var buildResult = RunDockerCommand(buildArgs); - - if (buildResult != 0) - { - return buildResult; - } - - var runArgs = new List { "run", "--rm", "-it", "--name", ContainerName, ContainerName }; - - if (Arguments?.Count > 0) - { - var argString = string.Join(" ", Arguments); - runArgs.Add(argString); - } - - return RunDockerCommand(runArgs); - } - finally{ - // Clean up the dockerfile we dumped there. - File.Delete(dockerFileDestination); - } - } - - private string GetDockerFileSource(string platform) - { - var dockerFileName = GetDockerFileName(platform); - - var executingDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - - var source = Path.Combine(executingDir, "Commands", "DockerFiles", dockerFileName); - - if(!File.Exists(source)) - { - Reporter.Error($"DockerFile '{source}' doesn't exist."); - throw new FileNotFoundException(); - } - - return source; - } - - private string GetDockerFileName(string platform) - { - return $"{platform}{DockerfileExtension}"; - } - - private int RunDockerCommand(List arguments) - { - var args = ArgumentEscaper.EscapeAndConcatenate(arguments.ToArray()); - Reporter.Verbose($"Running 'docker {args}'"); - - var psi = new ProcessStartInfo - { - FileName = "docker", - Arguments = args, - RedirectStandardError = true - }; - - var process = Process.Start(psi); - process.WaitForExit(); - - if(process.ExitCode != 0) - { - Reporter.Error(process.StandardError.ReadToEnd()); - } - - return process.ExitCode; - } - } -} diff --git a/tools/KoreBuild.Console/Commands/DockerFiles/jessie.dockerfile b/tools/KoreBuild.Console/Commands/DockerFiles/jessie.dockerfile deleted file mode 100644 index 4f12a9c..0000000 --- a/tools/KoreBuild.Console/Commands/DockerFiles/jessie.dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM microsoft/dotnet:2.0-runtime-deps-jessie - -RUN apt-get update && \ - apt-get install -y git && \ - apt-get install -y curl && \ - apt-get install -y unzip && \ - apt-get install -y apt-transport-https - -ADD ./ ./ - -RUN rm -f ./korebuild-lock.txt - -ENTRYPOINT ["./build.sh"] diff --git a/tools/KoreBuild.Console/Commands/RootCommand.cs b/tools/KoreBuild.Console/Commands/RootCommand.cs index f24f09c..196dd0b 100644 --- a/tools/KoreBuild.Console/Commands/RootCommand.cs +++ b/tools/KoreBuild.Console/Commands/RootCommand.cs @@ -12,7 +12,6 @@ namespace KoreBuild.Console.Commands { application.FullName = "korebuild"; - application.Command("docker-build", new DockerBuildCommand().Configure, throwOnUnexpectedArg:false); application.Command("install-tools", new InstallToolsCommand().Configure, throwOnUnexpectedArg:false); application.Command("msbuild", new MSBuildCommand().Configure, throwOnUnexpectedArg:false);