Skip to content

Commit

Permalink
Consolidate core part 1, networking, healthcheck, linter (#288)
Browse files Browse the repository at this point in the history
* fix cl

* auto docs release v3.24.0-alpha.2 triggered by @rtfm-47

* resolver

* merge in @lando/healthcheck

* merge in @lando/networking

* BIG LINTIN

* remove networking from examples

* fix legacy scan

* fix landonet setup hook dep resolution

* fixed/added some more tezts

* fixed/added some more tezts part 2

---------

Co-authored-by: rtfm-47 <[email protected]>
  • Loading branch information
pirog and rtfm-47 authored Dec 4, 2024
1 parent 51f7bf1 commit bd39aa1
Show file tree
Hide file tree
Showing 140 changed files with 774 additions and 876 deletions.
17 changes: 15 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
{
"env": {
"node": true,
"mocha": true
"mocha": true,
"es2021": true
},
"parser": "@babel/eslint-parser",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 8,
"requireConfigFile": false
},
"extends": "google",
"extends": [
"eslint:recommended",
"google"
],
"rules": {
"arrow-parens": ["error",
"as-needed"
Expand All @@ -18,6 +22,15 @@
"code": 140,
"ignoreComments": true
}],
"no-empty": ["error", {
"allowEmptyCatch": true
}],
"no-unused-vars": ["error", {
"vars": "all",
"args": "after-used",
"ignoreRestSiblings": false
}],

"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
Expand Down
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

## v3.24.0-alpha.2 - [December 3, 2024](https://github.com/lando/core/releases/tag/v3.24.0-alpha.2)

* This release has no new content it is just a test of dual branch developmebt and `edge` branch release deployment
* This release has no new content it is just a test of dual branch development and `edge` branch release deployment

## v3.24.0-alpha.1 - [December 3, 2024](https://github.com/lando/core/releases/tag/v3.24.0-alpha.1)

* This release has no new content it is just a test of dual branch developmebt and `edge` branch release deployment
* This release has no new content it is just a test of dual branch development and `edge` branch release deployment

## v3.23.15 - [December 3, 2024](https://github.com/lando/core/releases/tag/v3.23.15)

* Disabled `DOCKER_CLI_HINTS` on `lando`
* Fixed bug causing some `lando exec` and tooling commands from not inheriting terminal columns and lines correctly[#277](https://github.com/lando/core/issues/277)
* Fixed bug causing some `lando exec` and tooling commands from not inheriting terminal columns and lines correctly [#277](https://github.com/lando/core/issues/277)
* Fixed bug causing `lando setup` loop on `U Need Setup!`
* Fixed bug causing failed update message when user needs to relaunch terminal
* Improved `ux` for `autosetup`
Expand Down
22 changes: 16 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ module.exports = async (app, lando) => {
// load in and parse v4 services
app.events.on('pre-init', async () => await require('./hooks/app-add-v4-services')(app, lando));

// add in hostname
app.events.on('post-init', 1, async () => await require('./hooks/app-add-hostnames')(app, lando));

// run v3 build steps
app.events.on('post-init', async () => await require('./hooks/app-run-v3-build-steps')(app, lando));

Expand Down Expand Up @@ -166,6 +169,18 @@ module.exports = async (app, lando) => {
// If the app already is installed but we can't determine the builtAgainst, then set it to something bogus
app.events.on('pre-start', async () => await require('./hooks/app-update-built-against-pre')(app, lando));

// add healthchecks
app.events.on('post-start', 1, async () => await require('./hooks/app-add-healthchecks')(app, lando));

// add proxy 2 landonet
app.events.on('post-start', 1, async () => await require('./hooks/app-add-proxy-2-landonet')(app, lando));

// add 2 landonet
app.events.on('post-start', 1, async () => await require('./hooks/app-add-2-landonet')(app, lando));

// run healthchecks
app.events.on('post-start', 2, async () => await require('./hooks/app-run-healthchecks')(app, lando));

// Add path info/shellenv tip if needed
app.events.on('post-start', async () => await require('./hooks/app-add-updates-info')(app, lando));

Expand Down Expand Up @@ -218,15 +233,10 @@ module.exports = async (app, lando) => {
});
}

// LEGACY healthchecks
if (_.get(lando, 'config.healthcheck', true) === 'legacy') {
app.events.on('post-start', 2, async () => await require('./hooks/app-run-legacy-healthchecks')(app, lando));
}

// LEGACY URL Scanner urls
if (_.get(lando, 'config.scanner', true) === 'legacy') {
app.events.on('post-start', 10, async () => await require('./hooks/app-run-legacy-scanner')(app, lando));
};
}

// REturn defualts
return {
Expand Down
2 changes: 1 addition & 1 deletion builders/_appserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ module.exports = {
},
})});
super(id, options, ...sources);
};
}
},
};
2 changes: 1 addition & 1 deletion builders/_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = {
initService.services.init.labels['io.lando.service-container'] = 'TRUE';
initService.services.init.labels['io.lando.init-container'] = 'TRUE';
super('init', _.merge({}, config, {env, home, labels, userConfRoot}), initService);
};
}
},
};

