Skip to content

Commit

Permalink
improve dc2 renderer and fix some busted setup tasks part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Oct 10, 2024
1 parent c801e29 commit 3b2f116
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
7 changes: 0 additions & 7 deletions hooks/lando-setup-install-ca-darwin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ module.exports = async (lando, options) => {
}
},
canRun: async () => {
if (!await require('../utils/is-admin-user')()) {
throw new Error([
`User "${os.userInfo().username}" does not have permission to install the Lando Development Certificate Authority (CA)!`, // eslint-disable-line
'Contact your system admin for permission and then rerun setup.',
].join(os.EOL));
}

return true;
},
task: async (ctx, task) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = class LandoDaemon {
log = new Log(),
context = 'node',
compose = require('../utils/get-compose-x')(),
orchestratorVersion = '1.29.2',
orchestratorVersion = '2.27.1',
userConfRoot = path.join(os.homedir(), '.lando'),
) {
this.cache = cache;
Expand Down
1 change: 1 addition & 0 deletions lib/lando.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ module.exports = class Lando {
COMPLETED: 'Installed',
STARTED: 'Installing',
FAILED: 'FAILED',
WAITING: 'Waiting',
},
},
});
Expand Down
18 changes: 16 additions & 2 deletions plugins/networking/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,21 @@ module.exports = lando => {
// Add network add task
lando.events.once('pre-setup', async options => {
options.tasks.push({
title: `Upgrading Landonet`,
title: `Creating Landonet`,
id: 'create-landonet',
dependsOn: ['setup-build-engine'],
description: '@lando/landonet',
comments: {
'NOT INSTALLED': 'Will create Landonet',
},
hasRun: async () => {
// if docker isnt even installed then this is easy
if (lando.engine.dockerInstalled === false) return false;

// otherwise attempt to sus things out
try {
const landonet = lando.engine.getNetwork(lando.config.networkBridge);
await lando.engine.daemon.up();
await landonet.inspect();
return lando.versions.networking > 1;
} catch (error) {
Expand All @@ -69,6 +74,14 @@ module.exports = lando => {
}
},
task: async (ctx, task) => {
// we reinstantiate instead of using lando.engine.daemon so we can ensure an up-to-date docker bin
const LandoDaemon = require('../../lib/daemon');
const daemon = new LandoDaemon(lando.cache, lando.events, undefined, lando.log);

// we need docker up for this
await daemon.up();

// if we are v1 then disconnect and remove for upgrade
if (lando.versions.networking === 1) {
const landonet = lando.engine.getNetwork(lando.config.networkBridge);
await landonet.inspect()
Expand All @@ -80,6 +93,7 @@ module.exports = lando => {
});
}

// create landonet2
await lando.engine.getNetworks()
.then(networks => _.some(networks, network => network.Name === lando.config.networkBridge))
.then(exists => {
Expand All @@ -91,7 +105,7 @@ module.exports = lando => {
});
}
});
task.title = 'Upgraded Landonet';
task.title = 'Created Landonet';
},
});
});
Expand Down
9 changes: 5 additions & 4 deletions renderers/dc2.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const getDefaultColor = state => {
return 'green';
case 'FAILED':
return 'red';
case 'WAITING':
return 'yellow';
default:
return 'dim';
}
Expand All @@ -35,6 +37,7 @@ class DC2Renderer extends LandoRenderer {
COMPLETED: {message: 'Done', color: 'green'},
FAILED: {message: 'ERROR', color: 'red'},
STARTED: {message: 'Waiting', color: 'green'},
WAITING: {message: 'Waiting', color: 'yellow'},
...options.states,
};

Expand Down Expand Up @@ -88,7 +91,7 @@ class DC2Renderer extends LandoRenderer {
return render.join(EOL);
}

getMax(tasks = [], spacer = this.options.spacer) {
getMax(tasks = []) {
if (tasks.length === 0) return 0;

const lengths = tasks
Expand All @@ -100,8 +103,6 @@ class DC2Renderer extends LandoRenderer {
task?.message?.error,
]))
.filter(data => typeof data === 'string')
.map(data => data.split(spacer)[0])
.map(data => data.trim())
.map(data => data.length);

return Math.max(...lengths);
Expand All @@ -121,7 +122,7 @@ class DC2Renderer extends LandoRenderer {
output.flatMap((line, index) => {
const task = tasks.filter(task => task.enabled)[index];
const vibe = this.options.states[task.state] ?? this.options.states['STARTED'];
task.spacer = this.getSpacer(task?.message?.error ?? task.title, this.getMax(tasks));
task.spacer = this.getSpacer(task?.message?.error ?? task.title ?? task.initialTitle, this.getMax(tasks));
task.status = color[vibe.color](vibe.message);
output[index] = `${line}${task.spacer}${task.status}`;
});
Expand Down
2 changes: 2 additions & 0 deletions utils/parse-setup-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = otask => {

// update title to reflect pending
task.title = `${initialTitle} ${color.dim(`[Needs ${dids.join(', ')}]`)}`;
task.task.state = 'WAITING';

// wait until all tasks close, for good or ill
try {
Expand All @@ -72,6 +73,7 @@ module.exports = otask => {

// main event
task.title = initialTitle;
task.task.state = 'STARTED';
const result = await orunner(ctx, task);
// harvest
if (otask.count) ctx.results.push(result);
Expand Down

0 comments on commit 3b2f116

Please sign in to comment.