Skip to content

Commit

Permalink
Merge branch 'main' of github.com:lando/cli into main
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Sep 22, 2023
2 parents 093ba9d + c068dca commit c2ca8b1
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr-runtime-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
leia-test:
- examples/appname
- examples/global
- examples/renderer
- examples/v3
- examples/v4
steps:
Expand Down
48 changes: 48 additions & 0 deletions examples/renderer/.lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: lando-renderer
services:
appserver:
api: 3
type: lando
healthcheck: healthcheck
services:
image: php:8.2-fpm
command: docker-php-entrypoint sleep infinity
volumes:
- "./healthcheck.sh:/usr/local/bin/healthcheck"
nginx:
api: 3
type: lando
healthcheck: healthcheck
services:
image: nginx:1.22.1
command: /docker-entrypoint.sh nginx -g "daemon off;"
ports:
- 80
volumes:
- ./:/usr/share/nginx/html
- "./healthcheck.sh:/usr/local/bin/healthcheck"
run_as_root:
- echo "$(id)" > /run_as_root.txt
- ln -snf /usr/share/zoneinfo/America/New_York /etc/localtime
- echo "America/New_York" > /etc/timezone
overrides:
environment:
THING: STUFF
volumes:
- "./test.txt:/var/www/test.txt"
database:
api: 3
type: lando
healthcheck: healthcheck
services:
image: mariadb:10.4
command: docker-entrypoint.sh mysqld
environment:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: da
MARIADB_MYSQL_LOCALHOST_USER: da
MARIADB_DATABASE: test
MARIADB_USER: test
MARIADB_PASSWORD: test
MARIADB_AUTO_UPGRADE: da
volumes:
- "./healthcheck.sh:/usr/local/bin/healthcheck"
36 changes: 36 additions & 0 deletions examples/renderer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Renderer Example
================

This example exists primarily to test the fallback non-TTY list renderer.

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

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

```bash
# Should start up successfully
lando poweroff
lando start
```

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

Run the following commands to validate things are rolling as they should.

```bash
# Should use the verbose renderer in a non-TTY environment
lando start | grep "\[COMPLETED\]" | wc -l | grep 5
```

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

Run the following commands to trash this app like nothing ever happened.

```bash
# Should be destroyed with success
lando destroy -y
lando poweroff
```
21 changes: 21 additions & 0 deletions examples/renderer/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -eo pipefail

rm -rf /healthy

main () {
local healthfile=/tmp/healthfile

# if healthcheck file does not exist then create it
if [ ! -f $healthfile ]; then
touch $healthfile
fi
# append an X to the healthfile
echo -n "X" >> $healthfile
# run our "healthcheck"
cat $healthfile | grep -w "XXXXX" && rm -rf $healthfile
}

main

touch /healthy
2 changes: 2 additions & 0 deletions examples/renderer/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>HAND ME DOWN!</h1>
<h2>or don't</h2>
25 changes: 17 additions & 8 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,11 @@ module.exports = class Cli {
// run a listr tasks list
async runTaskList(tasks, {
ctx = {},
debugRenderer = 'debug',
debugRendererOptions = {},
renderer = 'default',
rendererDebug = 'debug',
rendererForce = false,
rendererOptions = {},
rendererDebugOptions = {},
listrOptions = {},
} = {}) {
// get the bossman
Expand All @@ -517,32 +517,41 @@ module.exports = class Cli {
|| this.logLevel === 'debug'
|| this.logLevel === 'silly'
)) {
renderer = rendererDebug;
rendererOptions = rendererDebugOptions;
renderer = debugRenderer;
rendererOptions = debugRendererOptions;
}

// attempt to reset the renderer if its a string and has a renderer we can load
if (typeof renderer === 'string' && fs.existsSync(path.resolve(__dirname, '..', 'renderers', `${renderer}.js`))) {
renderer = require(path.resolve(__dirname, '..', 'renderers', renderer));
}
if (typeof debugRenderer === 'string' && fs.existsSync(path.resolve(__dirname, '..', 'renderers', `${debugRenderer}.js`))) {
debugRenderer = require(path.resolve(__dirname, '..', 'renderers', debugRenderer));
}

const defaults = {
ctx,
renderer,
collectErrors: true,
concurrent: true,
showErrorMessage: false,
collectErrors: true,
exitOnError: false,
fallbackRenderer: 'verbose',
renderer,
rendererOptions: {
log: require('@lando/core-next/debug')('lando').extend('cli'),
collapseSubtasks: false,
suffixRetries: false,
showErrorMessage: false,
},
showErrorMessage: false,
};

// construct the runner
const runner = new Manager(_.merge({}, defaults, {...listrOptions, rendererOptions}));
const runner = new Manager(_.merge({}, defaults, {
...listrOptions,
fallbackRendererOptions: debugRendererOptions,
rendererOptions,
}));

// add the tasks
runner.add(tasks);
// run
Expand Down

0 comments on commit c2ca8b1

Please sign in to comment.