From 4591616933d815955faaa6e9e622892dc7e91bec Mon Sep 17 00:00:00 2001 From: French Ben Date: Fri, 8 Apr 2016 17:48:33 -0700 Subject: [PATCH 1/2] Added support for Docker for Windows Signed-off-by: French Ben --- src/utils/DockerUtil.js | 10 +++++++++- src/utils/SetupUtil.js | 7 +------ src/utils/Util.js | 20 +++++++++++++++++--- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/utils/DockerUtil.js b/src/utils/DockerUtil.js index 194279193..e30eda14e 100644 --- a/src/utils/DockerUtil.js +++ b/src/utils/DockerUtil.js @@ -30,7 +30,15 @@ export default { if (ip.indexOf('local') !== -1) { try { - this.client = new dockerode({socketPath: '/var/run/docker.sock'}); + if (util.isWindows()) { + this.client = new dockerode({ + protocol: 'http', + host: ip, + port: 2375 + }); + } else { + this.client = new dockerode({socketPath: '/var/run/docker.sock'}); + } } catch (error) { throw new Error('Cannot connect to the Docker daemon. Is the daemon running?'); } diff --git a/src/utils/SetupUtil.js b/src/utils/SetupUtil.js index ed624589e..67a9221ec 100644 --- a/src/utils/SetupUtil.js +++ b/src/utils/SetupUtil.js @@ -69,12 +69,7 @@ export default { while (true) { try { if (util.isNative()) { - let stats = fs.statSync('/var/run/docker.sock'); - if (stats.isSocket()) { - await this.nativeSetup(); - } else { - throw new Error('File found is not a socket'); - } + await this.nativeSetup(); } else { await this.nonNativeSetup(); } diff --git a/src/utils/Util.js b/src/utils/Util.js index 6e15f07a4..8cfebe686 100644 --- a/src/utils/Util.js +++ b/src/utils/Util.js @@ -4,6 +4,7 @@ import fs from 'fs'; import path from 'path'; import crypto from 'crypto'; import electron from 'electron'; +import request from 'request'; const remote = electron.remote; const dialog = remote.dialog; const app = remote.app; @@ -39,11 +40,24 @@ module.exports = { }, isNative: function () { let native = null; - if (native === null) { + if (this.isWindows()) { + native = request.get({ + url: `http://docker.local:2375/version` + }, (error, response, body) => { + if (response.statusCode === 200 ) { + let data = JSON.parse(body); + return data; + } else { + return false; + } + }); + } else { try { // Check if file exists - fs.statSync('/var/run/docker.sock'); - native = true; + let stats = fs.statSync('/var/run/docker.sock'); + if (stats.isSocket()) { + native = true; + } } catch (e) { if (this.isLinux()) { native = true; From 6a8a27aa3f2caa9fd6acb4b70b5b5374902d5331 Mon Sep 17 00:00:00 2001 From: French Ben Date: Fri, 8 Apr 2016 19:45:43 -0700 Subject: [PATCH 2/2] Updated error returned call Signed-off-by: French Ben --- src/utils/Util.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/Util.js b/src/utils/Util.js index 8cfebe686..afe59f9ac 100644 --- a/src/utils/Util.js +++ b/src/utils/Util.js @@ -44,11 +44,11 @@ module.exports = { native = request.get({ url: `http://docker.local:2375/version` }, (error, response, body) => { - if (response.statusCode === 200 ) { + if (error !== null || response.statusCode !== 200 ) { + return false; + } else { let data = JSON.parse(body); return data; - } else { - return false; } }); } else {