Skip to content

Commit 8d3ee17

Browse files
committed
rework daemon to accomodate new docker desktop cli commands
1 parent 10b27a8 commit 8d3ee17

File tree

4 files changed

+64
-42
lines changed

4 files changed

+64
-42
lines changed

.github/workflows/pr-setup-macos-tests.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ jobs:
6363
stdin: true
6464
- name: docker desktop cli tests
6565
run: |
66-
lando setup -y --debug --skip-networking --skip-common-plugins
67-
docker desktop version || true
68-
/Applications/Docker.app/Contents/Resources/bin/docker desktop version || true
69-
/Applications/Docker.app/Contents/Resources/bin/docker desktop status || true
70-
/Applications/Docker.app/Contents/Resources/bin/docker desktop start || true
71-
/Applications/Docker.app/Contents/Resources/bin/docker desktop status || true
72-
docker desktop status || true
7366
lando setup -y --debug --skip-common-plugins
67+
# docker desktop start --timeout 60
68+
# docker desktop status
69+
# lando setup -y --debug --skip-common-plugins

.github/workflows/pr-setup-windows-tests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,10 @@ jobs:
6060
shell: powershell
6161
stdin: true
6262
debug: true
63+
- name: docker desktop cli tests
64+
shell: powershell
65+
run: |
66+
lando setup -y --debug --skip-common-plugins
67+
# docker desktop start --timeout 60
68+
# docker desktop status
69+
# lando setup -y --debug --skip-common-plugins

examples/setup-windows/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Run the following commands to validate things are rolling as they should.
1111
```bash
1212
# Should dogfood the core plugin we are testing against
1313
lando plugin-add "@lando/core@file:../.."
14+
```
1415

1516
# Should be able to run lando setup
1617
lando setup -y --skip-networking --skip-common-plugins
@@ -27,4 +28,3 @@ Test-Path "$HOME/.lando/certs/LandoCA.crt"
2728

2829
# Should have installed the Lando Development CA
2930
certutil -store Root | findstr /C:"Lando Development CA"
30-
```

lib/daemon.js

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const fs = require('fs');
66
const getDockerBinPath = require('../utils/get-docker-bin-path');
77
const os = require('os');
88
const path = require('path');
9+
const semver = require('semver');
910

1011
const Cache = require('./cache');
1112
const Events = require('./events');
@@ -77,7 +78,7 @@ module.exports = class LandoDaemon {
7778
* @fires post_engine_up
7879
* @return {Promise} A Promise.
7980
*/
80-
up(retry = true, password) {
81+
async up(retry = true, password) {
8182
const debug = require('../utils/debug-shim')(this.log);
8283

8384
// backwards compat
@@ -91,48 +92,66 @@ module.exports = class LandoDaemon {
9192
* @since 3.0.0
9293
* @event pre_engine_up
9394
*/
94-
return this.events.emit('pre-engine-up').then(() => {
95-
// Automatically return true if we are in the GUI and on linux because
96-
// this requires SUDO and because the daemon should always be running on nix
97-
if (this.context !== 'node' && this.platform === 'linux') return Promise.resolve(true);
95+
await this.events.emit('pre-engine-up');
96+
97+
// Automatically return true if we are in the GUI and on linux because
98+
// this requires SUDO and because the daemon should always be running on nix
99+
if (this.context !== 'node' && this.platform === 'linux') return Promise.resolve(true);
100+
101+
// retry func
102+
const starter = async () => {
103+
return await this.isUp().then(async isUp => {
104+
// if we are already up then we are done
105+
if (isUp) return Promise.resolve();
98106

99-
// retry func
100-
const starter = async () => {
101-
return await this.isUp().then(async isUp => {
102-
if (isUp) return Promise.resolve();
107+
try {
108+
switch (this.platform) {
109+
// docker engine
110+
case 'linux': {
111+
const lscript = path.join(this.scriptsDir, 'docker-engine-start.sh');
112+
if (password) await require('../utils/run-elevated')([lscript], {debug, password});
113+
else await require('../utils/run-command')(lscript, {debug});
114+
break;
115+
}
116+
117+
// docker desktop
118+
case 'darwin':
119+
case 'win32':
120+
case 'wsl': {
121+
// get version information
122+
const {desktop} = await this.getVersions();
103123

104-
try {
105-
switch (this.platform) {
106-
case 'darwin':
124+
// if desktop version is >=4.37.1 then use docker desktop cli
125+
if (semver.gte(desktop, '4.37.0', {includePrerelease: true, loose: true})) {
126+
await require('../utils/run-command')('docker', ['desktop', 'start'], {debug: this.debug});
127+
128+
// otherwise mac fallback
129+
} else if (this.platform === 'darwin') {
107130
await require('../utils/run-command')('open', [MACOS_BASE], {debug: this.debug});
108-
break;
109-
case 'linux': {
110-
const lscript = path.join(this.scriptsDir, 'docker-engine-start.sh');
111-
if (password) await require('../utils/run-elevated')([lscript], {debug, password});
112-
else await require('../utils/run-command')(lscript, {debug});
113-
break;
114-
}
115-
case 'win32':
116-
case 'wsl': {
131+
132+
// otherwise windows/wsl fallback
133+
} else {
117134
const wscript = path.join(this.scriptsDir, 'docker-desktop-start.ps1');
118135
await require('../utils/run-powershell-script')(wscript, undefined, {debug: this.debug});
119136
await require('delay')(2000);
120-
break;
121137
}
122-
}
123138

124-
this.debug('build engine started but waiting to connect...');
125-
return Promise.reject();
126-
} catch (error) {
127-
this.debug('could not start build engine with %o', error?.message);
128-
this.debug('%j', error);
129-
return Promise.reject(error);
139+
break;
140+
}
130141
}
131-
});
132-
};
133142

134-
return Promise.retry(starter, retry);
135-
})
143+
this.debug('build engine started but waiting to connect...');
144+
return Promise.reject();
145+
} catch (error) {
146+
this.debug('could not start build engine with %o', error?.message);
147+
this.debug('%j', error);
148+
return Promise.reject(error);
149+
}
150+
});
151+
};
152+
153+
// try to start
154+
await Promise.retry(starter, retry);
136155

137156
/*
138157
* Not officially documented event that allows you to do some things after
@@ -141,7 +160,7 @@ module.exports = class LandoDaemon {
141160
* @since 3.0.0
142161
* @event post_engine_up
143162
*/
144-
.then(() => this.events.emit('post-engine-up'));
163+
await this.events.emit('post-engine-up');
145164
}
146165

147166
down() {

0 commit comments

Comments
 (0)