Merge pull request #1295 from docker/fix-volume-settings-bugs

Fix bug where renaming or editing container settings would cause volume settings to be lost
This commit is contained in:
Jeffrey Morgan 2015-12-13 17:47:55 -08:00
Родитель 806efdd767 94f7ce8b71
Коммит 07c3c67bf5
4 изменённых файлов: 19 добавлений и 31 удалений

Просмотреть файл

@ -32,7 +32,7 @@
"classnames": "^2.1.5",
"coveralls": "^2.11.2",
"deep-extend": "^0.4.0",
"dockerode": "^2.2.3",
"dockerode": "^2.2.7",
"install": "^0.1.8",
"jquery": "^2.1.3",
"mixpanel": "kitematic/mixpanel-node",

Просмотреть файл

@ -28,17 +28,10 @@ var ContainerHomeFolder = React.createClass({
var mounts = _.clone(this.props.container.Mounts);
var newSource = path.join(util.home(), util.documents(), 'Kitematic', this.props.container.Name, destination);
var binds = mounts.map(function (m) {
let source = m.Source;
mounts.forEach(m => {
if (m.Destination === destination) {
source = newSource;
m.Source = util.windowsToLinuxPath(newSource);
}
if(util.isWindows()) {
return util.windowsToLinuxPath(source) + ':' + m.Destination;
}
return source + ':' + m.Destination;
});
mkdirp(newSource, function (err) {
@ -48,7 +41,7 @@ var ContainerHomeFolder = React.createClass({
}
});
containerActions.update(this.props.container.Name, {Binds: binds});
containerActions.update(this.props.container.Name, {Mounts: mounts});
}
});
} else {

Просмотреть файл

@ -27,14 +27,10 @@ var ContainerSettingsVolumes = React.createClass({
metrics.track('Choose Directory for Volume');
if(util.isWindows()) {
directory = util.windowsToLinuxPath(directory);
}
var mounts = _.clone(this.props.container.Mounts);
_.each(mounts, m => {
if (m.Destination === dockerVol) {
m.Source = directory;
m.Source = util.windowsToLinuxPath(directory);
}
});
@ -50,19 +46,14 @@ var ContainerSettingsVolumes = React.createClass({
from: 'settings'
});
var hostConfig = _.clone(this.props.container.HostConfig);
var binds = hostConfig.Binds;
var mounts = _.clone(this.props.container.Mounts);
_.each(mounts, m => {
if (m.Destination === dockerVol) {
m.Source = null;
}
});
var index = _.findIndex(binds, bind => bind.indexOf(`:${dockerVol}`) !== -1);
if (index >= 0) {
binds.splice(index, 1);
}
containerActions.update(this.props.container.Name, {HostConfig: hostConfig, Binds: binds, Mounts: mounts});
containerActions.update(this.props.container.Name, {Mounts: mounts});
},
handleOpenVolumeClick: function (path) {
metrics.track('Opened Volume Directory', {

Просмотреть файл

@ -248,6 +248,11 @@ export default {
existingData.Tty = existingData.Config.Tty;
existingData.OpenStdin = existingData.Config.OpenStdin;
}
data.Mounts = data.Mounts || existingData.Mounts;
data.Binds = data.Mounts.map(m => m.Source + ':' + m.Destination);
// Preserve Ports
let networking = _.extend(existingData.NetworkSettings, data.NetworkSettings);
if (networking && networking.Ports) {
let exposed = _.reduce(networking.Ports, (res, value, key) => {
@ -273,8 +278,8 @@ export default {
containerServerActions.error({name, error});
return;
}
var oldPath = path.join(util.home(), 'Kitematic', name);
var newPath = path.join(util.home(), 'Kitematic', newName);
var oldPath = util.windowsToLinuxPath(path.join(util.home(), util.documents(), 'Kitematic', name));
var newPath = util.windowsToLinuxPath(path.join(util.home(), util.documents(), 'Kitematic', newName));
this.client.getContainer(newName).inspect((error, container) => {
if (error) {
@ -285,13 +290,12 @@ export default {
if (fs.existsSync(oldPath)) {
fs.renameSync(oldPath, newPath);
}
var binds = _.pairs(container.Volumes).map(function (pair) {
return pair[1] + ':' + pair[0];
container.Mounts.forEach(m => {
m.Source = m.Source.replace(oldPath, newPath);
});
var newBinds = binds.map(b => {
return b.replace(path.join(util.home(), 'Kitematic', name), path.join(util.home(), 'Kitematic', newName));
});
this.updateContainer(newName, {Binds: newBinds});
this.updateContainer(newName, {Mounts: container.Mounts});
rimraf(oldPath, () => {});
});
});