6 changes: 3 additions & 3 deletions builders/_lando.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
type,
userConfRoot,
version,
app = '',
// app = '',
confDest = '',
confSrc = '',
config = {},
Expand All @@ -47,7 +47,7 @@ module.exports = {
supported = ['custom'],
supportedIgnore = false,
root = '',
webroot = '/app',
// webroot = '/app',
} = {},
...sources
) {
Expand Down Expand Up @@ -177,6 +177,6 @@ module.exports = {

// Pass it down
super(id, info, ...sources);
};
}
},
};
2 changes: 1 addition & 1 deletion builders/_landoutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ module.exports = {
sources.push({services: _.set({}, options.name, {environment: options.env, labels: options.labels})});
// Send downstream
super(id, options, ...sources);
};
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
mountService.services.mounter.labels['io.lando.service-container'] = 'TRUE';
mountService.services.mounter.labels['io.lando.mount-container'] = 'TRUE';
super('mounter', _.merge({}, config, {userConfRoot}), mountService);
};
}
},
};

4 changes: 2 additions & 2 deletions builders/_service-v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ module.exports = {
// Add in creds if we have them
if (options.creds) options.info.creds = options.creds;

super(id, options, imageFile, ...sources);
};
super(id, options, ...sources);
}

addBuildStep
},
Expand Down
2 changes: 1 addition & 1 deletion builders/_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ module.exports = {
// Add in creds if we have them
if (options.creds) options.info.creds = options.creds;
super(id, options, ...sources);
};
}
},
};
2 changes: 1 addition & 1 deletion builders/_webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ module.exports = {
webroot: options.webroot,
});
super(id, options, ...sources);
};
}
},
};
22 changes: 7 additions & 15 deletions builders/lando-v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ module.exports = {
fs.accessSync(this.command, fs.constants.X_OK);
} catch {
throw new LandoError(`Command file ${this.command} for ${this.id} is not executable!`, {context: this});
};
}

// now complete the final mapping for container injection
this.addLSF(this.command, `${this.id}-start.sh`, 'user');
Expand Down Expand Up @@ -392,7 +392,7 @@ module.exports = {
// @TODO: allow for file path and single line contents
if (config?.build?.app && typeof config.build.app === 'string') {
this.addHookFile(config?.build?.app, {stage: 'app', hook: 'user'});
};
}

