From 8975218e1b5bc202df8f362a054a7519f4b592b4 Mon Sep 17 00:00:00 2001 From: Mike Pirog Date: Thu, 29 Feb 2024 10:33:25 -0500 Subject: [PATCH] improve database selection --- .github/workflows/pr-laravel-tests.yml | 9 +++-- CHANGELOG.md | 9 ++++- builders/laravel.js | 15 ++++++-- examples/.gitkeep | 0 examples/.lando.upstream.yml | 2 +- examples/laravel-downstreamer-1/.lando.yml | 11 ++++++ examples/laravel-downstreamer-1/README.md | 44 ++++++++++++++++++++++ examples/laravel-downstreamer-1/index.php | 1 + examples/laravel-downstreamer-1/info.php | 1 + examples/laravel-downstreamer-2/.lando.yml | 11 ++++++ examples/laravel-downstreamer-2/README.md | 44 ++++++++++++++++++++++ examples/laravel-downstreamer-2/index.php | 1 + examples/laravel-downstreamer-2/info.php | 1 + package-lock.json | 2 +- 14 files changed, 142 insertions(+), 9 deletions(-) delete mode 100644 examples/.gitkeep create mode 100644 examples/laravel-downstreamer-1/.lando.yml create mode 100644 examples/laravel-downstreamer-1/README.md create mode 100644 examples/laravel-downstreamer-1/index.php create mode 100644 examples/laravel-downstreamer-1/info.php create mode 100644 examples/laravel-downstreamer-2/.lando.yml create mode 100644 examples/laravel-downstreamer-2/README.md create mode 100644 examples/laravel-downstreamer-2/index.php create mode 100644 examples/laravel-downstreamer-2/info.php diff --git a/.github/workflows/pr-laravel-tests.yml b/.github/workflows/pr-laravel-tests.yml index 2c30f5a..9b31be4 100644 --- a/.github/workflows/pr-laravel-tests.yml +++ b/.github/workflows/pr-laravel-tests.yml @@ -18,15 +18,18 @@ jobs: node-version: - '18' leia-test: - - examples/laravel-init + - examples/7.1 + - examples/7.2 - examples/laravel-custom + - examples/laravel-downstreamer-1 + - examples/laravel-downstreamer-2 - examples/laravel-defaults - examples/laravel-export - examples/laravel-import + - examples/laravel-init - examples/laravel-mysql8 - examples/laravel-nginx - - examples/7.1 - - examples/7.2 + steps: - name: Checkout code uses: actions/checkout@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b4bc53..73f803c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +## v1.3.1 - [February 29, 2024](https://github.com/lando/laravel/releases/tag/v1.3.1) + +### Fixes + +* Improved `database` selection for purposes of `config` loading, fixes some `database` bootup issues when the `database` type is overriden downstream + ## v1.3.0 - [February 27, 2024](https://github.com/lando/laravel/releases/tag/v1.3.0) ### New Features @@ -25,7 +32,7 @@ * Fixed issue with missing proxy URLs. ## v1.0.0 - [December 7, 2023](https://github.com/lando/laravel/releases/tag/v1.0.0) - + * Dialed fully for `lando update` ## v0.9.0 - [July 3, 2023](https://github.com/lando/laravel/releases/tag/v0.9.0) diff --git a/builders/laravel.js b/builders/laravel.js index 9f28dca..aceba31 100644 --- a/builders/laravel.js +++ b/builders/laravel.js @@ -26,6 +26,13 @@ const getCache = cache => { } }; +/* + * Helper to get database type + */ +const getDatabaseType = options => { + return _.get(options, '_app.config.services.database.type', options.database) ?? 'mysql'; +}; + // Tooling defaults const toolingDefaults = { 'composer': { @@ -105,11 +112,12 @@ const getConfigDefaults = options => { // Get the viaconf if (_.startsWith(options.via, 'nginx')) options.defaultFiles.vhosts = 'default.conf.tpl'; - // Get the default db conf - const dbConfig = _.get(options, 'database', 'mysql'); + // attempt to discover the database that is actually being used + // @NOTE: this will look to see if database is overridden + const dbConfig = getDatabaseType(options); const database = _.first(dbConfig.split(':')); const version = _.last(dbConfig.split(':')).substring(0, 2); - if (database === 'mysql' || database === 'mariadb') { + if (database === 'laravel-mysql' || database === 'mysql' || database === 'mariadb') { if (version === '8.') { options.defaultFiles.database = 'mysql8.cnf'; } else { @@ -243,6 +251,7 @@ module.exports = { options.defaultFiles = _.merge({}, getConfigDefaults(_.cloneDeep(options)), options.defaultFiles); options.services = _.merge({}, getServices(options), options.services); options.tooling = _.merge({}, getTooling(options), options.tooling); + // Add in artisan tooling // @NOTE: does artisan always live one up of the webroot? options.tooling.artisan = { diff --git a/examples/.gitkeep b/examples/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/examples/.lando.upstream.yml b/examples/.lando.upstream.yml index 746a5a5..383d2bc 100644 --- a/examples/.lando.upstream.yml +++ b/examples/.lando.upstream.yml @@ -1,2 +1,2 @@ plugins: - "@lando/laravel": ./../../../ + "@lando/laravel": ../../.. diff --git a/examples/laravel-downstreamer-1/.lando.yml b/examples/laravel-downstreamer-1/.lando.yml new file mode 100644 index 0000000..1d93e7c --- /dev/null +++ b/examples/laravel-downstreamer-1/.lando.yml @@ -0,0 +1,11 @@ +name: laravel-downstreamer-1 +recipe: laravel + +services: + database: + type: mysql:8.0 + +# do not remove this +plugins: + "@lando/laravel": ../.. + "@lando/mysql": ../../node_modules/@lando/mysql diff --git a/examples/laravel-downstreamer-1/README.md b/examples/laravel-downstreamer-1/README.md new file mode 100644 index 0000000..342c0fd --- /dev/null +++ b/examples/laravel-downstreamer-1/README.md @@ -0,0 +1,44 @@ +# Laravel Downstreamer Example + +This example exists primarily to test the following documentation: + +* [Laravel Recipe](https://docs.lando.dev/laravel/config.html) + +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 be using mysql8 +lando mysql -V | grep 8.0 + +# Should use the default database connection info +lando mysql -ularavel -plaravel laravel -e quit + +# Should use the defauly mysql8 config file +lando ssh -s database -c "cat /opt/bitnami/mysql/conf/my_custom.cnf" | grep "LANDOLARAVELMYSQL8CNF" +lando mysql -u root -e "show variables;" | grep innodb_lock_wait_timeout | grep 127 +``` + +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/laravel-downstreamer-1/index.php b/examples/laravel-downstreamer-1/index.php new file mode 100644 index 0000000..f39d159 --- /dev/null +++ b/examples/laravel-downstreamer-1/index.php @@ -0,0 +1 @@ +DEFAULTS diff --git a/examples/laravel-downstreamer-1/info.php b/examples/laravel-downstreamer-1/info.php new file mode 100644 index 0000000..147cebc --- /dev/null +++ b/examples/laravel-downstreamer-1/info.php @@ -0,0 +1 @@ + diff --git a/examples/laravel-downstreamer-2/.lando.yml b/examples/laravel-downstreamer-2/.lando.yml new file mode 100644 index 0000000..6c3bf2c --- /dev/null +++ b/examples/laravel-downstreamer-2/.lando.yml @@ -0,0 +1,11 @@ +name: laravel-downstreamer-2 +recipe: laravel + +services: + database: + type: laravel-mysql:8.0 + +# do not remove this +plugins: + "@lando/laravel": ../.. + "@lando/mysql": ../../node_modules/@lando/mysql diff --git a/examples/laravel-downstreamer-2/README.md b/examples/laravel-downstreamer-2/README.md new file mode 100644 index 0000000..342c0fd --- /dev/null +++ b/examples/laravel-downstreamer-2/README.md @@ -0,0 +1,44 @@ +# Laravel Downstreamer Example + +This example exists primarily to test the following documentation: + +* [Laravel Recipe](https://docs.lando.dev/laravel/config.html) + +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 be using mysql8 +lando mysql -V | grep 8.0 + +# Should use the default database connection info +lando mysql -ularavel -plaravel laravel -e quit + +# Should use the defauly mysql8 config file +lando ssh -s database -c "cat /opt/bitnami/mysql/conf/my_custom.cnf" | grep "LANDOLARAVELMYSQL8CNF" +lando mysql -u root -e "show variables;" | grep innodb_lock_wait_timeout | grep 127 +``` + +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/laravel-downstreamer-2/index.php b/examples/laravel-downstreamer-2/index.php new file mode 100644 index 0000000..f39d159 --- /dev/null +++ b/examples/laravel-downstreamer-2/index.php @@ -0,0 +1 @@ +DEFAULTS diff --git a/examples/laravel-downstreamer-2/info.php b/examples/laravel-downstreamer-2/info.php new file mode 100644 index 0000000..147cebc --- /dev/null +++ b/examples/laravel-downstreamer-2/info.php @@ -0,0 +1 @@ + diff --git a/package-lock.json b/package-lock.json index 72f0812..7cd388d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "@lando/laravel", - "version": "1.1.0", + "version": "1.3.0", "license": "GPL-3.0", "dependencies": { "@lando/mariadb": "^1.0.0",