UNPKG

mecano

Version:

Common functions for system deployment.

62 lines (55 loc) 3.02 kB
// Generated by CoffeeScript 1.11.1 var mecano; mecano = require('..'); module.exports.options = ['api-cors-header', 'bridge', 'bip', 'debug', 'daemon', 'default-gateway', 'default-gateway-v6', 'default-ulimit', 'dns', 'dns-search', 'exec-driver', 'exec-opt', 'exec-root', 'fixed-cidr', 'fixed-cidr-v6', 'group', 'graph', 'host', 'help', 'icc', 'insecure-registry', 'ip', 'ip-forward', 'ip-masq', 'iptables', 'ipv6', 'log-level', 'label', 'log-driver', 'log-opt', 'mtu', 'pidfile', 'registry-mirror', 'storage-driver', 'selinux-enabled', 'storage-opt', 'tls', 'tlscacert', 'tlscert', 'tlskey', 'tlsverify', 'userland-proxy', 'version']; /* Build the docker command Accepted options are referenced in "module.exports.options". Also accept "machine" and "boot2docker". `compose` option allow to wrap the command for docker-compose instead of docker */ module.exports.wrap = function(options, cmd) { var docker, exe, option, value; docker = {}; if (options.compose == null) { options.compose = false; } if (docker.opts == null) { docker.opts = ''; } if (!options.compose) { docker.opts = (function() { var i, len, ref, results; ref = module.exports.options; results = []; for (i = 0, len = ref.length; i < len; i++) { option = ref[i]; value = void 0; if (options.docker[option]) { value = options.docker[option]; } else if (options[option]) { value = options.docker[option]; } if (value == null) { continue; } if (value === true) { value = 'true'; } if (value === false) { value = 'false'; } results.push("--" + option + " " + value); } return results; })(); docker.opts = docker.opts.join(' '); } exe = options.compose ? 'bin_compose' : 'bin_docker'; return "export SHELL=/bin/bash\nexport PATH=/opt/local/bin/:/opt/local/sbin/:/usr/local/bin/:/usr/local/sbin/:$PATH\nbin_boot2docker=$(command -v boot2docker)\nbin_docker=$(command -v docker)\nbin_machine=$(command -v docker-machine)\nbin_compose=$(command -v docker-compose)\nmachine='" + (options.machine || '') + "'\nboot2docker='" + (options.boot2docker ? '1' : '') + "'\ndocker=''\nif [[ $machine != '' ]] && [ $bin_machine ]; then\n if [ \"" + (options.machine || '--') + "\" = \"--\" ];then exit 5; fi\n if docker-machine status \"${machine}\" | egrep 'Stopped|Saved'; then\n docker-machine start \"${machine}\";\n fi\n docker=\"eval \\$(\\${bin_machine} env ${machine}) && $" + exe + "\"\nelif [[ $boot2docker != '1' ]] && [ $bin_boot2docker ]; then\n docker=\"eval \\$(\\${bin_boot2docker} shellinit) && $" + exe + "\"\nelse\n docker=\"$" + exe + "\"\nfi\neval $docker " + docker.opts + " " + cmd; }; module.exports.callback = function(err, executed, stdout, stderr) { if (err && /^Error response from daemon/.test(stderr)) { throw Error(stderr.trim().replace('Error response from daemon: ', '')); } };