mirror of https://github.com/docker/docs.git
updateContainer method for ContainerStore
This commit is contained in:
parent
257739f09d
commit
cbefb542ff
|
@ -29,7 +29,6 @@ var ContainerDetails = React.createClass({
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
componentWillReceiveProps: function () {
|
componentWillReceiveProps: function () {
|
||||||
// active container changes
|
|
||||||
if (this.state.page === this.PAGE_SETTINGS) {
|
if (this.state.page === this.PAGE_SETTINGS) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -61,7 +60,6 @@ var ContainerDetails = React.createClass({
|
||||||
},
|
},
|
||||||
init: function () {
|
init: function () {
|
||||||
this.setState({
|
this.setState({
|
||||||
page: this.PAGE_LOGS,
|
|
||||||
env: ContainerUtil.env(ContainerStore.container(this.getParams().name))
|
env: ContainerUtil.env(ContainerStore.container(this.getParams().name))
|
||||||
});
|
});
|
||||||
ContainerStore.fetchLogs(this.getParams().name, function () {
|
ContainerStore.fetchLogs(this.getParams().name, function () {
|
||||||
|
@ -124,9 +122,14 @@ var ContainerDetails = React.createClass({
|
||||||
$rows.each(function () {
|
$rows.each(function () {
|
||||||
var key = $(this).find('.key').val();
|
var key = $(this).find('.key').val();
|
||||||
var val = $(this).find('.val').val();
|
var val = $(this).find('.val').val();
|
||||||
|
if (!key.length || !val.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
envVarList.push(key + '=' + val);
|
envVarList.push(key + '=' + val);
|
||||||
});
|
});
|
||||||
console.log(envVarList);
|
ContainerStore.updateContainer(this.props.container.Name, {
|
||||||
|
Env: envVarList
|
||||||
|
});
|
||||||
},
|
},
|
||||||
handleAddPendingEnvVar: function () {
|
handleAddPendingEnvVar: function () {
|
||||||
var newKey = $('#new-env-key').val();
|
var newKey = $('#new-env-key').val();
|
||||||
|
|
|
@ -14,6 +14,7 @@ var _recommended = [];
|
||||||
var _containers = {};
|
var _containers = {};
|
||||||
var _progress = {};
|
var _progress = {};
|
||||||
var _logs = {};
|
var _logs = {};
|
||||||
|
var _muted = {};
|
||||||
|
|
||||||
var ContainerStore = assign(EventEmitter.prototype, {
|
var ContainerStore = assign(EventEmitter.prototype, {
|
||||||
CLIENT_CONTAINER_EVENT: 'client_container',
|
CLIENT_CONTAINER_EVENT: 'client_container',
|
||||||
|
@ -105,100 +106,32 @@ var ContainerStore = assign(EventEmitter.prototype, {
|
||||||
div.appendChild(text);
|
div.appendChild(text);
|
||||||
return div.innerHTML;
|
return div.innerHTML;
|
||||||
},
|
},
|
||||||
_createContainer: function (name, data, callback) {
|
_createContainer: function (name, containerData, callback) {
|
||||||
var existing = docker.client().getContainer(name);
|
var existing = docker.client().getContainer(name);
|
||||||
var self = this;
|
var self = this;
|
||||||
data.name = name;
|
containerData.name = name;
|
||||||
existing.remove(function (err, data) {
|
if (containerData.Config && containerData.Config.Image) {
|
||||||
docker.client().createContainer(data, function (err, container) {
|
containerData.Image = containerData.Config.Image;
|
||||||
if (err) {
|
|
||||||
callback(err, null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
container.start({
|
|
||||||
PublishAllPorts: true
|
|
||||||
}, function (err) {
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.fetchContainer(name, callback);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
updateContainer: function (name, data) {
|
|
||||||
var fullData = assign(this._containers[name], data);
|
|
||||||
this._createContainer(name, fullData, function (err) {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
rename: function (name, newName, callback) {
|
|
||||||
var existing = docker.client().getContainer(name);
|
|
||||||
var existingImage = existing.Image;
|
|
||||||
var self = this;
|
|
||||||
existing.remove(function (err, data) {
|
|
||||||
docker.client().createContainer({
|
|
||||||
Image: existingImage,
|
|
||||||
Tty: false,
|
|
||||||
name: newName,
|
|
||||||
User: 'root'
|
|
||||||
}, function (err, container) {
|
|
||||||
if (err) {
|
|
||||||
callback(err, null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
container.start({
|
|
||||||
PublishAllPorts: true
|
|
||||||
}, function (err) {
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.fetchContainer(newName, callback);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
remove: function (name, callback) {
|
|
||||||
var self = this;
|
|
||||||
var existing = docker.client().getContainer(name);
|
|
||||||
if (_containers[name].State.Paused) {
|
|
||||||
existing.unpause(function (err) {
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
existing.kill(function (err) {
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
existing.remove(function (err) {
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
existing.kill(function (err) {
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
existing.remove(function (err) {
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
existing.kill(function (err, data) {
|
||||||
|
existing.remove(function (err, data) {
|
||||||
|
docker.client().createContainer(containerData, function (err, container) {
|
||||||
|
if (err) {
|
||||||
|
callback(err, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
container.start({
|
||||||
|
PublishAllPorts: true
|
||||||
|
}, function (err) {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.fetchContainer(name, callback);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
_createPlaceholderContainer: function (imageName, name, callback) {
|
_createPlaceholderContainer: function (imageName, name, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -251,7 +184,7 @@ var ContainerStore = assign(EventEmitter.prototype, {
|
||||||
stream.setEncoding('utf8');
|
stream.setEncoding('utf8');
|
||||||
stream.on('data', function (data) {});
|
stream.on('data', function (data) {});
|
||||||
stream.on('end', function () {
|
stream.on('end', function () {
|
||||||
self._createContainer(container.KitematicDownloadingImage, container.Name, function () {});
|
self._createContainer(container.Name, {Image: container.KitematicDownloadingImage}, function () {});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -271,11 +204,17 @@ var ContainerStore = assign(EventEmitter.prototype, {
|
||||||
// If the event is delete, remove the container
|
// If the event is delete, remove the container
|
||||||
if (data.status === 'destroy') {
|
if (data.status === 'destroy') {
|
||||||
var container = _.findWhere(_.values(_containers), {Id: data.id});
|
var container = _.findWhere(_.values(_containers), {Id: data.id});
|
||||||
|
if (_muted[container.Name]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
delete _containers[container.Name];
|
delete _containers[container.Name];
|
||||||
this.emit(this.SERVER_CONTAINER_EVENT, container.Name, data.status);
|
this.emit(this.SERVER_CONTAINER_EVENT, container.Name, data.status);
|
||||||
} else {
|
} else {
|
||||||
this.fetchContainer(data.id, function (err) {
|
this.fetchContainer(data.id, function (err) {
|
||||||
var container = _.findWhere(_.values(_containers), {Id: data.id});
|
var container = _.findWhere(_.values(_containers), {Id: data.id});
|
||||||
|
if (_muted[container.Name]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.emit(this.SERVER_CONTAINER_EVENT, container ? container.Name : null, data.status);
|
this.emit(this.SERVER_CONTAINER_EVENT, container ? container.Name : null, data.status);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
@ -367,6 +306,9 @@ var ContainerStore = assign(EventEmitter.prototype, {
|
||||||
stderr: true,
|
stderr: true,
|
||||||
timestamps: true
|
timestamps: true
|
||||||
}, function (err, stream) {
|
}, function (err, stream) {
|
||||||
|
if (err) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
stream.setEncoding('utf8');
|
stream.setEncoding('utf8');
|
||||||
stream.on('data', function (buf) {
|
stream.on('data', function (buf) {
|
||||||
// Every other message is a header
|
// Every other message is a header
|
||||||
|
@ -417,7 +359,7 @@ var ContainerStore = assign(EventEmitter.prototype, {
|
||||||
self.emit(self.CLIENT_CONTAINER_EVENT, containerName, 'create');
|
self.emit(self.CLIENT_CONTAINER_EVENT, containerName, 'create');
|
||||||
_progress[containerName] = 0;
|
_progress[containerName] = 0;
|
||||||
self._pullImage(repository, tag, function () {
|
self._pullImage(repository, tag, function () {
|
||||||
self._createContainer(imageName, containerName, function (err, container) {
|
self._createContainer(containerName, {Image: imageName}, function (err, container) {
|
||||||
delete _progress[containerName];
|
delete _progress[containerName];
|
||||||
});
|
});
|
||||||
}, function (progress) {
|
}, function (progress) {
|
||||||
|
@ -428,13 +370,62 @@ var ContainerStore = assign(EventEmitter.prototype, {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// If not then directly create the container
|
// If not then directly create the container
|
||||||
self._createContainer(imageName, containerName, function (err, container) {
|
self._createContainer(containerName, {Image: imageName}, function (err, container) {
|
||||||
self.emit(ContainerStore.CLIENT_CONTAINER_EVENT, containerName, 'create');
|
self.emit(ContainerStore.CLIENT_CONTAINER_EVENT, containerName, 'create');
|
||||||
callback(null, containerName);
|
callback(null, containerName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
updateContainer: function (name, data) {
|
||||||
|
_muted[name] = true;
|
||||||
|
var fullData = assign(_containers[name], data);
|
||||||
|
this._createContainer(name, fullData, function (err) {
|
||||||
|
this.emit(this.CLIENT_CONTAINER_EVENT, name);
|
||||||
|
console.log(err);
|
||||||
|
_muted[name] = false;
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
remove: function (name, callback) {
|
||||||
|
var self = this;
|
||||||
|
var existing = docker.client().getContainer(name);
|
||||||
|
if (_containers[name].State.Paused) {
|
||||||
|
existing.unpause(function (err) {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
existing.kill(function (err) {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
existing.remove(function (err) {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
existing.kill(function (err) {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
existing.remove(function (err) {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
containers: function() {
|
containers: function() {
|
||||||
return _containers;
|
return _containers;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue