UNPKG

mecano

Version:

Common functions for system deployment.

144 lines (139 loc) 4.13 kB
// Generated by CoffeeScript 1.11.1 var docker, string, util; module.exports = function(options, callback) { var cmd, images, k, ref, v; options.log({ message: "Entering Docker load", level: 'DEBUG', module: 'mecano/lib/docker/load' }); 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.input == null) { options.input = options.source; } if (options.input == null) { return callback(Error('Missing input parameter')); } cmd = "load -i " + options.input; images = {}; delete options.cmd; options.log({ message: 'Storing previous state of image', level: 'INFO', module: 'mecano/lib/docker/load' }); if (options.checksum == null) { options.log({ message: 'No checksum provided', level: 'INFO', module: 'mecano/lib/docker/load' }); } if (options.checksum) { options.log({ message: "Checksum provided :" + options.checksum, level: 'INFO', module: 'mecano/lib/docker/load' }); } if (options.checksum == null) { options.checksum = ''; } return this.execute({ cmd: docker.wrap(options, " images | grep -v '<none>' | awk '{ print $1\":\"$2\":\"$3 }'") }, (function(_this) { return function(err, executed, stdout, stderr) { var i, image, infos, len, ref1; if (err) { return callback(err); } if (string.lines(stdout).length > 1) { ref1 = string.lines(stdout); for (i = 0, len = ref1.length; i < len; i++) { image = ref1[i]; image = image.trim(); if (image !== '') { infos = image.split(':'); if (infos[2] === options.checksum) { options.log({ message: "Image already exist checksum :" + options.checksum + ", repo:tag " + (infos[0] + ":" + infos[1]), level: 'INFO', module: 'mecano/lib/docker/load' }); } if (infos[2] === options.checksum) { return callback(null, false); } images[infos[0] + ":" + infos[1]] = "" + infos[2]; } } } options.log({ message: "Start Loading " + options.input + " ", level: 'INFO', module: 'mecano/lib/docker/load' }); _this.execute({ cmd: docker.wrap(options, cmd) }); return _this.execute({ cmd: docker.wrap(options, 'images | grep -v \'<none>\' | awk \'{ print $1":"$2":"$3 }\'') }, function(err, executed, out, stderr) { var diff, j, len1, new_image, new_images, new_k, ref2; if (err) { return callback(err, executed, out, stderr); } new_images = {}; diff = false; options.log({ message: 'Comparing new images', level: 'INFO', module: 'mecano/lib/docker/load' }); if (string.lines(stdout).length > 1) { ref2 = string.lines(out.toString()); for (j = 0, len1 = ref2.length; j < len1; j++) { image = ref2[j]; if (image !== '') { infos = image.split(':'); new_images[infos[0] + ":" + infos[1]] = "" + infos[2]; } } } for (new_k in new_images) { new_image = new_images[new_k]; if (images[new_k] == null) { diff = true; break; } else { for (k in images) { image = images[k]; if (image !== new_image && new_k === k) { diff = true; options.log({ message: 'Identical images', level: 'INFO', module: 'mecano/lib/docker/load' }); break; } } } } return callback(err, diff, stdout, stderr); }); }; })(this)); }; docker = require('../misc/docker'); string = require('../misc/string'); util = require('util');