From c4ce096fa97904c10ad9381c66d656cacf50204e Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Mon, 4 Mar 2024 20:25:39 -0800 Subject: [PATCH] Improve database selection. (#66) * Improve database selection. * Make sure we add dbConfig. * Remove laravel references. * Get rid of laravel reference. * Correct doc comments. --- .github/workflows/pr-wordpress-tests.yml | 2 + CHANGELOG.md | 6 +++ builders/wordpress.js | 14 +++++-- examples/wordpress-downstreamer-1/.lando.yml | 11 +++++ examples/wordpress-downstreamer-1/README.md | 44 ++++++++++++++++++++ examples/wordpress-downstreamer-1/index.php | 1 + examples/wordpress-downstreamer-1/info.php | 1 + examples/wordpress-downstreamer-2/.lando.yml | 11 +++++ examples/wordpress-downstreamer-2/README.md | 44 ++++++++++++++++++++ examples/wordpress-downstreamer-2/index.php | 1 + examples/wordpress-downstreamer-2/info.php | 1 + 11 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 examples/wordpress-downstreamer-1/.lando.yml create mode 100644 examples/wordpress-downstreamer-1/README.md create mode 100644 examples/wordpress-downstreamer-1/index.php create mode 100644 examples/wordpress-downstreamer-1/info.php create mode 100644 examples/wordpress-downstreamer-2/.lando.yml create mode 100644 examples/wordpress-downstreamer-2/README.md create mode 100644 examples/wordpress-downstreamer-2/index.php create mode 100644 examples/wordpress-downstreamer-2/info.php diff --git a/.github/workflows/pr-wordpress-tests.yml b/.github/workflows/pr-wordpress-tests.yml index 56a379f..5efe2af 100644 --- a/.github/workflows/pr-wordpress-tests.yml +++ b/.github/workflows/pr-wordpress-tests.yml @@ -14,6 +14,8 @@ jobs: leia-test: - examples/wordpress-custom - examples/wordpress-defaults + - examples/wordpress-downstreamer-1 + - examples/wordpress-downstreamer-2 - examples/wordpress-export - examples/wordpress-import - examples/wordpress-init diff --git a/CHANGELOG.md b/CHANGELOG.md index 010fa7b..e99a605 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v1.2.1 - [March 4, 2024](https://github.com/lando/wordpress/releases/tag/v1.2.1) + +### Fixes + +* Improved `database` selection for purposes of `config` loading, fixes some `database` bootup issues when the `database` type is overriden downstream + ## v1.2.0 - [February 22, 2024](https://github.com/lando/wordpress/releases/tag/v1.2.0) ### New Features diff --git a/builders/wordpress.js b/builders/wordpress.js index 9760f0b..1ad999d 100644 --- a/builders/wordpress.js +++ b/builders/wordpress.js @@ -65,6 +65,13 @@ const getServiceConfig = (options, types = ['php', 'server', 'vhosts']) => { return config; }; +/* + * Helper to get database type + */ +const getDatabaseType = options => { + return _.get(options, '_app.config.services.database.type', options.database) ?? 'mysql'; +}; + // Tooling defaults const toolingDefaults = { 'composer': { @@ -163,11 +170,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 === 'wordpress-mysql' || database === 'mysql' || database === 'mariadb') { if (version === '8.') { options.defaultFiles.database = 'mysql8.cnf'; } else { diff --git a/examples/wordpress-downstreamer-1/.lando.yml b/examples/wordpress-downstreamer-1/.lando.yml new file mode 100644 index 0000000..aca34be --- /dev/null +++ b/examples/wordpress-downstreamer-1/.lando.yml @@ -0,0 +1,11 @@ +name: wordpress-downstreamer-1 +recipe: wordpress + +services: + database: + type: mysql:8.0 + +# do not remove this +plugins: + "@lando/wordpress": ../.. + "@lando/mysql": ../../node_modules/@lando/mysql diff --git a/examples/wordpress-downstreamer-1/README.md b/examples/wordpress-downstreamer-1/README.md new file mode 100644 index 0000000..cfd0f37 --- /dev/null +++ b/examples/wordpress-downstreamer-1/README.md @@ -0,0 +1,44 @@ +# Wordpress Downstreamer Example + +This example exists primarily to test the following documentation: + +* [Wordpress Recipe](https://docs.lando.dev/wordpress/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 -uwordpress -pwordpress wordpress -e quit + +# Should use the defauly mysql8 config file +lando ssh -s database -c "cat /opt/bitnami/mysql/conf/my_custom.cnf" | grep "LANDOWORDPRESSMYSQL8CNF" +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/wordpress-downstreamer-1/index.php b/examples/wordpress-downstreamer-1/index.php new file mode 100644 index 0000000..f39d159 --- /dev/null +++ b/examples/wordpress-downstreamer-1/index.php @@ -0,0 +1 @@ +DEFAULTS diff --git a/examples/wordpress-downstreamer-1/info.php b/examples/wordpress-downstreamer-1/info.php new file mode 100644 index 0000000..147cebc --- /dev/null +++ b/examples/wordpress-downstreamer-1/info.php @@ -0,0 +1 @@ + diff --git a/examples/wordpress-downstreamer-2/.lando.yml b/examples/wordpress-downstreamer-2/.lando.yml new file mode 100644 index 0000000..bbf7197 --- /dev/null +++ b/examples/wordpress-downstreamer-2/.lando.yml @@ -0,0 +1,11 @@ +name: wordpress-downstreamer-2 +recipe: wordpress + +services: + database: + type: wordpress-mysql:8.0 + +# do not remove this +plugins: + "@lando/wordpress": ../.. + "@lando/mysql": ../../node_modules/@lando/mysql diff --git a/examples/wordpress-downstreamer-2/README.md b/examples/wordpress-downstreamer-2/README.md new file mode 100644 index 0000000..cfd0f37 --- /dev/null +++ b/examples/wordpress-downstreamer-2/README.md @@ -0,0 +1,44 @@ +# Wordpress Downstreamer Example + +This example exists primarily to test the following documentation: + +* [Wordpress Recipe](https://docs.lando.dev/wordpress/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 -uwordpress -pwordpress wordpress -e quit + +# Should use the defauly mysql8 config file +lando ssh -s database -c "cat /opt/bitnami/mysql/conf/my_custom.cnf" | grep "LANDOWORDPRESSMYSQL8CNF" +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/wordpress-downstreamer-2/index.php b/examples/wordpress-downstreamer-2/index.php new file mode 100644 index 0000000..f39d159 --- /dev/null +++ b/examples/wordpress-downstreamer-2/index.php @@ -0,0 +1 @@ +DEFAULTS diff --git a/examples/wordpress-downstreamer-2/info.php b/examples/wordpress-downstreamer-2/info.php new file mode 100644 index 0000000..147cebc --- /dev/null +++ b/examples/wordpress-downstreamer-2/info.php @@ -0,0 +1 @@ +