@waves/node-state
Version:
53 lines • 1.81 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.stats = exports.run = exports.isRunImage = exports.stop = exports.remove = void 0;
const utils_1 = require("../utils");
const console_1 = __importDefault(require("./console"));
function remove(image) {
return stats(['-a']).then(list => {
const args = list.filter(item => item.image === image)
.map(item => item.id);
if (!args.length) {
return void 0;
}
return utils_1.exec('docker', ['rm', ...args])
.then(console_1.default.log);
});
}
exports.remove = remove;
function stop(image) {
return stats().then(list => {
const args = list.filter(item => item.image === image)
.map(item => item.id);
if (!args.length) {
return void 0;
}
return utils_1.exec('docker', ['stop', ...args])
.then(console_1.default.log);
});
}
exports.stop = stop;
function isRunImage(image) {
return stats().then(list => list.filter(item => item.image === image).length !== 0);
}
exports.isRunImage = isRunImage;
function run(args, image) {
return stop(image).then(() => remove(image))
.then(() => utils_1.run('docker', ['run', ...args, image]));
}
exports.run = run;
function stats(flags = []) {
return utils_1.exec('docker', ['ps', ...flags]).then(message => {
return message
.split('\n')
.filter(Boolean)
.slice(1)
.map(line => line.split(/\s\s\s+/))
.map(([id, image, command]) => ({ id, image, command }));
});
}
exports.stats = stats;
//# sourceMappingURL=docker.js.map