From f326994f8ecc0b757365db98bba8ad5353723ea3 Mon Sep 17 00:00:00 2001 From: Paulo Castro Date: Mon, 6 Jul 2020 17:08:47 +0100 Subject: [PATCH] build/deploy/preload: Accept DOCKER_CERT_PATH and DOCKER_TLS_VERIFY env vars This allows the build and deploy commands to work with 'docker-machine' (the preload command still does not work with docker-machine, though). Resolves: #1844 Change-type: minor --- lib/utils/docker-js.js | 40 ++++++++++++++++++++++++++++------------ npm-shrinkwrap.json | 20 ++++++++++---------- package.json | 2 +- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/lib/utils/docker-js.js b/lib/utils/docker-js.js index fe96d1b5..737be3ff 100644 --- a/lib/utils/docker-js.js +++ b/lib/utils/docker-js.js @@ -112,28 +112,44 @@ const generateConnectOpts = function (opts) { return Bluebird.try(function () { const connectOpts = {}; - // Firsly need to decide between a local docker socket - // and a host available over a host:port combo + + // Start with docker-modem defaults which take several env vars into account, + // including DOCKER_HOST, DOCKER_TLS_VERIFY, DOCKER_CERT_PATH, SSH_AUTH_SOCK + // https://github.com/apocas/docker-modem/blob/v2.1.3/lib/modem.js#L15-L65 + const Modem = require('docker-modem'); + const defaultOpts = new Modem(); + const optsOfInterest = [ + 'ca', + 'cert', + 'key', + 'host', + 'port', + 'socketPath', + 'protocol', + 'username', + 'sshAuthAgent', + 'timeout', + ]; + for (const opt of optsOfInterest) { + connectOpts[opt] = defaultOpts[opt]; + } + + // Now override the default options with any explicit command line options if (opts.docker != null && opts.dockerHost == null) { // good, local docker socket connectOpts.socketPath = opts.docker; + delete connectOpts.host; + delete connectOpts.port; } else if (opts.dockerHost != null && opts.docker == null) { // Good a host is provided, and local socket isn't connectOpts.host = opts.dockerHost; connectOpts.port = opts.dockerPort || 2376; + delete connectOpts.socketPath; } else if (opts.docker != null && opts.dockerHost != null) { // Both provided, no obvious way to continue throw new ExpectedError( "Both a local docker socket and docker host have been provided. Don't know how to continue.", ); - } else { - // Use docker-modem defaults which take the DOCKER_HOST env var into account - // https://github.com/apocas/docker-modem/blob/v2.0.2/lib/modem.js#L16-L65 - const Modem = require('docker-modem'); - const defaultOpts = new Modem(); - for (let opt of ['host', 'port', 'socketPath']) { - connectOpts[opt] = defaultOpts[opt]; - } } // Now need to check if the user wants to connect over TLS @@ -275,9 +291,9 @@ var ensureDockerSeemsAccessible = function (docker) { const { exitWithExpectedError } = require('../errors'); return docker .ping() - .catch(() => + .catch((e) => exitWithExpectedError( - 'Docker seems to be unavailable. Is it installed and running?', + `Docker seems to be unavailable. Is it installed and running?\n${e}`, ), ); }; diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index b7572295..9f198afc 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -4989,9 +4989,9 @@ "integrity": "sha512-djh3R7KXkEPm80PXK9xbz8bCfEFuU11Tmf5l9IXKdjBPx91/cOqhwOwtOq6s35B8TqrwY6L4xLphmyYmJT0ZXw==" }, "docker-modem": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/docker-modem/-/docker-modem-2.1.1.tgz", - "integrity": "sha512-zSFwYN4AP38LJhTIOpZMjiDbAqSJbv8+u9i/Xq5XABIeTzgp83VF63epu6sVHWxe+6tfhMXqgV+sYjZWh/UzSQ==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/docker-modem/-/docker-modem-2.1.3.tgz", + "integrity": "sha512-cwaRptBmYZwu/FyhGcqBm2MzXA77W2/E6eVkpOZVDk6PkI9Bjj84xPrXiHMA+OWjzNy+DFjgKh8Q+1hMR7/OHg==", "requires": { "debug": "^4.1.1", "readable-stream": "^3.5.0", @@ -5010,17 +5010,17 @@ } }, "ssh2": { - "version": "0.8.8", - "resolved": "https://registry.npmjs.org/ssh2/-/ssh2-0.8.8.tgz", - "integrity": "sha512-egJVQkf3sbjECTY6rCeg8rgV/fab6S/7E5kpYqHT3Fe/YpfJbLYeA1qTcB2d+LRUUAjqKi7rlbfWkaP66YdpAQ==", + "version": "0.8.9", + "resolved": "https://registry.npmjs.org/ssh2/-/ssh2-0.8.9.tgz", + "integrity": "sha512-GmoNPxWDMkVpMFa9LVVzQZHF6EW3WKmBwL+4/GeILf2hFmix5Isxm7Amamo8o7bHiU0tC+wXsGcUXOxp8ChPaw==", "requires": { - "ssh2-streams": "~0.4.9" + "ssh2-streams": "~0.4.10" } }, "ssh2-streams": { - "version": "0.4.9", - "resolved": "https://registry.npmjs.org/ssh2-streams/-/ssh2-streams-0.4.9.tgz", - "integrity": "sha512-glMQKeYKuA+rLaH16fJC3nZMV1BWklbxuYCR4C5/LlBSf2yaoNRpPU7Ul702xsi5nvYjIx9XDkKBJwrBjkDynw==", + "version": "0.4.10", + "resolved": "https://registry.npmjs.org/ssh2-streams/-/ssh2-streams-0.4.10.tgz", + "integrity": "sha512-8pnlMjvnIZJvmTzUIIA5nT4jr2ZWNNVHwyXfMGdRJbug9TpI3kd99ffglgfSWqujVv/0gxwMsDn9j9RVst8yhQ==", "requires": { "asn1": "~0.2.0", "bcrypt-pbkdf": "^1.0.2", diff --git a/package.json b/package.json index ea0b3fef..55fa5c6f 100644 --- a/package.json +++ b/package.json @@ -207,7 +207,7 @@ "columnify": "^1.5.2", "common-tags": "^1.7.2", "denymount": "^2.3.0", - "docker-modem": "^2.1.1", + "docker-modem": "^2.1.3", "docker-progress": "^4.0.1", "docker-qemu-transpose": "^1.1.1", "docker-toolbelt": "^3.3.8",