From ac3b7ef4f6a6684baae73dbe5bf5499f2b751572 Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Tue, 26 May 2015 13:57:41 -0700 Subject: [PATCH 1/3] Opt in binary setup --- src/menutemplate.js | 18 ++++++++++++++++++ src/stores/SetupStore-test.js | 15 --------------- src/stores/SetupStore.js | 28 ++++++---------------------- src/utils/DockerMachineUtil.js | 2 +- src/utils/SetupUtil.js | 9 ++++++--- 5 files changed, 31 insertions(+), 41 deletions(-) diff --git a/src/menutemplate.js b/src/menutemplate.js index f673f8d265..36d5b44634 100644 --- a/src/menutemplate.js +++ b/src/menutemplate.js @@ -3,6 +3,7 @@ var app = remote.require('app'); var shell = require('shell'); var router = require('./router'); var util = require('./utils/Util'); +var setupUtil = require('./utils/SetupUtil'); var metrics = require('./utils/MetricsUtil'); var machine = require('./utils/DockerMachineUtil'); import docker from './utils/DockerUtil'; @@ -20,6 +21,23 @@ var MenuTemplate = function () { { type: 'separator' }, + { + label: 'Install Docker Commands', + enabled: true, + click: function () { + metrics.track('Installed Docker Commands'); + if (!setupUtil.shouldUpdateBinaries()) { + return; + } + + if (setupUtil.needsBinaryFix()) { + let cmd = setupUtil.copyBinariesCmd() + ' && ' + setupUtil.fixBinariesCmd(); + util.exec(setupUtil.macSudoCmd(cmd)).catch(() => {}); + } else { + util.exec(setupUtil.copyBinariesCmd()); + } + }, + }, { label: 'Preferences', accelerator: util.CommandOrCtrl() + '+,', diff --git a/src/stores/SetupStore-test.js b/src/stores/SetupStore-test.js index 5613d44aa5..66e0a251f6 100644 --- a/src/stores/SetupStore-test.js +++ b/src/stores/SetupStore-test.js @@ -33,8 +33,6 @@ describe('SetupStore', function () { describe('install step', function () { util.exec.mockReturnValue(Promise.resolve()); - setupUtil.copyBinariesCmd.mockReturnValue(Promise.resolve()); - setupUtil.fixBinariesCmd.mockReturnValue(Promise.resolve()); virtualBox.killall.mockReturnValue(Promise.resolve()); setupUtil.installVirtualBoxCmd.mockReturnValue(Promise.resolve()); setupUtil.macSudoCmd.mockImplementation(cmd => 'macsudo ' + cmd); @@ -44,22 +42,9 @@ describe('SetupStore', function () { util.exec.mockReturnValue(Promise.resolve()); return setupStore.steps().install.run().then(() => { expect(virtualBox.killall).toBeCalled(); - expect(setupUtil.copyBinariesCmd).toBeCalled(); - expect(setupUtil.fixBinariesCmd).toBeCalled(); expect(setupUtil.installVirtualBoxCmd).toBeCalled(); }); }); - - pit('only installs binaries if virtualbox is installed', function () { - virtualBox.installed.mockReturnValue(true); - util.compareVersions.mockReturnValue(0); - setupUtil.needsBinaryFix.mockReturnValue(true); - return setupStore.steps().install.run().then(() => { - expect(setupUtil.copyBinariesCmd).toBeCalled(); - expect(setupUtil.fixBinariesCmd).toBeCalled(); - expect(setupUtil.installVirtualBoxCmd).not.toBeCalled(); - }); - }); }); describe('init step', function () { diff --git a/src/stores/SetupStore.js b/src/stores/SetupStore.js index be11126a6e..f97a8e7cbb 100644 --- a/src/stores/SetupStore.js +++ b/src/stores/SetupStore.js @@ -37,20 +37,14 @@ var _steps = [{ percent: 0, seconds: 5, run: Promise.coroutine(function* (progressCallback) { - var cmd = setupUtil.copyBinariesCmd() + ' && ' + setupUtil.fixBinariesCmd(); if (!virtualBox.installed()) { yield virtualBox.killall(); - cmd += ' && ' + setupUtil.installVirtualBoxCmd(); - } else { - if (!setupUtil.needsBinaryFix()) { - return; - } - } - try { progressCallback(50); // TODO: detect when the installation has started so we can simulate progress - yield util.exec(setupUtil.macSudoCmd(cmd)); - } catch (err) { - throw null; + try { + yield util.exec(setupUtil.macSudoCmd(setupUtil.installVirtualBoxCmd())); + } catch (err) { + throw null; + } } }) }, { @@ -159,7 +153,7 @@ var SetupStore = assign(Object.create(EventEmitter.prototype), { var vboxNeedsInstall = !virtualBox.installed(); required.download = vboxNeedsInstall && (!fs.existsSync(vboxfile) || setupUtil.checksum(vboxfile) !== virtualBox.checksum()); - required.install = vboxNeedsInstall || setupUtil.needsBinaryFix(); + required.install = vboxNeedsInstall; required.init = required.install || !(yield machine.exists()) || (yield machine.state()) !== 'Running' || !isoversion || util.compareVersions(isoversion, packagejson['docker-version']) < 0; var exists = yield machine.exists(); @@ -176,20 +170,10 @@ var SetupStore = assign(Object.create(EventEmitter.prototype), { }); return Promise.resolve(_requiredSteps); }), - updateBinaries: function () { - if (setupUtil.needsBinaryFix()) { - return Promise.resolve(); - } - if (setupUtil.shouldUpdateBinaries()) { - return util.exec(setupUtil.copyBinariesCmd()); - } - return Promise.resolve(); - }, run: Promise.coroutine(function* () { metrics.track('Started Setup', { virtualbox: virtualBox.installed() ? yield virtualBox.version() : 'Not Installed' }); - yield this.updateBinaries(); var steps = yield this.requiredSteps(); for (let step of steps) { _currentStep = step; diff --git a/src/utils/DockerMachineUtil.js b/src/utils/DockerMachineUtil.js index 98399d3c25..b5dceb62d7 100644 --- a/src/utils/DockerMachineUtil.js +++ b/src/utils/DockerMachineUtil.js @@ -156,7 +156,7 @@ var DockerMachine = { }); } else { this.info().then(machine => { - var cmd = [resources.terminal(), `DOCKER_HOST=${machine.url} DOCKER_CERT_PATH=${path.join(util.home(), '.docker/machine/machines/' + machine.name)} DOCKER_TLS_VERIFY=1 $SHELL`]; + var cmd = [resources.terminal(), `PATH=${resources.resourceDir()}:$PATH DOCKER_HOST=${machine.url} DOCKER_CERT_PATH=${path.join(util.home(), '.docker/machine/machines/' + machine.name)} DOCKER_TLS_VERIFY=1 $SHELL`]; util.exec(cmd).then(() => {}); }); } diff --git a/src/utils/SetupUtil.js b/src/utils/SetupUtil.js index 49e2bc0e25..a7697daec1 100644 --- a/src/utils/SetupUtil.js +++ b/src/utils/SetupUtil.js @@ -12,16 +12,19 @@ var virtualBox = require ('./VirtualBoxUtil'); var SetupUtil = { needsBinaryFix() { return this.pathDoesNotExistOrDenied(util.binsPath()) || - this.pathDoesNotExistOrDenied(util.dockerBinPath()) || - this.pathDoesNotExistOrDenied(util.dockerMachineBinPath()); + (fs.existsSync(util.dockerBinPath()) && this.pathDenied(util.dockerBinPath())) || + (fs.existsSync(util.dockerMachineBinPath()) && this.pathDenied(util.dockerMachineBinPath())); }, pathDoesNotExistOrDenied: function (path) { if(util.isWindows()) { return (!fs.existsSync(path)); } else { - return (!fs.existsSync(path) || fs.statSync(path).gid !== 80 || fs.statSync(path).uid !== process.getuid()); + return (!fs.existsSync(path) || this.pathDenied(path)); } }, + pathDenied: function (path) { + return fs.statSync(path).gid !== 80 || fs.statSync(path).uid !== process.getuid(); + }, shouldUpdateBinaries: function () { return !fs.existsSync(util.dockerBinPath()) || !fs.existsSync(util.dockerMachineBinPath()) || From d58b6779dbeb3f71d6f712911e468c9b43993f00 Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Wed, 27 May 2015 18:28:40 -0700 Subject: [PATCH 2/3] Docker-machine 0.3.0 RC with optional binaries --- .gitignore | 2 +- package.json | 2 +- src/menutemplate.js | 39 +++++++++++++++++----------------- src/utils/DockerMachineUtil.js | 2 +- src/utils/DockerUtil.js | 4 +++- src/utils/ResourcesUtil.js | 4 ++-- util/deps | 21 +++++++++--------- util/deps.ps1 | 16 ++++++-------- 8 files changed, 46 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index 3b0964fe5b..e51ebc5468 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ identity* integration # Resources -resources/docker-* +resources/docker* resources/boot2docker-* # Cache diff --git a/package.json b/package.json index 25ce4dd1d3..c8fe0c52b9 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ } ], "docker-version": "1.6.2", - "docker-machine-version": "0.2.0", + "docker-machine-version": "0.3.0", "electron-version": "0.26.0", "virtualbox-version": "4.3.28", "virtualbox-filename": "VirtualBox-4.3.28.pkg", diff --git a/src/menutemplate.js b/src/menutemplate.js index 36d5b44634..4e10b5aea2 100644 --- a/src/menutemplate.js +++ b/src/menutemplate.js @@ -6,6 +6,7 @@ var util = require('./utils/Util'); var setupUtil = require('./utils/SetupUtil'); var metrics = require('./utils/MetricsUtil'); var machine = require('./utils/DockerMachineUtil'); +var dialog = remote.require('dialog'); import docker from './utils/DockerUtil'; // main.js @@ -21,23 +22,6 @@ var MenuTemplate = function () { { type: 'separator' }, - { - label: 'Install Docker Commands', - enabled: true, - click: function () { - metrics.track('Installed Docker Commands'); - if (!setupUtil.shouldUpdateBinaries()) { - return; - } - - if (setupUtil.needsBinaryFix()) { - let cmd = setupUtil.copyBinariesCmd() + ' && ' + setupUtil.fixBinariesCmd(); - util.exec(setupUtil.macSudoCmd(cmd)).catch(() => {}); - } else { - util.exec(setupUtil.copyBinariesCmd()); - } - }, - }, { label: 'Preferences', accelerator: util.CommandOrCtrl() + '+,', @@ -53,8 +37,25 @@ var MenuTemplate = function () { type: 'separator' }, { - label: 'Services', - submenu: [] + label: 'Install Docker Commands', + enabled: true, + click: function () { + metrics.track('Installed Docker Commands'); + if (!setupUtil.shouldUpdateBinaries()) { + return; + } + + let copy = setupUtil.needsBinaryFix() ? + util.exec(setupUtil.copyBinariesCmd() + ' && ' + setupUtil.fixBinariesCmd()) : + util.exec(setupUtil.copyBinariesCmd()); + + copy.then(() => { + dialog.showMessageBox({ + message: 'Docker Binaries have been copied to /usr/local/bin', + buttons: ['OK'] + }); + }).catch(() => {}); + }, }, { type: 'separator' diff --git a/src/utils/DockerMachineUtil.js b/src/utils/DockerMachineUtil.js index b5dceb62d7..3e52871d6c 100644 --- a/src/utils/DockerMachineUtil.js +++ b/src/utils/DockerMachineUtil.js @@ -72,7 +72,7 @@ var DockerMachine = { return util.exec([this.command(), 'rm', '-f', NAME]); }, ip: function () { - return util.exec([this.command(), '-D', 'ip', NAME]).then(stdout => { + return util.exec([this.command(), 'ip', NAME]).then(stdout => { return Promise.resolve(stdout.trim().replace('\n', '')); }); }, diff --git a/src/utils/DockerUtil.js b/src/utils/DockerUtil.js index 0ec52f089e..1109a381d1 100644 --- a/src/utils/DockerUtil.js +++ b/src/utils/DockerUtil.js @@ -17,7 +17,7 @@ export default { setup (ip, name) { if (!ip || !name) { - throw new Error('Falsy ip or machine name passed to init'); + throw new Error('Falsy ip or name passed to docker client setup'); } let certDir = path.join(util.home(), '.docker/machine/machines/', name); @@ -25,6 +25,8 @@ export default { throw new Error('Certificate directory does not exist'); } + console.log(ip); + this.host = ip; this.client = new dockerode({ protocol: 'https', diff --git a/src/utils/ResourcesUtil.js b/src/utils/ResourcesUtil.js index 0c170db73b..9459db8f7b 100644 --- a/src/utils/ResourcesUtil.js +++ b/src/utils/ResourcesUtil.js @@ -12,9 +12,9 @@ module.exports = { return path.join(this.resourceDir(), 'terminal'); }, docker: function () { - return path.join(this.resourceDir(), 'docker-' + util.packagejson()['docker-version'] + util.binsEnding()); + return path.join(this.resourceDir(), 'docker' + util.binsEnding()); }, dockerMachine: function () { - return path.join(this.resourceDir(), 'docker-machine-' + util.packagejson()['docker-machine-version'] + util.binsEnding()); + return path.join(this.resourceDir(), 'docker-machine' + util.binsEnding()); } }; diff --git a/util/deps b/util/deps index fc06cb505d..25afdbb19c 100755 --- a/util/deps +++ b/util/deps @@ -1,29 +1,30 @@ #!/bin/bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" BASE=$DIR/.. -DOCKER_MACHINE_CLI_VERSION=$(node -pe "JSON.parse(process.argv[1])['docker-machine-version']" "$(cat $BASE/package.json)") -DOCKER_MACHINE_CLI_FILE=docker-machine-$DOCKER_MACHINE_CLI_VERSION DOCKER_VERSION=$(node -pe "JSON.parse(process.argv[1])['docker-version']" "$(cat $BASE/package.json)") -DOCKER_CLI_FILE=docker-$DOCKER_VERSION +DOCKER_MACHINE_VERSION=$(node -pe "JSON.parse(process.argv[1])['docker-machine-version']" "$(cat $BASE/package.json)") +CURRENT_DOCKER_VERSION=$($BASE/resources/docker -v | cut -d ',' -f1 | awk '{print $3}' | cut -d '-' -f1) +CURRENT_DOCKER_MACHINE_VERSION=$($BASE/resources/docker-machine -v | cut -d ',' -f1 | awk '{print $3}' | cut -d '-' -f1) BOOT2DOCKER_FILE=boot2docker-$DOCKER_VERSION.iso pushd $BASE/resources > /dev/null -if [ ! -f $DOCKER_CLI_FILE ]; then +if [ "$DOCKER_VERSION" != "$CURRENT_DOCKER_VERSION" ]; then echo "-----> Downloading Docker CLI..." + rm -rf docker rm -rf docker-* curl -L -o docker-$DOCKER_VERSION.tgz https://get.docker.com/builds/Darwin/x86_64/docker-$DOCKER_VERSION.tgz tar xvzf docker-$DOCKER_VERSION.tgz --strip=3 rm docker-$DOCKER_VERSION.tgz - mv docker docker-$DOCKER_VERSION - chmod +x $DOCKER_VERSION + chmod +x docker fi -if [ ! -f $DOCKER_MACHINE_CLI_FILE ]; then +if [ "$DOCKER_MACHINE_VERSION" != "$CURRENT_DOCKER_MACHINE_VERSION" ]; then echo "-----> Downloading Docker Machine CLI..." - rm -rf docker-machine* - curl -L -o $DOCKER_MACHINE_CLI_FILE https://github.com/docker/machine/releases/download/v$DOCKER_MACHINE_CLI_VERSION/docker-machine_darwin-amd64 - chmod +x $DOCKER_MACHINE_CLI_FILE + rm -rf docker-machine + rm -rf docker-machine-* + curl -L -o docker-machine https://github.com/docker/machine/releases/download/v$DOCKER_MACHINE_VERSION-rc1/docker-machine_darwin-amd64 + chmod +x docker-machine fi if [ ! -f $BOOT2DOCKER_FILE ]; then diff --git a/util/deps.ps1 b/util/deps.ps1 index caf5f198ce..ba08d6c2ec 100644 --- a/util/deps.ps1 +++ b/util/deps.ps1 @@ -8,21 +8,19 @@ $packageJsonContent = $serializer.DeserializeObject($packageJson) $webclient = New-Object System.Net.WebClient $DOCKER_MACHINE_CLI_VERSION = $packageJsonContent['docker-machine-version'] -$DOCKER_MACHINE_CLI_FILE = 'docker-machine-' + $DOCKER_MACHINE_CLI_VERSION + '.exe' $DOCKER_CLI_VERSION = $packageJsonContent['docker-version'] -$DOCKER_CLI_FILE = 'docker-' + $DOCKER_CLI_VERSION + '.exe' -if(-Not (test-path ($BasePath + '\resources\' + $DOCKER_CLI_FILE))) { +if(-Not (test-path ($BasePath + '\resources\docker'))) { echo "-----> Downloading Docker CLI..." $source = "https://master.dockerproject.com/windows/amd64/docker.exe" - $destination = $BasePath + "\resources\" + $DOCKER_CLI_FILE + $destination = $BasePath + "\resources\docker" $webclient.DownloadFile($source, $destination) } -if(-Not (test-path ($BasePath + '\resources\' + $DOCKER_MACHINE_CLI_FILE))) { - echo "-----> Downloading Docker Machine CLI..." - $source = "https://github.com/docker/machine/releases/download/v0.1.0/docker-machine_windows-amd64.exe" - $destination = $BasePath + "\resources\" + $DOCKER_MACHINE_CLI_FILE +if(-Not (test-path ($BasePath + '\resources\docker-machine'))) { + echo "-----> Downloading Docker Machine CLI..." + $source = "https://github.com/docker/machine/releases/download/v" + $DOCKER_MACHINE_VERSION+ "/docker-machine_windows-amd64.exe" + $destination = $BasePath + "\resources\docker-machine" $webclient.DownloadFile($source, $destination) -} \ No newline at end of file +} From 5f87b07c2b7ea20e18e1606405ed9813c7260b89 Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Wed, 27 May 2015 18:39:16 -0700 Subject: [PATCH 3/3] fixing unit test --- __tests__/SetupStore-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/SetupStore-test.js b/__tests__/SetupStore-test.js index ef9daa1d59..5c693c7331 100644 --- a/__tests__/SetupStore-test.js +++ b/__tests__/SetupStore-test.js @@ -40,7 +40,7 @@ describe('SetupStore', function () { pit('installs virtualbox if it is not installed', function () { virtualBox.installed.mockReturnValue(false); util.exec.mockReturnValue(Promise.resolve()); - return setupStore.steps().install.run().then(() => { + return setupStore.steps().install.run(() => {}).then(() => { expect(virtualBox.killall).toBeCalled(); expect(setupUtil.installVirtualBoxCmd).toBeCalled(); });