Skip to content

Commit

Permalink
fix tests and improve landoPlatform usage
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Nov 26, 2024
1 parent ab1c0c2 commit 8c00bbc
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion builders/lando-v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ module.exports = {
LANDO_DEBUG: lando.debuggy ? '1' : '',
LANDO_HOST_IP: 'host.lando.internal',
LANDO_HOST_GID: require('../utils/get-gid')(),
LANDO_HOST_OS: process.landoPlatform,
LANDO_HOST_OS: process.platform,
LANDO_HOST_UID: require('../utils/get-uid')(),
LANDO_HOST_USER: require('../utils/get-username')(),
LANDO_LEIA: lando.config.leia === false ? '0' : '1',
Expand Down
2 changes: 1 addition & 1 deletion hooks/lando-autostart-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = async lando => {
},
task: async (ctx, task) => {
// Prompt for sudo password on linux
if (process.landoPlatform === 'linux' && lando.config.isInteractive) {
if (lando.config.os.landoPlatform === 'linux' && lando.config.isInteractive) {
ctx.password = await task.prompt({
type: 'password',
name: 'password',
Expand Down
2 changes: 1 addition & 1 deletion hooks/lando-setup-create-ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = async (lando, options) => {
});

// on wsl we also want to copy the ca to the windows side
if (process.landoPlatform === 'wsl') {
if (lando.config.os.landoPlatform === 'wsl') {
options.tasks.push({
title: `Copy Lando Development CA`,
id: 'install-ca',
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ module.exports = async lando => {
lando.events.on('pre-setup', 0, async () => await require('./hooks/lando-copy-v3-scripts')(lando));

// Ensure we setup docker if needed
lando.events.once('pre-setup', async options => await require(`./hooks/lando-setup-build-engine-${process.landoPlatform}`)(lando, options)); // eslint-disable-line max-len
lando.events.once('pre-setup', async options => await require(`./hooks/lando-setup-build-engine-${lando.config.os.landoPlatform}`)(lando, options)); // eslint-disable-line max-len

// Ensure we create and install ca if needed
lando.events.once('pre-setup', async options => await require('./hooks/lando-setup-create-ca')(lando, options));
lando.events.once('pre-setup', async options => await require(`./hooks/lando-setup-install-ca-${process.landoPlatform}`)(lando, options)); // eslint-disable-line max-len
lando.events.once('pre-setup', async options => await require(`./hooks/lando-setup-install-ca-${lando.config.os.landoPlatform}`)(lando, options)); // eslint-disable-line max-len

// also move scripts for init considerations
lando.events.on('pre-init', 0, async () => await require('./hooks/lando-copy-v3-scripts')(lando));
Expand Down
2 changes: 1 addition & 1 deletion lib/art.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ exports.newContent = (type = 'guide') => [
'',
].join(os.EOL);

exports.setupHeader = (bengine = process.landoPlatform === 'linux' ? 'Engine' : 'Desktop') => `
exports.setupHeader = (bengine = process.landoPlatform ?? process.platform === 'linux' ? 'Engine' : 'Desktop') => `
${chalk.magenta(niceFont('Lando Setup!', 'Small Slant'))}
${chalk.bold('lando setup')} is a hidden convenience command to help you satisify the
Expand Down
21 changes: 11 additions & 10 deletions lib/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ const Shell = require('./shell');
const shell = new Shell();

// Constants
const macOSBase = '/Applications/Docker.app';
const MACOS_BASE = '/Applications/Docker.app';

/*
* Get services wrapper
*/
const buildDockerCmd = (cmd, scriptsDir, dockerBin) => {
const windowsStartScript = path.join(scriptsDir, 'docker-desktop-start.ps1');
switch (process.landoPlatform) {
switch (process.landoPlatform ?? process.platform) {
case 'darwin':
return ['open', macOSBase];
return ['open', MACOS_BASE];
case 'linux':
return [path.join(scriptsDir, `docker-engine-${cmd}.sh`)];
case 'win32':
Expand All @@ -37,7 +37,7 @@ const buildDockerCmd = (cmd, scriptsDir, dockerBin) => {
/*
* Helper to build mac docker version get command
*/
const getMacProp = prop => shell.sh(['defaults', 'read', `${macOSBase}/Contents/Info.plist`, prop])
const getMacProp = prop => shell.sh(['defaults', 'read', `${MACOS_BASE}/Contents/Info.plist`, prop])
.then(data => _.trim(data))
.catch(() => null);

Expand Down Expand Up @@ -65,6 +65,7 @@ module.exports = class LandoDaemon {
this.log = log;
this.scriptsDir = path.join(userConfRoot, 'scripts');
this.isRunning = false;
this.platform = process.landoPlatform ?? process.platform;
};

/*
Expand Down Expand Up @@ -92,10 +93,10 @@ module.exports = class LandoDaemon {
return this.events.emit('pre-engine-up').then(() => {
// Automatically return true if we are in the GUI and on linux because
// this requires SUDO and because the daemon should always be running on nix
if (this.context !== 'node' && process.landoPlatform === 'linux') return Promise.resolve(true);
if (this.context !== 'node' && this.platform === 'linux') return Promise.resolve(true);

// special handling for linux
if (this.context === 'node' && process.landoPlatform === 'linux') {
if (this.context === 'node' && this.platform === 'linux') {
return this.isUp().then(async isUp => {
if (!isUp) {
try {
Expand Down Expand Up @@ -148,7 +149,7 @@ module.exports = class LandoDaemon {
.then(() => {
// Automatically return true if we are in browsery context and on linux because
// this requires SUDO and because the daemon should always be running on nix
if (this.context !== 'node' && process.landoPlatform === 'linux') return Promise.resolve(true);
if (this.context !== 'node' && this.platform === 'linux') return Promise.resolve(true);

// Automatically return if we are on Windows or Darwin because we don't
// ever want to automatically turn the VM off since users might be using
Expand All @@ -159,7 +160,7 @@ module.exports = class LandoDaemon {
//
// @todo: When/if we can run our own isolated docker daemon we can change
// this back.
if (process.landoPlatform === 'darwin' || process.landoPlatform === 'win32' || process.landoPlatform === 'wsl') {
if (this.platform === 'darwin' || this.platform === 'win32' || this.platform === 'wsl') {
return Promise.resolve(true);
}

Expand Down Expand Up @@ -212,15 +213,15 @@ module.exports = class LandoDaemon {
// presumably if we get this far orchestratorVersion is set and orchestratorBin exists
const versions = {compose: this.orchestratorVersion, desktop: false, engine: false};
// try to get either the desktop or engine
switch (process.landoPlatform) {
switch (this.platform) {
case 'darwin':
return getMacProp('CFBundleShortVersionString').then(version => ({...versions, desktop: version}));
case 'linux':
const cmd = [`"${this.docker}"`, 'version', '--format', '{{.Server.Version}}'];
return shell.sh(cmd).catch(() => '18.0.0').then(version => ({...versions, engine: version}));
case 'win32':
case 'wsl':
const componentsVersionFile = process.landoPlatform === 'win32'
const componentsVersionFile = this.platform === 'win32'
? path.resolve(getDockerBinPath('win32'), '..', 'componentsVersion.json') : '/Docker/host/componentsVersion.json';

// if cvf doesnt exist then just set it to something high and dont worry about it?
Expand Down
7 changes: 5 additions & 2 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ module.exports = class Engine {

// Grab the supported ranges for our things
this.supportedVersions = config.dockerSupportedVersions;

// platform
this.platform = process.landoPlatform ?? process.platform;
};

/**
Expand Down Expand Up @@ -183,7 +186,7 @@ module.exports = class Engine {
.map((data, name) => _.merge({}, data, {name}))
.map(data => ([data.name, {
satisfies: data.satisfies || `${data.min} - ${data.max}`,
link: data.link[process.landoPlatform],
link: data.link[this.platform],
tested: data.tested || 'x.x.x',
recommendUpdate: data.recommendUpdate || 'x.x.x',
}]))
Expand All @@ -193,7 +196,7 @@ module.exports = class Engine {
return this.daemon.getVersions().then(versions => {
// Remove the things we don't need depending on platform
// @TODO: Should daemon.getVersions just do this automatically?
if (process.landoPlatform === 'linux') delete versions.desktop;
if (this.platform === 'linux') delete versions.desktop;
else delete versions.engine;

// handle skip
Expand Down
4 changes: 2 additions & 2 deletions plugins/networking/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ module.exports = lando => {
options.tasks.push({
title: `Creating Landonet`,
id: 'create-landonet',
dependsOn: ['linux', 'wsl'].includes(process.landoPlatform) ? ['setup-build-engine-group'] : ['setup-build-engine'],
dependsOn: ['linux', 'wsl'].includes(lando.config.os.landoPlatform) ? ['setup-build-engine-group'] : ['setup-build-engine'],
description: '@lando/landonet',
comments: {
'NOT INSTALLED': 'Will create Landonet',
},
skip: () => {
if (!['linux', 'wsl'].includes(process.landoPlatform)) return false;
if (!['linux', 'wsl'].includes(lando.config.os.landoPlatform)) return false;
return !require('../../utils/is-group-member')('docker');
},
hasRun: async () => {
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module.exports = lando => {
// get defaults from the lando config
const defaults = lando.config.setup;
// determine label for build engine
const buildEngine = process.landoPlatform === 'linux' ? 'docker-engine' : 'docker-desktop';
const buildEngine = process.landoPlatform ?? process.platform === 'linux' ? 'docker-engine' : 'docker-desktop';
// default options
const options = {
'build-engine': {
Expand Down
1 change: 0 additions & 1 deletion test/daemon.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('daemon', () => {
describe('#LandoDaemon', () => {
it('should return an instance with the correct defaults', () => {
const daemon = new Daemon();

daemon.docker.should.equal(getDockerExecutable());
daemon.log.should.be.instanceOf(Log);
return daemon.context.should.equal('node');
Expand Down
8 changes: 4 additions & 4 deletions utils/get-config-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const browsers = ['electron', 'chrome', 'atom-shell'];
const path = require('path');
const os = require('os');

const getBuildEngineVersion = () => {
switch (process.landoPlatform) {
const getBuildEngineVersion = (platform = process.landoPlatform ?? process.platform) => {
switch (platform) {
case 'darwin':
return '4.36.0';
case 'linux':
Expand Down Expand Up @@ -35,7 +35,7 @@ const defaultConfig = options => ({
os: {
type: os.type(),
platform: os.platform(),
landoPlatform: process.landoPlatform,
landoPlatform: process.landoPlatform ?? process.platform,
release: os.release(),
arch: os.arch(),
isWsl: os.release().toLowerCase().includes('microsoft'),
Expand All @@ -48,7 +48,7 @@ const defaultConfig = options => ({
// this governs both autosetup and the defaults of lando setup
// @TODO: orchestrator works a bit differently because it predates lando.setup() we set it elsewhere
setup: {
buildEngine: getBuildEngineVersion(),
buildEngine: getBuildEngineVersion(process.landoPlatform ?? process.platform),
buildEngineAcceptLicense: !require('is-interactive')(),
commonPlugins: {
'@lando/acquia': 'latest',
Expand Down
2 changes: 1 addition & 1 deletion utils/get-docker-bin-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fs = require('fs');
const path = require('path');

module.exports = (platform = process.landoPlatform) => {
module.exports = (platform = process.landoPlatform ?? process.platform) => {
switch (platform) {
case 'darwin':
return '/Applications/Docker.app/Contents/Resources/bin';
Expand Down
4 changes: 2 additions & 2 deletions utils/get-docker-x.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const getDockerBin = (bin, base, pathFallback = true) => {
if (!fs.existsSync(binPath)) return false;

// Otherwise return a normalized binpath
switch (process.landoPlatform) {
switch (process.landoPlatform ?? process.platform) {
case 'darwin': return path.posix.normalize(binPath);
case 'linux': return path.posix.normalize(binPath);
case 'win32': return path.win32.normalize(binPath);
Expand All @@ -28,6 +28,6 @@ const getDockerBin = (bin, base, pathFallback = true) => {
};

module.exports = () => {
const base = (process.landoPlatform === 'linux') ? '/usr/bin' : require('./get-docker-bin-path')();
const base = (process.landoPlatform ?? process.platform === 'linux') ? '/usr/bin' : require('./get-docker-bin-path')();
return getDockerBin('docker', base);
};
4 changes: 2 additions & 2 deletions utils/get-system-cas.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const os = require('os');
*/
module.exports = async ({
format = 'fingerprint',
platform = process.landoPlatform,
platform = process.landoPlatform ?? process.platform,
}= {}) => {
const fingerprints = [];

Expand Down Expand Up @@ -69,6 +69,6 @@ module.exports = async ({

return fingerprints;
default:
throw new Error(`Unsupported platform: ${process.landoPlatform}`);
throw new Error(`Unsupported platform: ${platform}`);
}
};
5 changes: 3 additions & 2 deletions utils/shutdown-os.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ module.exports = ({
message = 'Lando wants to restart your computer',
password = undefined,
type = 'restart',
wait = process.landoPlatform === 'win32' ? 5 : 'now',
wait = process.landoPlatform ?? process.platform === 'win32' ? 5 : 'now',
platform = process.landoPlatform ?? process.platform,
} = {}) => {
debug('shutdown with %o %o', type, {message, wait});

switch (process.landoPlatform) {
switch (platform) {
case 'darwin':
args.push('shutdown');
// handle the restart type
Expand Down

0 comments on commit 8c00bbc

Please sign in to comment.