diff --git a/CHANGELOG.md b/CHANGELOG.md index c8d53a0f..e6571cc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Changed +- Provide a helpful warning when Docker is not installed (or is unaccessible) - Added a link to the Node download page in the warning for users with old Node versions ## [6.3.1] - 2017-08-08 diff --git a/build/utils/docker.js b/build/utils/docker.js index 769a2c19..74ea5f5e 100644 --- a/build/utils/docker.js +++ b/build/utils/docker.js @@ -1,5 +1,5 @@ // Generated by CoffeeScript 1.12.7 -var QEMU_BIN_NAME, QEMU_VERSION, cacheHighlightStream, copyQemu, generateConnectOpts, getQemuPath, hasQemu, installQemu, parseBuildArgs, platformNeedsQemu, tarDirectory; +var QEMU_BIN_NAME, QEMU_VERSION, cacheHighlightStream, copyQemu, ensureDockerSeemsAccessible, generateConnectOpts, getQemuPath, hasQemu, installQemu, parseBuildArgs, platformNeedsQemu, tarDirectory; QEMU_VERSION = 'v2.5.50-resin-execve'; @@ -266,7 +266,9 @@ exports.runBuild = function(params, options, getBundleInfo, logger) { return newStream.pipe(logThroughStream).pipe(cacheHighlightStream()).pipe(logger.streams.build); } }; - return generateConnectOpts(options).then(function(connectOpts) { + return generateConnectOpts(options).tap(function(connectOpts) { + return ensureDockerSeemsAccessible(connectOpts); + }).then(function(connectOpts) { var builder, opts; logger.logDebug('Connecting with the following options:'); logger.logDebug(JSON.stringify(connectOpts, null, ' ')); @@ -309,12 +311,26 @@ exports.getDocker = function(options) { var Docker, Promise; Docker = require('dockerode'); Promise = require('bluebird'); - return generateConnectOpts(options).then(function(connectOpts) { + return generateConnectOpts(options).tap(function(connectOpts) { + return ensureDockerSeemsAccessible(connectOpts); + }).then(function(connectOpts) { connectOpts['Promise'] = Promise; return new Docker(connectOpts); }); }; +ensureDockerSeemsAccessible = function(options) { + var fs; + fs = require('mz/fs'); + if (options.socketPath != null) { + return fs.access(options.socketPath, fs.constants.R_OK | fs.constants.W_OK)["return"](true)["catch"](function(err) { + throw new Error("Docker seems to be unavailable (using socket " + options.socketPath + "). Is it installed, and do you have permission to talk to it?"); + }); + } else { + return Promise.resolve(true); + } +}; + hasQemu = function() { var fs; fs = require('mz/fs'); diff --git a/lib/utils/docker.coffee b/lib/utils/docker.coffee index 2f8c8391..8404edec 100644 --- a/lib/utils/docker.coffee +++ b/lib/utils/docker.coffee @@ -175,7 +175,6 @@ parseBuildArgs = (args, onError) -> # Pass in the command line parameters and options and also # a function which will return the information about the bundle exports.runBuild = (params, options, getBundleInfo, logger) -> - Promise = require('bluebird') dockerBuild = require('resin-docker-build') resolver = require('resin-bundle-resolve') @@ -277,8 +276,9 @@ exports.runBuild = (params, options, getBundleInfo, logger) -> # Create a builder generateConnectOpts(options) + .tap (connectOpts) -> + ensureDockerSeemsAccessible(connectOpts) .then (connectOpts) -> - # Allow degugging output, hidden behind an env var logger.logDebug('Connecting with the following options:') logger.logDebug(JSON.stringify(connectOpts, null, ' ')) @@ -317,11 +317,29 @@ exports.getDocker = (options) -> Promise = require('bluebird') generateConnectOpts(options) + .tap (connectOpts) -> + ensureDockerSeemsAccessible(connectOpts) .then (connectOpts) -> # Use bluebird's promises connectOpts['Promise'] = Promise new Docker(connectOpts) +ensureDockerSeemsAccessible = (options) -> + fs = require('mz/fs') + + if options.socketPath? + # If we're trying to use a socket, check it exists and we have access to it + fs.access(options.socketPath, fs.constants.R_OK | fs.constants.W_OK) + .return(true) + .catch (err) -> + throw new Error( + "Docker seems to be unavailable (using socket #{options.socketPath}). Is it + installed, and do you have permission to talk to it?" + ) + else + # Otherwise, we think we're probably ok + Promise.resolve(true) + hasQemu = -> fs = require('mz/fs')