Exemple #1
0
 protected Process Run(ParamsBuilder param, string exec = DockerCmd, bool stdin = true, bool stdout = true,
     bool stderr = true,
     bool shellExec = false)
 {
     Logger.Command(param);
       return ProcessHelper.Run(exec, param, stdin, stdout, stderr, shellExec);
 }
Exemple #2
0
 protected void Exec(ParamsBuilder args)
 {
     Logger.Command(args, false);
       var exit = ProcessHelper.Exec(DockerCmd, args.Params);
       if (exit != 0)
       {
     throw new DockerException(args, exit);
       }
       return;
 }
Exemple #3
0
 /// <exception cref="DockerException">Exit code is not 0</exception>
 protected void RunNow(ParamsBuilder param, string exec = DockerCmd, bool important = false)
 {
     var process = Run(param, exec);
       foreach (var line in process.ReadOutputLines())
       {
     Logger.Output(line, important);
       }
       process.WaitForExit();
       if (process.ExitCode != 0)
       {
     var errorLog = process.StandardError.ReadToEnd();
     throw new DockerException($"{param}\n{errorLog}", process.ExitCode);
       }
 }
Exemple #4
0
 /// <exception cref="DockerException">Exit code is not 0</exception>
 protected string RunNowOutput(ParamsBuilder param, string exec = DockerCmd, bool important = false)
 {
     var process = Run(param, exec);
       var b = new StringBuilder();
       foreach (var line in process.ReadOutputLines())
       {
     Logger.Output(line, important);
     b.Append(line);
       }
       process.WaitForExit();
       if (process.ExitCode != 0)
       {
     throw new DockerException(param, process.ExitCode);
       }
       return b.ToString();
 }
Exemple #5
0
        public static Process Run(
            string filename,
            ParamsBuilder param,
            bool stdin = true,
            bool stdout = true,
            bool stderr = true,
            bool shellExec = false,
            bool exec = false)
        {
            var processStartInfo = new ProcessStartInfo
              {
            FileName = filename,
            Arguments = param,
            RedirectStandardInput = stdin,
            RedirectStandardOutput = stdout,
            RedirectStandardError = stderr,
            UseShellExecute = shellExec
              };

              return Process.Start(processStartInfo);
        }
Exemple #6
0
    public void Create(DockerApp app)
    {
      var containerName = app.Container.Name;
      var appName = app.Name;
      var desktopConfig = app.Desktop;

      string icon = null;
      string terminal = null;
      string comment = null;
      string name = null;

      var runnerPath = GetExecPath(containerName, appName);
      if (desktopConfig != null)
      {
        name = desktopConfig.name;

        comment = desktopConfig.comment;


        if (!string.IsNullOrEmpty(desktopConfig.icon))
        {
          switch (icon[0])
          {
            case '.': // relative
              icon = Path.Combine(app.Container.ContainerPath, icon); // make it absolute
              break;
            case '/': // absolute
              break;
            default: // freedesktop
              break;
          }
        }
        if (!string.IsNullOrEmpty(desktopConfig.terminal))
        {
          string param = new ParamsBuilder(true) | runnerPath;
          terminal = desktopConfig.terminal.Replace(ExePattern, param);
        }
      }


      var filename = DesktopFilename(containerName, appName);
      using (var f = File.Open(filename, FileMode.OpenOrCreate, FileAccess.Write))
      {
        using (var w = new StreamWriter(f))
        {
          w.WriteLine("[Desktop Entry]");
          w.WriteLine("Encoding=UTF-8");
          w.WriteLine("Type=Application");
          w.WriteLine("Version=1.0");

          w.WriteLine("Comment=" + (comment ?? "DockerApp app"));
          w.WriteLine($"Name=" + (name ?? appName));

          w.WriteLine("DappApp=" + (terminal ?? runnerPath));
          if (icon != null)
          {
            w.WriteLine($"Icon={icon}");
          }
        }
      }
    }
Exemple #7
0
 protected void AppendUserParam(ParamsBuilder b, string user)
 {
   if (string.IsNullOrEmpty(user))
   {
     var uid = GetUseId("-u");
     var gid = GetUseId("-g");
     b = b | "-u" | $"{uid}:{gid}";
   }
   else if (user == "root")
   {
     b = b | "-u" | "0:0";
   }
 }