// user image build stuff
// @TODO: image:user image:root?
Expand All @@ -407,7 +407,7 @@ module.exports = {
WORKDIR ${this.workdir}
RUN ${runner}
`});
};
}

// info things
this.info = {hostnames: this.hostnames};
Expand Down Expand Up @@ -558,12 +558,8 @@ module.exports = {

await Promise.all(cstorage.map(async volume => {
const bengine = this.getBengine();
try {
await bengine.createVolume({Name: volume.source, Labels: volume.labels});
this.debug('created service storage volume %o with metadata %o', volume.id, volume.labels);
} catch (error) {
throw error;
}
await bengine.createVolume({Name: volume.source, Labels: volume.labels});
this.debug('created service storage volume %o with metadata %o', volume.id, volume.labels);
}));
}

Expand Down Expand Up @@ -639,12 +635,8 @@ module.exports = {

// and then trash them
await Promise.all(volumes.map(async volume => {
try {
await volume.remove({force: true});
this.debug('removed %o volume %o', this.project, volume.id);
} catch (error) {
throw error;
}
await volume.remove({force: true});
this.debug('removed %o volume %o', this.project, volume.id);
}));
}

Expand Down
2 changes: 1 addition & 1 deletion builders/lando.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ module.exports = {
networks: options.networks,
volumes: options.volumes,
});
};
}
},
};
8 changes: 4 additions & 4 deletions components/l337-v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class L337ServiceV4 extends EventEmitter {

constructor(id, {
appRoot = path.join(os.tmpdir(), project, 'app', id),
buildArgs = {},
// buildArgs = {},
context = path.join(os.tmpdir(), project, 'build-contexts', id),
config = {},
debug = L337ServiceV4.debug,
Expand Down Expand Up @@ -210,8 +210,8 @@ class L337ServiceV4 extends EventEmitter {
args = args
.map(arg => typeof arg === 'string' ? arg.split('=') : arg)
.filter(arg => arg !== null && arg !== undefined)
.filter(([key, value]) => key !== null && key !== undefined)
.filter(([key, value]) => value !== null && value !== undefined)
.filter(([key]) => key !== null && key !== undefined)
.filter(([, value]) => value !== null && value !== undefined)
.map(([key, value]) => ([key, String(value)]))
.map(([key, value]) => ([key.trim(), value.trim()]));

Expand Down Expand Up @@ -793,6 +793,6 @@ class L337ServiceV4 extends EventEmitter {
// log
this.debug('%o set base image to %o with instructions %o', this.id, this.#data.image, this.#data.imageInstructions);
}
};
}

module.exports = L337ServiceV4;
12 changes: 7 additions & 5 deletions components/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Plugin {
config = {},
commit,
debug = Plugin.debug,
id = Plugin.id || 'lando',
id = Plugin.id ?? 'lando',
installer = Plugin.installer,
loadOpts = [],
type = 'app',
Expand All @@ -161,6 +161,7 @@ class Plugin {
this.installer = installer;
this.type = type;
this.legacyPlugin = false;
this.id = id;

// if there isnt a package.json we have a more complicated situation
if (!fs.existsSync(path.join(this.root, 'package.json'))) {
Expand Down Expand Up @@ -195,12 +196,13 @@ class Plugin {
this.nm = path.join(this.root, 'node_modules');
this.debug = debug.extend(this.name);
this.package = this.pjson.name;
this.version = this.pjson.version;
this.version = version ?? this.pjson.version;

// extract the plugin config from teh manifest and merge in any user injected config
this.api = this.manifest.api || 4;
this.cspace = this.manifest.cspace || this.name;
this.api = this.manifest.api ?? 4;
this.cspace = this.manifest.cspace ?? this.name;
this.core = this.manifest.core === true || false;
this.hidden = this.manifest.hidden === true || false;
// @NOTE: do we still want to do this?
this.config = merge({}, [this.manifest.config, config[this.cspace]]);

Expand Down Expand Up @@ -238,7 +240,7 @@ class Plugin {
// determine some packaging stuff
this.packaged = has(this.parent, 'pjson.dist') || has(this, 'pjson.dist');
this.source = fs.existsSync(path.join(this.sourceRoot, '.git', 'HEAD'));
this.commit = this.source ? require('../utils/get-commit-hash')(this.sourceRoot, {short: true}) : false;
this.commit = commit ?? this.source ? require('../utils/get-commit-hash')(this.sourceRoot, {short: true}) : false;
// append commit to version if from source
if (this.source && this.commit) this.version = `${this.version}-0-${this.commit}`;

Expand Down
4 changes: 2 additions & 2 deletions components/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ const fileloader = {
case 'string':
return new ImportString(fs.readFileSync(data.file, {encoding: 'utf8'}), data);
case 'yaml':
case 'yaml':
case 'yml':
return new ImportObject(yaml.load(data.file), data);
default:
return new ImportString(fs.readFileSync(data.file, {encoding: 'utf8'}), data);
};
}
},
predicate: data => data instanceof ImportString || data instanceof ImportObject,
represent: data => data.getDumper(),
Expand Down
2 changes: 0 additions & 2 deletions docs/services/lando-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,5 +464,3 @@ In this example the container will boot as `root` do the Lando things it needs t
## Examples

Almost all of the [core tests](https://github.com/lando/core/tree/main/examples) use this service.

HELLO THERE!
2 changes: 0 additions & 2 deletions examples/certs/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,5 @@ tooling:

plugins:
"@lando/core": "../.."
"@lando/healthcheck": "../../plugins/healthcheck"
"@lando/networking": "../../plugins/networking"
"@lando/proxy": "../../plugins/proxy"
"@lando/scanner": "../../plugins/scanner"
2 changes: 0 additions & 2 deletions examples/command/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,5 @@ services:

plugins:
"@lando/core": "../.."
"@lando/healthcheck": "../../plugins/healthcheck"
"@lando/networking": "../../plugins/networking"
"@lando/proxy": "../../plugins/proxy"
"@lando/scanner": "../../plugins/scanner"
4 changes: 2 additions & 2 deletions examples/command/routes/example/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

module.exports = async function(fastify, opts) {
fastify.get('/', async function(request, reply) {
module.exports = async function(fastify) {
fastify.get('/', async function() {
return 'this is an example';
});
};
4 changes: 2 additions & 2 deletions examples/command/routes/root.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

module.exports = async function(fastify, opts) {
fastify.get('/', async function(request, reply) {
module.exports = async function(fastify) {
fastify.get('/', async function() {
return {root: true};
});
};
4 changes: 2 additions & 2 deletions examples/command/routes/thing/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

module.exports = async function(fastify, opts) {
fastify.get('/', async function(request, reply) {
module.exports = async function(fastify) {
fastify.get('/', async function() {
return 'this is a thing';
});
};
1 change: 0 additions & 1 deletion examples/healthcheck/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,3 @@ services:

plugins:
"@lando/core": "../.."
"@lando/healthcheck": "../../plugins/healthcheck"
Loading

0 comments on commit bd39aa1

Please sign in to comment.