diff --git a/build/actions/local/common.js b/build/actions/local/common.js index be87c7af..f340384c 100644 --- a/build/actions/local/common.js +++ b/build/actions/local/common.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.12.4 (function() { - var Docker, Promise, _, chalk, filterOutSupervisorContainer, form; + var Docker, Promise, _, chalk, dockerPort, dockerTimeout, filterOutSupervisorContainer, form; Promise = require('bluebird'); @@ -12,7 +12,11 @@ chalk = require('chalk'); - filterOutSupervisorContainer = function(container) { + exports.dockerPort = dockerPort = 2375; + + exports.dockerTimeout = dockerTimeout = 2000; + + exports.filterOutSupervisorContainer = filterOutSupervisorContainer = function(container) { var i, len, name, ref; ref = container.Names; for (i = 0, len = ref.length; i < len; i++) { @@ -24,86 +28,86 @@ return true; }; - module.exports = { - filterOutSupervisorContainer: filterOutSupervisorContainer, - selectContainerFromDevice: Promise.method(function(deviceIp, filterSupervisor) { - var docker; - if (filterSupervisor == null) { - filterSupervisor = false; + exports.selectContainerFromDevice = Promise.method(function(deviceIp, filterSupervisor) { + var docker; + if (filterSupervisor == null) { + filterSupervisor = false; + } + docker = new Docker({ + host: deviceIp, + port: dockerPort, + timeout: dockerTimeout + }); + return docker.listContainersAsync({ + all: true + }).filter(function(container) { + if (!filterSupervisor) { + return true; } - docker = new Docker({ - host: deviceIp, - port: 2375 - }); - return docker.listContainersAsync({ - all: true - }).filter(function(container) { - if (!filterSupervisor) { - return true; - } - return filterOutSupervisorContainer(container); - }).then(function(containers) { - if (_.isEmpty(containers)) { - throw new Error("No containers found in " + deviceIp); - } - return form.ask({ - message: 'Select a container', - type: 'list', - choices: _.map(containers, function(container) { - var containerName, containerStatus, shortContainerId; - containerName = container.Names[0] || 'Untitled'; - shortContainerId = ('' + container.Id).substr(0, 11); - containerStatus = container.Status; - return { - name: containerName + " (" + shortContainerId + ") - " + containerStatus, - value: container.Id - }; - }) - }); - }); - }), - pipeContainerStream: Promise.method(function(arg) { - var container, deviceIp, docker, follow, name, outStream, ref; - deviceIp = arg.deviceIp, name = arg.name, outStream = arg.outStream, follow = (ref = arg.follow) != null ? ref : false; - docker = new Docker({ - host: deviceIp, - port: 2375 - }); - container = docker.getContainer(name); - return container.inspectAsync().then(function(containerInfo) { - var ref1; - return containerInfo != null ? (ref1 = containerInfo.State) != null ? ref1.Running : void 0 : void 0; - }).then(function(isRunning) { - return container.attachAsync({ - logs: !follow || !isRunning, - stream: follow && isRunning, - stdout: true, - stderr: true - }); - }).then(function(containerStream) { - return containerStream.pipe(outStream); - })["catch"](function(err) { - err = '' + err.statusCode; - if (err === '404') { - return console.log(chalk.red.bold("Container '" + name + "' not found.")); - } - throw err; - }); - }), - getSubShellCommand: function(command) { - var os; - os = require('os'); - if (os.platform() === 'win32') { - return { - program: 'cmd.exe', - args: ['/s', '/c', command] - }; - } else { - return { - program: '/bin/sh', - args: ['-c', command] - }; + return filterOutSupervisorContainer(container); + }).then(function(containers) { + if (_.isEmpty(containers)) { + throw new Error("No containers found in " + deviceIp); } + return form.ask({ + message: 'Select a container', + type: 'list', + choices: _.map(containers, function(container) { + var containerName, containerStatus, shortContainerId; + containerName = container.Names[0] || 'Untitled'; + shortContainerId = ('' + container.Id).substr(0, 11); + containerStatus = container.Status; + return { + name: containerName + " (" + shortContainerId + ") - " + containerStatus, + value: container.Id + }; + }) + }); + }); + }); + + exports.pipeContainerStream = Promise.method(function(arg) { + var container, deviceIp, docker, follow, name, outStream, ref; + deviceIp = arg.deviceIp, name = arg.name, outStream = arg.outStream, follow = (ref = arg.follow) != null ? ref : false; + docker = new Docker({ + host: deviceIp, + port: dockerPort + }); + container = docker.getContainer(name); + return container.inspectAsync().then(function(containerInfo) { + var ref1; + return containerInfo != null ? (ref1 = containerInfo.State) != null ? ref1.Running : void 0 : void 0; + }).then(function(isRunning) { + return container.attachAsync({ + logs: !follow || !isRunning, + stream: follow && isRunning, + stdout: true, + stderr: true + }); + }).then(function(containerStream) { + return containerStream.pipe(outStream); + })["catch"](function(err) { + err = '' + err.statusCode; + if (err === '404') { + return console.log(chalk.red.bold("Container '" + name + "' not found.")); + } + throw err; + }); + }); + + exports.getSubShellCommand = function(command) { + var os; + os = require('os'); + if (os.platform() === 'win32') { + return { + program: 'cmd.exe', + args: ['/s', '/c', command] + }; + } else { + return { + program: '/bin/sh', + args: ['-c', command] + }; } }; diff --git a/build/actions/local/logs.js b/build/actions/local/logs.js index 2f0c688c..05aa09a4 100644 --- a/build/actions/local/logs.js +++ b/build/actions/local/logs.js @@ -34,6 +34,7 @@ limitations under the License. alias: 'a' } ], + root: true, action: function(params, options, done) { var Promise, forms, pipeContainerStream, ref, selectContainerFromDevice; Promise = require('bluebird'); diff --git a/build/actions/local/promote.js b/build/actions/local/promote.js index 3c79c7a0..093af023 100644 --- a/build/actions/local/promote.js +++ b/build/actions/local/promote.js @@ -34,6 +34,7 @@ limitations under the License. alias: 'p' } ], + root: true, action: function(params, options, done) { var Promise, _, child_process, forms, getSubShellCommand, verbose; child_process = require('child_process'); diff --git a/build/actions/local/push.js b/build/actions/local/push.js index 44f0c869..9b75e350 100644 --- a/build/actions/local/push.js +++ b/build/actions/local/push.js @@ -29,6 +29,8 @@ limitations under the License. resinPush.primary = true; + resinPush.root = true; + module.exports = resinPush; }).call(this); diff --git a/build/actions/local/scan.js b/build/actions/local/scan.js index f79e5e71..477b3dee 100644 --- a/build/actions/local/scan.js +++ b/build/actions/local/scan.js @@ -41,14 +41,16 @@ limitations under the License. } ], primary: true, + root: true, action: function(params, options, done) { - var Docker, Promise, SpinnerPromise, _, discover, prettyjson; + var Docker, Promise, SpinnerPromise, _, discover, dockerPort, dockerTimeout, prettyjson, ref; Promise = require('bluebird'); _ = require('lodash'); prettyjson = require('prettyjson'); Docker = require('docker-toolbelt'); discover = require('resin-sync').discover; SpinnerPromise = require('resin-cli-visuals').SpinnerPromise; + ref = require('./common'), dockerPort = ref.dockerPort, dockerTimeout = ref.dockerTimeout; if (options.timeout != null) { options.timeout *= 1000; } @@ -59,13 +61,17 @@ limitations under the License. stopMessage: 'Reporting scan results' }); }).filter(function(arg) { - var address, docker; + var address; address = arg.address; - docker = new Docker({ - host: address, - port: 2375 - }); - return docker.infoAsync()["return"](true).catchReturn(false); + return Promise["try"](function() { + var docker; + docker = new Docker({ + host: address, + port: dockerPort, + timeout: dockerTimeout + }); + return docker.pingAsync(); + })["return"](true).catchReturn(false); }).tap(function(devices) { if (_.isEmpty(devices)) { throw new Error('Could not find any resinOS devices in the local network'); @@ -75,7 +81,8 @@ limitations under the License. host = arg.host, address = arg.address; docker = new Docker({ host: address, - port: 2375 + port: dockerPort, + timeout: dockerTimeout }); return Promise.props({ dockerInfo: docker.infoAsync().catchReturn('Could not get Docker info'), diff --git a/build/actions/local/ssh.js b/build/actions/local/ssh.js index d34d231a..74636c32 100644 --- a/build/actions/local/ssh.js +++ b/build/actions/local/ssh.js @@ -45,6 +45,7 @@ limitations under the License. alias: 'p' } ], + root: true, action: function(params, options, done) { var Promise, _, child_process, forms, getSubShellCommand, ref, selectContainerFromDevice, verbose; child_process = require('child_process'); diff --git a/build/actions/local/stop.js b/build/actions/local/stop.js index e901e7eb..c5195f03 100644 --- a/build/actions/local/stop.js +++ b/build/actions/local/stop.js @@ -33,6 +33,7 @@ limitations under the License. alias: 'a' } ], + root: true, action: function(params, options, done) { var Promise, ResinLocalDockerUtils, chalk, config, filterOutSupervisorContainer, forms, ref, ref1, selectContainerFromDevice; Promise = require('bluebird');