Skip to content

Commit

Permalink
improve autosetup to cover init and fix orchestrator reset
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Dec 7, 2024
1 parent b56606f commit ded2332
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 38 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }})

* Fixed bug causing auto setup to not correctly reset the orchestrator binary path
* Improved `lando init` so that it can auto setup if needed

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

* Improved release flow to better accommodate double barrelled development
Expand Down
12 changes: 4 additions & 8 deletions examples/networking/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
Networking Example
==================
# Networking Example

This example exists primarily to test the following documentation:

* [Networking](https://docs.devwithlando.io/config/networking.html)

See the [Landofiles](https://docs.devwithlando.io/config/lando.html) in this directory for the exact magicks.

Start up tests
--------------
## Start up tests

```bash
# Should init and start a lamp app
Expand All @@ -26,8 +24,7 @@ cp -rf .lando.lemp.yml lemp/.lando.yml
cd lemp && lando start
```

Verification commands
---------------------
## Verification commands

Run the following commands to verify things work as expected

Expand Down Expand Up @@ -68,8 +65,7 @@ cd lamp
lando exec database -- mysql -uroot -h database.landolemp.internal -e "quit"
```

Destroy tests
-------------
## Destroy tests

```bash
# Should destroy lamp successfully
Expand Down
4 changes: 4 additions & 0 deletions hooks/lando-run-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ module.exports = async lando => {
await lando.reloadPlugins();
// reload needed config
const {orchestratorBin, orchestratorVersion, dockerBin, engineConfig} = require('../utils/build-config')();
// reset needed config
lando.config = {...lando.config, orchestratorBin, orchestratorVersion, dockerBin, engineConfig};
// we need to explicitly reset this for some reason
lando.config.orchestratorBin = require('../utils/get-compose-x')(lando.config);

// reload engine
lando.engine = require('../utils/setup-engine')(
lando.config,
Expand Down
65 changes: 35 additions & 30 deletions tasks/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const runBuild = (lando, options = {}, steps = []) => lando.Promise.each(steps,
step,
)),
);
};
}
});

module.exports = lando => {
Expand Down Expand Up @@ -80,7 +80,7 @@ module.exports = lando => {
[--yes]
[--other-plugin-provided-options...]`,
options: _.merge(getInitBaseOpts(recipes, sources), configOpts, getInitOveridesOpts(inits, recipes, sources)),
run: options => {
run: async options => {
// Parse options abd and configs
options = parseInitOptions(options);
// Get our recipe and source configs
Expand All @@ -90,44 +90,49 @@ module.exports = lando => {
const buildSteps = (_.has(sourceConfig, 'build')) ? sourceConfig.build(options, lando) : [];
const configStep = (_.has(recipeConfig, 'build')) ? recipeConfig.build : () => {};

// run setup if we need to
await require('../hooks/lando-run-setup')(lando);

// Pre init event and run build steps
// @NOTE: source build steps are designed to grab code from somewhere
return lando.events.emit('pre-init', options, buildSteps).then(() => runBuild(lando, options, buildSteps))
await lando.events.emit('pre-init', options, buildSteps);

// run build
await runBuild(lando, options, buildSteps);

// Run any config steps
// @NOTE: config steps are designed to augmnet the landofile with additional metadata
.then(() => configStep(options, lando))
const config = await configStep(options, lando);

// Compile and dump the yaml
.then((config = {}) => {
// if config is false then it means we want to skip landofile mutation
if (config !== false) {
// Where are we going?
const dest = path.join(options.destination, '.lando.yml');
const landoFile = getYaml(dest, options, lando);

// Get a lower level config if needed, merge in current recipe config
if (options.full) {
const Recipe = lando.factory.get(options.recipe);
const recipeConfig = _.merge({}, landoFile, {app: landoFile.name, _app: {_config: lando.config}});
_.merge(landoFile, new Recipe(landoFile.name, recipeConfig).config);
}

// Merge in any additional configuration options specified
_.forEach(options.option, option => {
const key = _.first(option.split('='));
_.set(landoFile, `config.${key}`, _.last(option.split('=')));
});

// Merge and dump the config file
lando.yaml.dump(dest, _.merge(landoFile, config));
// if config is false then it means we want to skip landofile mutation
if (config !== false) {
// Where are we going?
const dest = path.join(options.destination, '.lando.yml');
const landoFile = getYaml(dest, options, lando);

// Get a lower level config if needed, merge in current recipe config
if (options.full) {
const Recipe = lando.factory.get(options.recipe);
const recipeConfig = _.merge({}, landoFile, {app: landoFile.name, _app: {_config: lando.config}});
_.merge(landoFile, new Recipe(landoFile.name, recipeConfig).config);
}

// Show it
showInit(lando, options);
})
// Merge in any additional configuration options specified
_.forEach(options.option, option => {
const key = _.first(option.split('='));
_.set(landoFile, `config.${key}`, _.last(option.split('=')));
});

// Merge and dump the config file
lando.yaml.dump(dest, _.merge(landoFile, config));
}

// Show it
showInit(lando, options);

// Post init event
.then(() => lando.events.emit('post-init', options));
await lando.events.emit('post-init', options);
},
};
};

0 comments on commit ded2332

Please sign in to comment.