From c66e6725dd1c971c9de10ac82dabdc75f7810b7c Mon Sep 17 00:00:00 2001 From: kraynel Date: Fri, 5 Jun 2015 13:34:03 +0200 Subject: [PATCH] - Change MAC label in settings for Windows integration : MAC -> LOCAL - Use child_process to spawn a terminal. Works on windows - Transform Windows paths on Linux style for mounting directories - Launch ssh on Windows (if ssh.exe is un the path) Signed-off-by: Kevin Raynel --- .../ContainerDetailsSubheader.react.js | 26 ++++++++++++++----- src/components/ContainerHomeFolders.react.js | 9 ++----- .../ContainerSettingsPorts.react.js | 2 +- .../ContainerSettingsVolumes.react.js | 15 ++++++++--- src/utils/DockerMachineUtil.js | 8 +++++- src/utils/Util.js | 21 +++++++++++++++ 6 files changed, 62 insertions(+), 19 deletions(-) diff --git a/src/components/ContainerDetailsSubheader.react.js b/src/components/ContainerDetailsSubheader.react.js index bc9d4a348d..83a4390e54 100644 --- a/src/components/ContainerDetailsSubheader.react.js +++ b/src/components/ContainerDetailsSubheader.react.js @@ -5,6 +5,7 @@ var exec = require('exec'); var shell = require('shell'); var metrics = require('../utils/MetricsUtil'); var ContainerUtil = require('../utils/ContainerUtil'); +var util = require('../utils/Util'); var machine = require('../utils/DockerMachineUtil'); var RetinaImage = require('react-retina-image'); var classNames = require('classnames'); @@ -107,13 +108,24 @@ var ContainerDetailsSubheader = React.createClass({ shell = 'sh'; } machine.ip().then(ip => { - var cmd = [resources.terminal(), 'ssh', '-p', '22', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'LogLevel=quiet', '-o', 'StrictHostKeyChecking=no', '-i', '~/.docker/machine/machines/' + machine.name() + '/id_rsa', 'docker@' + ip, '-t', 'docker', - 'exec', '-i', '-t', container.Name, shell]; - exec(cmd, function (stderr, stdout, code) { - if (code) { - console.log(stderr); - } - }); + if(util.isWindows()) { + var cmd = ['ssh', '-p', '22', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'LogLevel=quiet', '-o', 'StrictHostKeyChecking=no', '-i', util.home() + '/.docker/machine/machines/' + machine.name() + '/id_rsa', 'docker@' + ip, '-t', 'docker', + 'exec', '-i' , '-t', container.Name, shell]; + console.log(cmd.join(" ")); + util.execProper('start cmd.exe /C "' + cmd.join(" ") + '"', function (stderr, stdout, code) { + if (code) { + console.log(stderr); + } + }); + } else { + var cmd = [resources.terminal(), 'ssh', '-p', '22', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'LogLevel=quiet', '-o', 'StrictHostKeyChecking=no', '-i', '~/.docker/machine/machines/' + machine.name() + '/id_rsa', 'docker@' + ip, '-t', 'docker', + 'exec', '-i', '-t', container.Name, shell]; + exec(cmd, function (stderr, stdout, code) { + if (code) { + console.log(stderr); + } + }); + } }); } }, diff --git a/src/components/ContainerHomeFolders.react.js b/src/components/ContainerHomeFolders.react.js index 4f769ce766..b7d2c6d55f 100644 --- a/src/components/ContainerHomeFolders.react.js +++ b/src/components/ContainerHomeFolders.react.js @@ -29,12 +29,7 @@ var ContainerHomeFolder = React.createClass({ volumes[containerVolume] = newHostVolume; var binds = _.pairs(volumes).map(function (pair) { if(util.isWindows()) { - var home = util.home(); - home = home.charAt(0).toLowerCase() + home.slice(1); - home = '/' + home.replace(':', '').replace(/\\/g, '/'); - var fullPath = path.join(home, 'Kitematic', pair[1], pair[0]); - fullPath = fullPath.replace(/\\/g, '/'); - return fullPath + ':' + pair[0]; + return util.windowsToLinuxPath(pair[1]) + ':' + pair[0]; } return pair[1] + ':' + pair[0]; }); @@ -64,7 +59,7 @@ var ContainerHomeFolder = React.createClass({ } var folders = _.map(this.props.container.Volumes, (val, key) => { - var firstFolder = key.split(path.sep)[1]; + var firstFolder = key.split('/')[1]; return (
diff --git a/src/components/ContainerSettingsPorts.react.js b/src/components/ContainerSettingsPorts.react.js index c266384d94..f08787dfd2 100644 --- a/src/components/ContainerSettingsPorts.react.js +++ b/src/components/ContainerSettingsPorts.react.js @@ -65,7 +65,7 @@ var ContainerSettingsPorts = React.createClass({
DOCKER PORT
-
MAC PORT
+
LOCAL PORT
{ports}
diff --git a/src/components/ContainerSettingsVolumes.react.js b/src/components/ContainerSettingsVolumes.react.js index 5ccd5e4f32..64992927a4 100644 --- a/src/components/ContainerSettingsVolumes.react.js +++ b/src/components/ContainerSettingsVolumes.react.js @@ -3,6 +3,7 @@ var React = require('react/addons'); var remote = require('remote'); var dialog = remote.require('dialog'); var shell = require('shell'); +var util = require('../utils/Util'); var metrics = require('../utils/MetricsUtil'); var containerActions = require('../actions/ContainerActions'); @@ -15,7 +16,10 @@ var ContainerSettingsVolumes = React.createClass({ } var directory = filenames[0]; if (directory) { - metrics.track('Chose Directory for Volume'); + metrics.track('Choose Directory for Volume'); + if(util.isWindows()) { + directory = util.windowsToLinuxPath(directory); + } var volumes = _.clone(self.props.container.Volumes); volumes[dockerVol] = directory; var binds = _.pairs(volumes).map(function (pair) { @@ -48,8 +52,13 @@ var ContainerSettingsVolumes = React.createClass({ return false; } + var homeDir = process.env.HOME; + if(util.isWindows()) { + homeDir = util.windowsToLinuxPath(homeDir); + } + var volumes = _.map(this.props.container.Volumes, (val, key) => { - if (!val || val.indexOf(process.env.HOME) === -1) { + if (!val || val.indexOf(homeDir) === -1) { val = ( No Folder @@ -80,7 +89,7 @@ var ContainerSettingsVolumes = React.createClass({
DOCKER FOLDER
-
MAC FOLDER
+
LOCAL FOLDER
{volumes}
diff --git a/src/utils/DockerMachineUtil.js b/src/utils/DockerMachineUtil.js index 0875882d5c..8ab38f4651 100644 --- a/src/utils/DockerMachineUtil.js +++ b/src/utils/DockerMachineUtil.js @@ -156,7 +156,13 @@ var DockerMachine = { dockerTerminal: function () { if(util.isWindows()) { this.info().then(machine => { - util.execProper(`start cmd.exe /k "SET DOCKER_HOST=${machine.url}&& SET DOCKER_CERT_PATH=${path.join(util.home(), '.docker/machine/machines/' + machine.name)}&& SET DOCKER_TLS_VERIFY=1`); + util.execProper('start cmd.exe /k', + {'env': { + 'DOCKER_HOST' : machine.url, + 'DOCKER_CERT_PATH' : path.join(util.home(), '.docker/machine/machines/' + machine.name), + 'DOCKER_TLS_VERIFY': 1 + } + }); }); } else { this.info().then(machine => { diff --git a/src/utils/Util.js b/src/utils/Util.js index fd4524e4e5..77f636977a 100644 --- a/src/utils/Util.js +++ b/src/utils/Util.js @@ -1,4 +1,5 @@ var exec = require('exec'); +var execProper = require('child_process').exec; var Promise = require('bluebird'); var fs = require('fs'); var path = require('path'); @@ -20,6 +21,19 @@ module.exports = { }); }); }, + execProper: function (args, options) { + options = options || {}; + return new Promise((resolve, reject) => { + execProper(args, options, (error, stdout, stderr) => { + if (error != null) { + var cmd = Array.isArray(args) ? args.join(' ') : args; + reject(new Error(cmd + ' returned non zero exit code. Stderr: ' + stderr)); + } else { + resolve(stdout); + } + }); + }); + }, isWindows: function () { return process.platform === 'win32'; }, @@ -129,5 +143,12 @@ module.exports = { randomId: function () { return crypto.randomBytes(32).toString('hex'); }, + windowsToLinuxPath: function(windowsAbsPath) { + var fullPath = windowsAbsPath.replace(':', '').split(path.sep).join('/'); + if(fullPath.charAt(0) !== '/'){ + fullPath = '/' + fullPath.charAt(0).toLowerCase() + fullPath.substring(1); + } + return fullPath; + }, webPorts: ['80', '8000', '8080', '3000', '5000', '2368', '9200', '8983'] };