mecano
Version:
Common functions for system deployment.
63 lines (60 loc) • 1.59 kB
JavaScript
// Generated by CoffeeScript 1.11.1
var docker;
module.exports = function(options, callback) {
var cmd, k, opt, ref, v;
options.log({
message: "Entering Docker rm",
level: 'DEBUG',
module: 'mecano/lib/docker/rm'
});
if (options.docker == null) {
options.docker = {};
}
ref = options.docker;
for (k in ref) {
v = ref[k];
if (options[k] == null) {
options[k] = v;
}
}
if (options.container == null) {
return callback(Error('Missing container parameter'));
}
cmd = (function() {
var i, len, ref1, results;
ref1 = ['link', 'volumes', 'force'];
results = [];
for (i = 0, len = ref1.length; i < len; i++) {
opt = ref1[i];
if (options[opt]) {
results.push("-" + (opt.charAt(0)));
} else {
results.push(void 0);
}
}
return results;
})();
cmd = "rm " + (cmd.join(' ')) + " " + options.container;
this.execute({
cmd: docker.wrap(options, "ps | grep '" + options.container + "'"),
code_skipped: 1
}, (function(_this) {
return function(err, executed, stdout, stderr) {
if (executed && !options.force) {
throw Error('Container must be stopped to be removed without force', null);
}
};
})(this));
this.execute({
cmd: docker.wrap(options, "ps -a | grep '" + options.container + "'"),
code_skipped: 1
}, docker.callback);
this.execute({
cmd: docker.wrap(options, cmd),
"if": function() {
return this.status(-1);
}
}, docker.callback);
return this.then(callback);
};
docker = require('../misc/docker');