Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #340 from kitematic/fix-volumes
Browse files Browse the repository at this point in the history
Fixes for various volume-related bugs
  • Loading branch information
JeffDM committed Mar 27, 2015
2 parents d5527f6 + 4780087 commit 55f6483
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 60 deletions.
64 changes: 39 additions & 25 deletions src/ContainerHomeFolders.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,38 @@ var _ = require('underscore');
var React = require('react/addons');
var RetinaImage = require('react-retina-image');
var path = require('path');
var exec = require('exec');
var shell = require('shell');
var util = require('./Util');
var metrics = require('./Metrics');
var Router = require('react-router');
var ContainerStore = require('./ContainerStore');

var ContainerHomeFolder = React.createClass({
mixins: [Router.State, Router.Navigation],
handleClickFolder: function (path) {
handleClickFolder: function (hostVolume, containerVolume) {
metrics.track('Opened Volume Directory', {
from: 'home'
});
exec(['open', path], function (err) {
if (err) { throw err; }
});

if (hostVolume.indexOf(process.env.HOME) === -1) {
var volumes = _.clone(this.props.container.Volumes);
var newHostVolume = path.join(util.home(), 'Kitematic', this.props.container.Name, containerVolume);
volumes[containerVolume] = newHostVolume;
var binds = _.pairs(volumes).map(function (pair) {
return pair[1] + ':' + pair[0];
});
ContainerStore.updateContainer(this.props.container.Name, {
Binds: binds
}, function (err) {
if (err) {
console.log(err);
return;
}
shell.showItemInFolder(newHostVolume);
});
} else {
shell.showItemInFolder(hostVolume);
}
},
handleClickChangeFolders: function () {
metrics.track('Viewed Volume Settings', {
Expand All @@ -23,24 +42,21 @@ var ContainerHomeFolder = React.createClass({
this.transitionTo('containerSettingsVolumes', {name: this.getParams().name});
},
render: function () {
var folders;
if (this.props.container) {
var self = this;
folders = _.map(self.props.container.Volumes, function (val, key) {
var firstFolder = key.split(path.sep)[1];
if (!val || val.indexOf(process.env.HOME) === -1) {
return;
} else {
return (
<div key={key} className="folder" onClick={self.handleClickFolder.bind(self, val)}>
<RetinaImage src="folder.png" />
<div className="text">{firstFolder}</div>
</div>
);
}
});
if (!this.props.container) {
return false;
}
if (this.props.container && this.props.container.Volumes && _.keys(this.props.container.Volumes).length > 0 && this.props.container.State.Running) {

var folders = _.map(this.props.container.Volumes, (val, key) => {
var firstFolder = key.split(path.sep)[1];
return (
<div key={key} className="folder" onClick={this.handleClickFolder.bind(this, val, key)}>
<RetinaImage src="folder.png" />
<div className="text">{firstFolder}</div>
</div>
);
});

if (this.props.container.Volumes && _.keys(this.props.container.Volumes).length > 0 && this.props.container.State.Running) {
return (
<div className="folders wrapper">
<h4>Edit Files</h4>
Expand All @@ -51,9 +67,7 @@ var ContainerHomeFolder = React.createClass({
</div>
);
} else {
return (
<div></div>
);
return false;
}
}
});
Expand Down
17 changes: 17 additions & 0 deletions src/ContainerSettingsVolumes.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ var ContainerSettingsVolumes = React.createClass({
}
});
},
handleRemoveVolumeClick: function (dockerVol) {
metrics.track('Removed Volume Directory', {
from: 'settings'
});
var volumes = _.clone(this.props.container.Volumes);
delete volumes[dockerVol];
var binds = _.pairs(volumes).map(function (pair) {
return pair[1] + ':' + pair[0];
});
ContainerStore.updateContainer(this.props.container.Name, {
Binds: binds
}, function (err) {
if (err) { console.log(err); }
});
},
handleOpenVolumeClick: function (path) {
metrics.track('Opened Volume Directory', {
from: 'settings'
Expand All @@ -50,13 +65,15 @@ var ContainerSettingsVolumes = React.createClass({
<span>
<a className="value-right">No Folder</a>
<a className="btn btn-action small" onClick={self.handleChooseVolumeClick.bind(self, key)}>Change</a>
<a className="btn btn-action small" onClick={self.handleRemoveVolumeClick.bind(self, key)}>Remove</a>
</span>
);
} else {
val = (
<span>
<a className="value-right" onClick={self.handleOpenVolumeClick.bind(self, val)}>{val.replace(process.env.HOME, '~')}</a>
<a className="btn btn-action small" onClick={self.handleChooseVolumeClick.bind(self, key)}>Change</a>
<a className="btn btn-action small" onClick={self.handleRemoveVolumeClick.bind(self, key)}>Remove</a>
</span>
);
}
Expand Down
51 changes: 16 additions & 35 deletions src/ContainerStore.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
var _ = require('underscore');
var EventEmitter = require('events').EventEmitter;
var async = require('async');
var path = require('path');
var assign = require('object-assign');
var docker = require('./Docker');
var metrics = require('./Metrics');
var registry = require('./Registry');
var logstore = require('./LogStore');
var bugsnag = require('bugsnag-js');
var util = require('./Util');

var _placeholders = {};
var _containers = {};
Expand Down Expand Up @@ -92,38 +90,22 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
},
_startContainer: function (name, containerData, callback) {
var self = this;
docker.client().getImage(containerData.Image).inspect(function (err, data) {
var binds = containerData.Binds || [];
var startopts = {
Binds: binds
};
if (containerData.NetworkSettings && containerData.NetworkSettings.Ports) {
startopts.PortBindings = containerData.NetworkSettings.Ports;
} else{
startopts.PublishAllPorts = true;
}
var container = docker.client().getContainer(name);
container.start(startopts, function (err) {
if (err) {
callback(err);
return;
}
var binds = containerData.Binds || [];
if (data.Config.Volumes) {
_.each(data.Config.Volumes, function (value, key) {
var existingBind = _.find(binds, b => {
return b.indexOf(':' + key) !== -1;
});
if (!existingBind) {
binds.push(path.join(util.home(), 'Kitematic', name, key)+ ':' + key);
}
});
}
var startopts = {
Binds: binds
};
if (containerData.NetworkSettings && containerData.NetworkSettings.Ports) {
startopts.PortBindings = containerData.NetworkSettings.Ports;
} else{
startopts.PublishAllPorts = true;
}
var container = docker.client().getContainer(name);
container.start(startopts, function (err) {
if (err) {
callback(err);
return;
}
self.fetchContainer(name, callback);
});
self.fetchContainer(name, callback);
});
},
_createContainer: function (name, containerData, callback) {
Expand All @@ -137,18 +119,17 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
if (containerData.Config && containerData.Config.Image) {
containerData.Image = containerData.Config.Image;
}
if (containerData.Config && containerData.Config.Env) {
containerData.Env = containerData.Config.Env;
}
existing.kill(function () {
existing.remove(function () {
docker.client().createContainer(containerData, function (err) {
if (err) {
callback(err, null);
return;
}
if (containerData.State && !containerData.State.Running) {
self.fetchContainer(containerData.name, callback);
} else {
self._startContainer(name, containerData, callback);
}
self._startContainer(name, containerData, callback);
});
});
});
Expand Down

0 comments on commit 55f6483

Please sign in to comment.