diff --git a/.github/workflows/pr-runtime-tests.yml b/.github/workflows/pr-runtime-tests.yml index 232a8818f..11e5f77c4 100644 --- a/.github/workflows/pr-runtime-tests.yml +++ b/.github/workflows/pr-runtime-tests.yml @@ -18,6 +18,7 @@ jobs: leia-test: - examples/appname - examples/global + - examples/renderer - examples/v3 - examples/v4 steps: diff --git a/examples/renderer/.lando.yml b/examples/renderer/.lando.yml new file mode 100755 index 000000000..8b388c733 --- /dev/null +++ b/examples/renderer/.lando.yml @@ -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" diff --git a/examples/renderer/README.md b/examples/renderer/README.md new file mode 100755 index 000000000..dd82136f6 --- /dev/null +++ b/examples/renderer/README.md @@ -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 +``` diff --git a/examples/renderer/healthcheck.sh b/examples/renderer/healthcheck.sh new file mode 100755 index 000000000..364e03ee5 --- /dev/null +++ b/examples/renderer/healthcheck.sh @@ -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 diff --git a/examples/renderer/index.html b/examples/renderer/index.html new file mode 100644 index 000000000..d47156f57 --- /dev/null +++ b/examples/renderer/index.html @@ -0,0 +1,2 @@ +

HAND ME DOWN!

+

or don't

diff --git a/lib/cli.js b/lib/cli.js index bf81b52ec..2de62c1ab 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -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 @@ -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