- 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 <kraynel@yahoo.fr>
This commit is contained in:
kraynel 2015-06-05 13:34:03 +02:00 committed by Kevin Raynel
parent 6f7d9b80e7
commit c66e6725dd
6 changed files with 62 additions and 19 deletions

View File

@ -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);
}
});
}
});
}
},

View File

@ -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 (
<div key={key} className="folder" onClick={this.handleClickFolder.bind(this, val, key)}>
<RetinaImage src="folder.png" />

View File

@ -65,7 +65,7 @@ var ContainerSettingsPorts = React.createClass({
<div className="table ports">
<div className="table-labels">
<div className="label-left">DOCKER PORT</div>
<div className="label-right">MAC PORT</div>
<div className="label-right">LOCAL PORT</div>
</div>
{ports}
</div>

View File

@ -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 = (
<span>
<a className="value-right">No Folder</a>
@ -80,7 +89,7 @@ var ContainerSettingsVolumes = React.createClass({
<div className="table volumes">
<div className="table-labels">
<div className="label-left">DOCKER FOLDER</div>
<div className="label-right">MAC FOLDER</div>
<div className="label-right">LOCAL FOLDER</div>
</div>
{volumes}
</div>

View File

@ -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 => {

View File

@ -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']
};