Skip to content

Commit

Permalink
Merge branch 'main' of github.com:lando/core into 67-windows-dc2
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Oct 6, 2023
2 parents 2f4f9e9 + 3912cc3 commit e7e7992
Show file tree
Hide file tree
Showing 21 changed files with 389 additions and 100 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/pr-core-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
runs-on: ${{ matrix.os }}
env:
TERM: xterm
GITHUB_PAT: ${{ secrets.PIROG_TOKEN }}
strategy:
fail-fast: false
matrix:
Expand All @@ -23,9 +24,11 @@ jobs:
- examples/base
- examples/events
- examples/healthcheck
- examples/init-github
- examples/init-remote
- examples/keys
- examples/l337
- examples/lando-101
# - examples/lando-101
- examples/landofile-custom
- examples/long-name
- examples/networking
Expand Down Expand Up @@ -60,6 +63,12 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.DEPLOY_KEY }}
known_hosts: unnecessary
if_key_exists: replace
- name: Install node ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## v3.20.3 - [October 6, 2023](https://github.com/lando/core/releases/tag/3.20.3)

### Fixes

* Fixed race condition in some init `sources` causing command to run before user was properly setup

### Internal

* Added `inits` directory to list of plugin autoloaders
* Added `none` recipe for testing purposes
* Moved `_lamp` and `_drupaly` recipes into `builders` folder
* Set `inits` directory as the preferred `init` source
* Switched `github` init `source` to use `@octokit/rest`

## v3.20.2 - [September 30, 2023](https://github.com/lando/core/releases/tag/3.20.2)

### Fixes
Expand Down
1 change: 1 addition & 0 deletions examples/init-github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github
38 changes: 38 additions & 0 deletions examples/init-github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Lando Init GitHub Source Example
================================

This example exists primarily to test the following documentation:

