<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[59277] trunk: Build/Test Tools: Add support for MySQL 8.4 to the Docker environment.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/59277">59277</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/59277","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>desrosj</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-10-22 23:41:29 +0000 (Tue, 22 Oct 2024)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Build/Test Tools: Add support for MySQL 8.4 to the Docker environment.
See <a href="https://core.trac.wordpress.org/ticket/62221">#62221</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkdockercomposeyml">trunk/docker-compose.yml</a></li>
<li><a href="#trunktoolslocalenvscriptsdockerjs">trunk/tools/local-env/scripts/docker.js</a></li>
<li><a href="#trunktoolslocalenvscriptsinstalljs">trunk/tools/local-env/scripts/install.js</a></li>
<li><a href="#trunktoolslocalenvscriptsstartjs">trunk/tools/local-env/scripts/start.js</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunktoolslocalenvmysqloldphpconf">trunk/tools/local-env/mysql-old-php.conf</a></li>
<li><a href="#trunktoolslocalenvoldphpmysql84overrideyml">trunk/tools/local-env/old-php-mysql-84.override.yml</a></li>
<li><a href="#trunktoolslocalenvscriptsutilsjs">trunk/tools/local-env/scripts/utils.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkdockercomposeyml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/docker-compose.yml</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/docker-compose.yml 2024-10-22 18:26:53 UTC (rev 59276)
+++ trunk/docker-compose.yml 2024-10-22 23:41:29 UTC (rev 59277)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -79,7 +79,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> - mysql:/var/lib/mysql
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> # For compatibility with PHP versions that don't support the caching_sha2_password auth plugin used in MySQL 8.0.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- command: --default-authentication-plugin=mysql_native_password
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ command: ${LOCAL_DB_AUTH_OPTION-}
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> healthcheck:
</span><span class="cx" style="display: block; padding: 0 10px"> test: [ "CMD-SHELL", "if [ \"$LOCAL_DB_TYPE\" = \"mariadb\" ]; then mariadb-admin ping -h localhost; else mysqladmin ping -h localhost; fi" ]
</span></span></pre></div>
<a id="trunktoolslocalenvmysqloldphpconf"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tools/local-env/mysql-old-php.conf</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tools/local-env/mysql-old-php.conf (rev 0)
+++ trunk/tools/local-env/mysql-old-php.conf 2024-10-22 23:41:29 UTC (rev 59277)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,20 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+##
+# The local Docker environment will try to use the database software's default authentication plugin whenever possible.
+#
+# One exception to this is using PHP 7.2 & 7.3 in combination with MySQL >= 8.0. These versions of PHP lack support for
+# MySQL's caching_sha2_password plugin, which was made the new default in MySQL 8.0.
+#
+# Until MySQL 8.4, this could easily be changed using the --default-authentication-plugin with the old value of
+# mysql_native_password.
+#
+# In MySQL 8.4, the --default-authentication-plugin option was removed in favor of --authentication-policy and
+# mysql_native_password was disabled by default.
+#
+# When mounted to the database container in the local Docker environment, this file turns the old authentication plugin
+# back on so that PHP 7.2 & 7.3 can be used in combination with MySQL 8.4.
+#
+# MySQL 9.0 will remove mysql_native_password.
+##
+
+[mysqld]
+mysql-native-password=ON
</ins></span></pre></div>
<a id="trunktoolslocalenvoldphpmysql84overrideyml"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tools/local-env/old-php-mysql-84.override.yml</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tools/local-env/old-php-mysql-84.override.yml (rev 0)
+++ trunk/tools/local-env/old-php-mysql-84.override.yml 2024-10-22 23:41:29 UTC (rev 59277)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,5 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+services:
+
+ mysql:
+ volumes:
+ - ./tools/local-env/mysql-old-php.conf:/etc/mysql/conf.d/config-file.cnf
</ins></span></pre></div>
<a id="trunktoolslocalenvscriptsdockerjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tools/local-env/scripts/docker.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tools/local-env/scripts/docker.js 2024-10-22 18:26:53 UTC (rev 59276)
+++ trunk/tools/local-env/scripts/docker.js 2024-10-22 23:41:29 UTC (rev 59277)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,8 +1,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> const dotenv = require( 'dotenv' );
</span><span class="cx" style="display: block; padding: 0 10px"> const dotenvExpand = require( 'dotenv-expand' );
</span><span class="cx" style="display: block; padding: 0 10px"> const { execSync } = require( 'child_process' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+const local_env_utils = require( './utils' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> dotenvExpand.expand( dotenv.config() );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+const composeFiles = local_env_utils.get_compose_files();
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Execute any docker compose command passed to this script.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-execSync( 'docker compose ' + process.argv.slice( 2 ).join( ' ' ), { stdio: 'inherit' } );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+execSync( 'docker compose ' + composeFiles + ' ' + process.argv.slice( 2 ).join( ' ' ), { stdio: 'inherit' } );
</ins></span></pre></div>
<a id="trunktoolslocalenvscriptsinstalljs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tools/local-env/scripts/install.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tools/local-env/scripts/install.js 2024-10-22 18:26:53 UTC (rev 59276)
+++ trunk/tools/local-env/scripts/install.js 2024-10-22 23:41:29 UTC (rev 59277)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3,9 +3,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> const wait_on = require( 'wait-on' );
</span><span class="cx" style="display: block; padding: 0 10px"> const { execSync } = require( 'child_process' );
</span><span class="cx" style="display: block; padding: 0 10px"> const { renameSync, readFileSync, writeFileSync } = require( 'fs' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+const { utils } = require( './utils.js' );
+const local_env_utils = require( './utils' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> dotenvExpand.expand( dotenv.config() );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Determine if a non-default database authentication plugin needs to be used.
+local_env_utils.determine_auth_option();
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Create wp-config.php.
</span><span class="cx" style="display: block; padding: 0 10px"> wp_cli( 'config create --dbname=wordpress_develop --dbuser=root --dbpass=password --dbhost=mysql --path=/var/www/src --force' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -48,7 +53,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param {string} cmd The WP-CLI command to run.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_cli( cmd ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- execSync( `docker compose run --rm cli ${cmd}`, { stdio: 'inherit' } );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ const composeFiles = local_env_utils.get_compose_files();
+
+ execSync( `docker compose ${composeFiles} run --rm cli ${cmd}`, { stdio: 'inherit' } );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -56,7 +63,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function install_wp_importer() {
</span><span class="cx" style="display: block; padding: 0 10px"> const testPluginDirectory = 'tests/phpunit/data/plugins/wordpress-importer';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ const composeFiles = local_env_utils.get_compose_files();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- execSync( `docker compose exec -T php rm -rf ${testPluginDirectory}`, { stdio: 'inherit' } );
- execSync( `docker compose exec -T php git clone https://github.com/WordPress/wordpress-importer.git ${testPluginDirectory} --depth=1`, { stdio: 'inherit' } );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ execSync( `docker compose ${composeFiles} exec -T php rm -rf ${testPluginDirectory}`, { stdio: 'inherit' } );
+ execSync( `docker compose ${composeFiles} exec -T php git clone https://github.com/WordPress/wordpress-importer.git ${testPluginDirectory} --depth=1`, { stdio: 'inherit' } );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktoolslocalenvscriptsstartjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tools/local-env/scripts/start.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tools/local-env/scripts/start.js 2024-10-22 18:26:53 UTC (rev 59276)
+++ trunk/tools/local-env/scripts/start.js 2024-10-22 23:41:29 UTC (rev 59277)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,6 +1,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> const dotenv = require( 'dotenv' );
</span><span class="cx" style="display: block; padding: 0 10px"> const dotenvExpand = require( 'dotenv-expand' );
</span><span class="cx" style="display: block; padding: 0 10px"> const { execSync } = require( 'child_process' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+const local_env_utils = require( './utils' );
</ins><span class="cx" style="display: block; padding: 0 10px"> const { constants, copyFile } = require( 'node:fs' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Copy the default .env file when one is not present.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -10,6 +11,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> dotenvExpand.expand( dotenv.config() );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+const composeFiles = local_env_utils.get_compose_files();
+
+// Determine if a non-default database authentication plugin needs to be used.
+local_env_utils.determine_auth_option();
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Check if the Docker service is running.
</span><span class="cx" style="display: block; padding: 0 10px"> try {
</span><span class="cx" style="display: block; padding: 0 10px"> execSync( 'docker info' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -25,7 +31,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> const containers = ( process.env.LOCAL_PHP_MEMCACHED === 'true' )
</span><span class="cx" style="display: block; padding: 0 10px"> ? 'wordpress-develop memcached'
</span><span class="cx" style="display: block; padding: 0 10px"> : 'wordpress-develop';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-execSync( `docker compose up -d ${containers}`, { stdio: 'inherit' } );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+execSync( `docker compose ${composeFiles} up -d ${containers}`, { stdio: 'inherit' } );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If Docker Toolbox is being used, we need to manually forward LOCAL_PORT to the Docker VM.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( process.env.DOCKER_TOOLBOX_INSTALL_PATH ) {
</span></span></pre></div>
<a id="trunktoolslocalenvscriptsutilsjs"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tools/local-env/scripts/utils.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tools/local-env/scripts/utils.js (rev 0)
+++ trunk/tools/local-env/scripts/utils.js 2024-10-22 23:41:29 UTC (rev 59277)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,53 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+const local_env_utils = {
+
+ /**
+ * Determines which Docker compose files are required to properly configure the local environment given the
+ * specified PHP version, database type, and database version.
+ *
+ * By default, only the standard docker-compose.yml file will be used.
+ *
+ * When PHP 7.2 or 7.3 is used in combination with MySQL 8.4, an override file will also be returned to ensure
+ * that the mysql_native_password plugin authentication plugin is on and available for use.
+ */
+ get_compose_files: function() {
+ var composeFiles = '-f docker-compose.yml';
+
+ if ( process.env.LOCAL_DB_TYPE !== 'mysql' ) {
+ return composeFiles;
+ }
+
+ if ( process.env.LOCAL_PHP !== '7.2-fpm' && process.env.LOCAL_PHP !== '7.3-fpm' ) {
+ return composeFiles;
+ }
+
+ // PHP 7.2/7.3 in combination with MySQL 8.4 requires additional configuration to function properly.
+ if ( process.env.LOCAL_DB_VERSION === '8.4' ) {
+ composeFiles = composeFiles + ' -f tools/local-env/old-php-mysql-84.override.yml';
+ }
+
+ return composeFiles;
+ },
+
+ /**
+ * Determines the option to pass for proper authentication plugin configuration given the specified PHP version,
+ * database type, and database version.
+ */
+ determine_auth_option: function() {
+ if ( process.env.LOCAL_DB_TYPE !== 'mysql' ) {
+ return;
+ }
+
+ if ( process.env.LOCAL_PHP !== '7.2-fpm' && process.env.LOCAL_PHP !== '7.3-fpm' ) {
+ return;
+ }
+
+ // MySQL 8.4 removed --default-authentication-plugin in favor of --authentication-policy.
+ if ( process.env.LOCAL_DB_VERSION === '8.4' ) {
+ process.env.LOCAL_DB_AUTH_OPTION = '--authentication-policy=mysql_native_password';
+ } else {
+ process.env.LOCAL_DB_AUTH_OPTION = '--default-authentication-plugin=mysql_native_password';
+ }
+ }
+};
+
+module.exports = local_env_utils;
</ins></span></pre>
</div>
</div>
</body>
</html>