Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/17/19 10:40:41 (5 years ago)
Author:
dpiringe
Message:

#2924:

  • some changes in CLIApplication.cs to reduce unnecessary allocation of string objects
  • renamed AppTest to ConsoleOptimizer and fixed race condition
  • replaced enum RunnerJob with class RunnerMessage for more control of saved data
  • changed usage of BinaryFormatter with HEAL.Attic, following types are now Storable:
    • ConsoleOptimizer
    • InspectApplication
    • ApplicationBase
    • ApplicationRunner
    • AssemblyInfo
    • Runner
    • UniPath
    • RunnerMessage
  • switched QuietMode from ApplicationRunner to IRunner
  • DockerRunnerHost can now automatically build docker images for linux and windows containers (also identifies which container type is active) -> removes the condition to have the image preinstalled
    • to achieve this, there are two new folders DockerLinuxBuild and DockerWindowsBuild included in build output, which include Dockerfiles to build images for linux and windows container
  • added NuGet package System.CodeDom to project HeuristicLab.Scripting-3.3
  • added method Send(RunnerMessage) to IRunnerHost and transferred methods Pause and Resume to IRunner
  • added internal reference of RunnerHost in Runner
  • added abstract method SendMessage(RunnerMessage) in RunnerHost which gets called from method Send(RunnerMessage)
  • because of a Google.Protobuf "bug", RunnerMessages cannot get serialized/deserialized directly on stream -> workaround with a byte array, which gets written and read
    • additionally, the length of the array gets sent first (length as integer -> 4 bytes)
    • static method in RunnerMessage to read a message from a stream
    • the method SendMessage(RunnerMessage) in RunnerHost implements this functionality
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2924_DotNetCoreMigration/HeuristicLab.PluginInfrastructure/3.3/Isolation/DockerRunnerHost.cs

    r16993 r17013  
    11using System.Diagnostics;
     2using System.IO;
     3using System.Threading.Tasks;
    24using HeuristicLab.PluginInfrastructure.Exceptions;
    35
     
    810  public class DockerRunnerHost : RunnerHost {
    911    #region Constants
    10     private const string Docker = "docker";
    11     private const string ContainerStartup = "container run -i --rm ";
    12     private const string Mounting = @"--mount type=bind,source=/c/Users/,target=/Users ";
    13     private const string Image = "heuristiclab33:latest";
    14     private const string DockerExceptionMessage = "Docker is not running or image '" + Image + "' does not exists!";
     12    private readonly static string Docker = "docker";
     13    private readonly static string ContainerStartup = "container run -i --rm ";
     14    private readonly static string MountingLinux = @"--mount type=bind,source=/c/Users/,target=/Users ";
     15    private readonly static string MountingWindows = @"--mount type=bind,source=C:\Users\,target=C:\Users\ ";
     16    private readonly static string LinuxImage = "." + Path.DirectorySeparatorChar + "DockerLinuxBuild" + Path.DirectorySeparatorChar + "Dockerfile";
     17    private readonly static string WindowsImage = "." + Path.DirectorySeparatorChar + "DockerWindowsBuild" + Path.DirectorySeparatorChar + "Dockerfile";
     18    private readonly static string Image = "heuristiclab33:latest";
     19    private readonly static string DockerExceptionMessage = "Docker is not running!";
    1520    #endregion
    1621
    1722    #region Constructors
    18     public DockerRunnerHost(bool doDockerAvailableCheck = true)
    19       : base(Docker, ContainerStartup + Mounting + Image, null, null, null) {
    20       if (doDockerAvailableCheck && !IsDockerAvailable())
    21         throw new DockerException(DockerExceptionMessage);
     23    public DockerRunnerHost()
     24      : base(Docker, ContainerStartup + GetTargetOSMounting() + Image, null, null, null) {
    2225    }
    2326    #endregion
    2427
    2528    #region Helper
    26     private bool IsDockerAvailable() {
     29
     30    private static string GetTargetOSMounting() {
     31      Task<bool> win = Task.Run(() => BuildImage(WindowsImage));
     32      Task<bool> lin = Task.Run(() => BuildImage(LinuxImage));
     33      if (win.Result) return MountingWindows;
     34      else if (lin.Result) return MountingLinux;
     35      else throw new DockerException(DockerExceptionMessage);
     36    }
     37
     38    private static bool BuildImage(string pathToDockerfile) {
    2739      var process = new Process {
    2840        StartInfo = new ProcessStartInfo {
    2941          FileName = Docker,
    30           Arguments = "image inspect " + Image,
     42          Arguments = "image build -t " + Image +
     43            " -f " + Path.GetFullPath(pathToDockerfile) +
     44            " .",
    3145          UseShellExecute = false,
    3246          RedirectStandardOutput = true,
     
    3751        EnableRaisingEvents = false
    3852      };
    39 
    4053      process.Start();
    4154      process.BeginOutputReadLine();
Note: See TracChangeset for help on using the changeset viewer.