* [Lando Init with GitHub Source](https://docs.lando.dev/cli/init.html#github)

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

Run the following commands to get up and running with this example.

```bash
# Should clone code down from GitHub
mkdir -p github && cd github
lando init --source github --recipe none --github-auth="$GITHUB_PAT" --github-repo="[email protected]:lando/lando.git" --github-key-name="$GITHUB_SHA" --yes
```

Verification commands
---------------------

Run the following commands to verify things work as expected

```bash
# Should have a landofile in the approot
cd github && cat .lando.yml
```

Destroy tests
-------------

```bash
# Should remove key
docker run --rm -v "$(pwd)":/data -w /data badouralix/curl-jq:alpine sh -c "/data/remove-key.sh $GITHUB_PAT $GITHUB_SHA"

# Should remove initialized code
rm -rf github
```
23 changes: 23 additions & 0 deletions examples/init-github/remove-key.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
set -e

TOKEN="$1"
TITLE="$2"

ID=$(curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/user/keys | jq -r --arg TITLE "$TITLE" '.[] | select(.title == $TITLE).id')


# TRY TO REMOVE KEY
echo "Trying to remove key $KEYID"...
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/user/keys/${ID}"

echo "REMOVED!"
2 changes: 2 additions & 0 deletions examples/init-remote/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
git
tar
43 changes: 43 additions & 0 deletions examples/init-remote/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Lando Init Remote Source Example
================================

This example exists primarily to test the following documentation:

* [Lando Init with Remote Source](https://docs.lando.dev/cli/init.html#remote-git-repo-or-archive)

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

Run the following commands to get up and running with this example.

```bash
# Should clone code down from a remote git repo
mkdir -p git && cd git
lando init --source remote --recipe none --remote-url="[email protected]:lando/lando.git" --yes

# Should extract code from a remote tar file
mkdir -p tar && cd tar
lando init --source remote --recipe none --remote-url="https://github.com/lando/lando/archive/refs/tags/v3.20.2.tar.gz" --remote-options="--strip-components=1" --yes
```

Verification commands
---------------------

Run the following commands to verify things work as expected

```bash
# Should have a landofile in the approot of the git clone
cd git && cat .lando.yml

# Should have a landofile in the approot of thee extracted tar
cd tar && cat .lando.yml
```

Destroy tests
-------------

```bash
# Should remove initialized code
rm -rf git
rm -rf tar
```
32 changes: 25 additions & 7 deletions lib/lando.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ const BOOTSTRAP_LEVELS = {
const DEFAULT_VERSIONS = {networking: 1};

// Helper to get init config
const getInitConfig = dirs => _(dirs)
const getLegacyInitConfig = dirs => _(dirs)
.filter(dir => fs.existsSync(dir))
.flatMap(dir => glob.sync(path.join(dir, '*', 'init.js')))
.map(file => require(file))
.value();

// Helper to get init config
const getInitConfig = dirs => _(dirs)
.filter(dir => fs.existsSync(dir))
.flatMap(dir => fs.readdirSync(dir).map(file => path.join(dir, file)))
.map(file => require(file))
.value();

// Helper to get init source config
const getInitSourceConfig = dirs => _(dirs)
.filter(dir => fs.existsSync(dir))
Expand Down Expand Up @@ -64,14 +71,25 @@ const bootstrapConfig = lando => {
* Helper to bootstrap tasks
*/
const bootstrapTasks = lando => {
// Load in config from init and source plugins
const inits = getInitConfig(_.map(lando.config.plugins, 'recipes'));
// Load in config from inits
const legacyInits = getLegacyInitConfig(_.map(lando.config.plugins, 'recipes'));
const inits = getInitConfig(_.map(lando.config.plugins, 'inits'));
lando.config.inits = _.sortBy(_.map(_.merge(
{},
_.fromPairs(_.map(legacyInits, init => ([init.name, init]))),
_.fromPairs(_.map(inits, init => ([init.name, init]))),
), init => init), 'name');

// Load in config frmo sources
const sources = getInitSourceConfig(_.map(lando.config.plugins, 'sources'));
const initSources = _(inits).filter(init => _.has(init, 'sources')).flatMap(init => init.sources).value();
// Sort into useful things and add to config
const initSources = _(lando.config.inits)
.filter(init => _.has(init, 'sources'))
.flatMap(init => init.sources)
.value();
lando.config.sources = _.sortBy(sources.concat(initSources), 'label');
lando.config.recipes = _.sortBy(_.map(inits, init => init.name), 'name');
lando.config.inits = inits;

// And finally the recipes
lando.config.recipes = _.sortBy(_.map(lando.config.inits, init => init.name), 'name');

// Load in all our tasks
return lando.Promise.resolve(lando.config.plugins)
Expand Down
1 change: 1 addition & 0 deletions lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const autoLoaders = [
'app.js',
'builders',
'compose',
'inits',
'methods',
'scripts',
'services',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"test": "yarn lint && yarn test:unit"
},
"dependencies": {
"@octokit/rest": "^19",
"axios": "0.21.4",
"bluebird": "^3.4.1",
"clean-stacktrace": "^1.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

// Modules
const _ = require('lodash');
const LandoLaemp = require('./../laemp/builder.js');
const LandoLaemp = require('./laemp.js');
const semver = require('semver');
const utils = require('./../../lib/utils');
const warnings = require('./../../lib/warnings');
const utils = require('../lib/utils.js');
const warnings = require('../lib/warnings.js');

// "Constants"
const DRUSH8 = '8.4.8';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Modules
const _ = require('lodash');
const fs = require('fs');
const utils = require('./../../lib/utils');
const utils = require('../lib/utils');

// Tooling defaults
const toolingDefaults = {
Expand Down
20 changes: 20 additions & 0 deletions plugins/lando-recipes/inits/none.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const {nanoid} = require('nanoid');

/*
* Init Lamp
*/
module.exports = {
name: 'none',
overrides: {
name: {
when: answers => {
answers.name = nanoid();
return false;
},
},
webroot: {when: () => false},
},
build: () => false,
};
9 changes: 0 additions & 9 deletions plugins/lando-recipes/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ const defaultOpts = {
},
};

// Helper to get source option conflicts
/*
const getConflicts = (name, all, lando) => _(all)
.filter(one => _.has(one, 'options'))
.flatMap(one => _.keys(one.options(lando)))
.thru(options => _.difference(options, _.keys(_.find(all, {name}).options(lando))))
.value();
*/

// Name Opts
const nameOpts = {
describe: 'The name of the app',
Expand Down
19 changes: 19 additions & 0 deletions plugins/lando-recipes/scripts/wait-for-user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e

# user info
user="${1:-$LANDO_WEBROOT_USER}"
id="${2:-$LANDO_HOST_UID}"

# retry settings
attempt=0
delay=1
retry=5

until [ "$attempt" -ge "$retry" ]
do
id "$user"| grep uid | grep "$id" &>/dev/null && break
attempt=$((attempt+1))
sleep "$delay"
done
Loading

0 comments on commit e7e7992

Please sign in to comment.