Merge pull request #1921 from balena-io/1844-build-DOCKER_CERT_PATH

build/deploy/preload: Accept DOCKER_CERT_PATH and DOCKER_TLS_VERIFY env vars
This commit is contained in:
bulldozer-balena[bot] 2020-07-07 00:23:06 +00:00 committed by GitHub
commit 89e2bb5945
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 23 deletions

View File

@ -112,28 +112,44 @@ const generateConnectOpts = function (opts) {
return Bluebird.try(function () { return Bluebird.try(function () {
const connectOpts = {}; 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) { if (opts.docker != null && opts.dockerHost == null) {
// good, local docker socket // good, local docker socket
connectOpts.socketPath = opts.docker; connectOpts.socketPath = opts.docker;
delete connectOpts.host;
delete connectOpts.port;
} else if (opts.dockerHost != null && opts.docker == null) { } else if (opts.dockerHost != null && opts.docker == null) {
// Good a host is provided, and local socket isn't // Good a host is provided, and local socket isn't
connectOpts.host = opts.dockerHost; connectOpts.host = opts.dockerHost;
connectOpts.port = opts.dockerPort || 2376; connectOpts.port = opts.dockerPort || 2376;
delete connectOpts.socketPath;
} else if (opts.docker != null && opts.dockerHost != null) { } else if (opts.docker != null && opts.dockerHost != null) {
// Both provided, no obvious way to continue // Both provided, no obvious way to continue
throw new ExpectedError( throw new ExpectedError(
"Both a local docker socket and docker host have been provided. Don't know how to continue.", "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 // Now need to check if the user wants to connect over TLS
@ -275,9 +291,9 @@ var ensureDockerSeemsAccessible = function (docker) {
const { exitWithExpectedError } = require('../errors'); const { exitWithExpectedError } = require('../errors');
return docker return docker
.ping() .ping()
.catch(() => .catch((e) =>
exitWithExpectedError( exitWithExpectedError(
'Docker seems to be unavailable. Is it installed and running?', `Docker seems to be unavailable. Is it installed and running?\n${e}`,
), ),
); );
}; };

20
npm-shrinkwrap.json generated
View File

@ -4989,9 +4989,9 @@
"integrity": "sha512-djh3R7KXkEPm80PXK9xbz8bCfEFuU11Tmf5l9IXKdjBPx91/cOqhwOwtOq6s35B8TqrwY6L4xLphmyYmJT0ZXw==" "integrity": "sha512-djh3R7KXkEPm80PXK9xbz8bCfEFuU11Tmf5l9IXKdjBPx91/cOqhwOwtOq6s35B8TqrwY6L4xLphmyYmJT0ZXw=="
}, },
"docker-modem": { "docker-modem": {
"version": "2.1.1", "version": "2.1.3",
"resolved": "https://registry.npmjs.org/docker-modem/-/docker-modem-2.1.1.tgz", "resolved": "https://registry.npmjs.org/docker-modem/-/docker-modem-2.1.3.tgz",
"integrity": "sha512-zSFwYN4AP38LJhTIOpZMjiDbAqSJbv8+u9i/Xq5XABIeTzgp83VF63epu6sVHWxe+6tfhMXqgV+sYjZWh/UzSQ==", "integrity": "sha512-cwaRptBmYZwu/FyhGcqBm2MzXA77W2/E6eVkpOZVDk6PkI9Bjj84xPrXiHMA+OWjzNy+DFjgKh8Q+1hMR7/OHg==",
"requires": { "requires": {
"debug": "^4.1.1", "debug": "^4.1.1",
"readable-stream": "^3.5.0", "readable-stream": "^3.5.0",
@ -5010,17 +5010,17 @@
} }
}, },
"ssh2": { "ssh2": {
"version": "0.8.8", "version": "0.8.9",
"resolved": "https://registry.npmjs.org/ssh2/-/ssh2-0.8.8.tgz", "resolved": "https://registry.npmjs.org/ssh2/-/ssh2-0.8.9.tgz",
"integrity": "sha512-egJVQkf3sbjECTY6rCeg8rgV/fab6S/7E5kpYqHT3Fe/YpfJbLYeA1qTcB2d+LRUUAjqKi7rlbfWkaP66YdpAQ==", "integrity": "sha512-GmoNPxWDMkVpMFa9LVVzQZHF6EW3WKmBwL+4/GeILf2hFmix5Isxm7Amamo8o7bHiU0tC+wXsGcUXOxp8ChPaw==",
"requires": { "requires": {
"ssh2-streams": "~0.4.9" "ssh2-streams": "~0.4.10"
} }
}, },
"ssh2-streams": { "ssh2-streams": {
"version": "0.4.9", "version": "0.4.10",
"resolved": "https://registry.npmjs.org/ssh2-streams/-/ssh2-streams-0.4.9.tgz", "resolved": "https://registry.npmjs.org/ssh2-streams/-/ssh2-streams-0.4.10.tgz",
"integrity": "sha512-glMQKeYKuA+rLaH16fJC3nZMV1BWklbxuYCR4C5/LlBSf2yaoNRpPU7Ul702xsi5nvYjIx9XDkKBJwrBjkDynw==", "integrity": "sha512-8pnlMjvnIZJvmTzUIIA5nT4jr2ZWNNVHwyXfMGdRJbug9TpI3kd99ffglgfSWqujVv/0gxwMsDn9j9RVst8yhQ==",
"requires": { "requires": {
"asn1": "~0.2.0", "asn1": "~0.2.0",
"bcrypt-pbkdf": "^1.0.2", "bcrypt-pbkdf": "^1.0.2",

View File

@ -207,7 +207,7 @@
"columnify": "^1.5.2", "columnify": "^1.5.2",
"common-tags": "^1.7.2", "common-tags": "^1.7.2",
"denymount": "^2.3.0", "denymount": "^2.3.0",
"docker-modem": "^2.1.1", "docker-modem": "^2.1.3",
"docker-progress": "^4.0.1", "docker-progress": "^4.0.1",
"docker-qemu-transpose": "^1.1.1", "docker-qemu-transpose": "^1.1.1",
"docker-toolbelt": "^3.3.8", "docker-toolbelt": "^3.3.8",