From 69c4c9607870b338bcc7ba39f05db6da84406f23 Mon Sep 17 00:00:00 2001 From: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:03:45 +0000 Subject: [PATCH 1/6] wp-env: Add phpMyAdmin support - Add option `--phpmyadmin` to `wp-env start` (off by default) - Defaults to port 9000 - Configurable in .wp-env.json under key `phpmyadminPort` - Overridden by environment variable `WP_ENV_PHPMYADMIN_PORT` --- packages/env/README.md | 2 +- .../env/lib/build-docker-compose-config.js | 13 +++++++++ packages/env/lib/cli.js | 6 +++++ packages/env/lib/commands/start.js | 21 +++++++++++---- .../get-config-from-environment-vars.js | 3 +++ packages/env/lib/config/parse-config.js | 27 +++++++++++++------ .../__snapshots__/config-integration.js.snap | 8 ++++++ packages/env/lib/config/test/parse-config.js | 1 + packages/env/lib/validate-run-container.js | 1 + 9 files changed, 68 insertions(+), 14 deletions(-) diff --git a/packages/env/README.md b/packages/env/README.md index 35b00fe83e8f4d..af037f5ee80ab6 100644 --- a/packages/env/README.md +++ b/packages/env/README.md @@ -349,7 +349,7 @@ containers. Positionals: container The Docker service to run the command on. [string] [required] [choices: "mysql", "tests-mysql", "wordpress", - "tests-wordpress", "cli", "tests-cli", "composer", "phpunit"] + "tests-wordpress", "cli", "tests-cli", "composer", "phpmyadmin"] command The command to run. [required] Options: diff --git a/packages/env/lib/build-docker-compose-config.js b/packages/env/lib/build-docker-compose-config.js index a394537e360872..88e4d0bb241b28 100644 --- a/packages/env/lib/build-docker-compose-config.js +++ b/packages/env/lib/build-docker-compose-config.js @@ -173,6 +173,9 @@ module.exports = function buildDockerComposeConfig( config ) { const testsMysqlPorts = `\${WP_ENV_TESTS_MYSQL_PORT:-${ config.env.tests.mysqlPort ?? '' }}:3306`; + const phpmyadminPorts = `\${WP_ENV_PHPMYADMIN_PORT:-${ + config.env.development.phpmyadminPort ?? '' + }}:80`; return { services: { @@ -266,6 +269,16 @@ module.exports = function buildDockerComposeConfig( config ) { }, extra_hosts: [ 'host.docker.internal:host-gateway' ], }, + phpmyadmin: { + image: 'phpmyadmin', + ports: [ phpmyadminPorts ], + environment: { + PMA_PORT: 3306, + PMA_HOST: 'mysql', + PMA_USER: 'root', + PMA_PASSWORD: 'password', + }, + }, }, volumes: { ...( ! config.env.development.coreSource && { wordpress: {} } ), diff --git a/packages/env/lib/cli.js b/packages/env/lib/cli.js index 896df6cd59fed0..5eefffa1983b40 100644 --- a/packages/env/lib/cli.js +++ b/packages/env/lib/cli.js @@ -133,6 +133,12 @@ module.exports = function cli() { 'Download source updates and apply WordPress configuration.', default: false, } ); + args.option( 'phpmyadmin', { + describe: + 'Enables PHPMyAdmin. By default, a PHPMyAdmin server will be available on port 9000 (override with WP_ENV_PHPMYADMIN_PORT).', + type: 'boolean', + default: false, + } ); args.option( 'xdebug', { describe: 'Enables Xdebug. If not passed, Xdebug is turned off. If no modes are set, uses "debug". You may set multiple Xdebug modes by passing them in a comma-separated list: `--xdebug=develop,coverage`. See https://xdebug.org/docs/all_settings#mode for information about Xdebug modes.', diff --git a/packages/env/lib/commands/start.js b/packages/env/lib/commands/start.js index 4203ac74632287..ae084d296b5ba1 100644 --- a/packages/env/lib/commands/start.js +++ b/packages/env/lib/commands/start.js @@ -43,16 +43,18 @@ const CONFIG_CACHE_KEY = 'config_checksum'; * Starts the development server. * * @param {Object} options - * @param {Object} options.spinner A CLI spinner which indicates progress. - * @param {boolean} options.update If true, update sources. - * @param {string} options.xdebug The Xdebug mode to set. - * @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed. - * @param {boolean} options.debug True if debug mode is enabled. + * @param {Object} options.spinner A CLI spinner which indicates progress. + * @param {boolean} options.update If true, update sources. + * @param {string} options.xdebug The Xdebug mode to set. + * @param {string} options.phpmyadmin Indicated whether or not PHPMyAdmin should be started. + * @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed. + * @param {boolean} options.debug True if debug mode is enabled. */ module.exports = async function start( { spinner, update, xdebug, + phpmyadmin, scripts, debug, } ) { @@ -180,6 +182,15 @@ module.exports = async function start( { } ); + if ( phpmyadmin ) { + await dockerCompose.upOne( 'phpmyadmin', { + ...dockerComposeConfig, + commandOptions: shouldConfigureWp + ? [ '--build', '--force-recreate' ] + : [], + } ); + } + // Make sure we've consumed the custom CLI dockerfile. if ( shouldConfigureWp ) { await dockerCompose.buildOne( [ 'cli' ], { ...dockerComposeConfig } ); diff --git a/packages/env/lib/config/get-config-from-environment-vars.js b/packages/env/lib/config/get-config-from-environment-vars.js index beaf721ea1c0c1..95058ee85bfd8f 100644 --- a/packages/env/lib/config/get-config-from-environment-vars.js +++ b/packages/env/lib/config/get-config-from-environment-vars.js @@ -40,6 +40,9 @@ module.exports = function getConfigFromEnvironmentVars( cacheDirectoryPath ) { testsMysqlPort: getPortFromEnvironmentVariable( 'WP_ENV_TESTS_MYSQL_PORT' ), + phpmyadminPort: getPortFromEnvironmentVariable( + 'WP_ENV_PHPMYADMIN_PORT' + ), lifecycleScripts: getLifecycleScriptOverrides(), }; diff --git a/packages/env/lib/config/parse-config.js b/packages/env/lib/config/parse-config.js index 1fc7e949251490..91ecb54d80856b 100644 --- a/packages/env/lib/config/parse-config.js +++ b/packages/env/lib/config/parse-config.js @@ -46,14 +46,15 @@ const mergeConfigs = require( './merge-configs' ); * The environment-specific configuration options. (development/tests/etc) * * @typedef WPEnvironmentConfig - * @property {WPSource} coreSource The WordPress installation to load in the environment. - * @property {WPSource[]} pluginSources Plugins to load in the environment. - * @property {WPSource[]} themeSources Themes to load in the environment. - * @property {number} port The port to use. - * @property {number} mysqlPort The port to use for MySQL. Random if empty. - * @property {Object} config Mapping of wp-config.php constants to their desired values. - * @property {Object.} mappings Mapping of WordPress directories to local directories which should be mounted. - * @property {string|null} phpVersion Version of PHP to use in the environments, of the format 0.0. + * @property {WPSource} coreSource The WordPress installation to load in the environment. + * @property {WPSource[]} pluginSources Plugins to load in the environment. + * @property {WPSource[]} themeSources Themes to load in the environment. + * @property {number} port The port to use. + * @property {number} mysqlPort The port to use for MySQL. Random if empty. + * @property {number} phpmyadminPort The port to use for PHPMyAdmin. + * @property {Object} config Mapping of wp-config.php constants to their desired values. + * @property {Object.} mappings Mapping of WordPress directories to local directories which should be mounted. + * @property {string|null} phpVersion Version of PHP to use in the environments, of the format 0.0. */ /** @@ -87,6 +88,7 @@ const DEFAULT_ENVIRONMENT_CONFIG = { port: 8888, testsPort: 8889, mysqlPort: null, + phpmyadminPort: 9000, mappings: {}, config: { FS_METHOD: 'direct', @@ -282,6 +284,11 @@ function getEnvironmentVarOverrides( cacheDirectoryPath ) { overrideConfig.env.development.mysqlPort = overrides.mysqlPort; } + if ( overrides.phpmyadminPort ) { + overrideConfig.env.development.phpmyadminPort = + overrides.phpmyadminPort; + } + if ( overrides.testsPort ) { overrideConfig.testsPort = overrides.testsPort; overrideConfig.env.tests.port = overrides.testsPort; @@ -455,6 +462,10 @@ async function parseEnvironmentConfig( parsedConfig.mysqlPort = config.mysqlPort; } + if ( config.phpmyadminPort !== undefined ) { + parsedConfig.phpmyadminPort = config.phpmyadminPort; + } + if ( config.phpVersion !== undefined ) { // Support null as a valid input. if ( config.phpVersion !== null ) { diff --git a/packages/env/lib/config/test/__snapshots__/config-integration.js.snap b/packages/env/lib/config/test/__snapshots__/config-integration.js.snap index 6c3618f4724cb0..d91d44ff6f96b2 100644 --- a/packages/env/lib/config/test/__snapshots__/config-integration.js.snap +++ b/packages/env/lib/config/test/__snapshots__/config-integration.js.snap @@ -31,6 +31,7 @@ exports[`Config Integration should load local and override configuration files 1 "mappings": {}, "mysqlPort": 23306, "phpVersion": null, + "phpmyadminPort": 9000, "pluginSources": [], "port": 999, "themeSources": [], @@ -60,6 +61,7 @@ exports[`Config Integration should load local and override configuration files 1 "mappings": {}, "mysqlPort": 23307, "phpVersion": null, + "phpmyadminPort": 9000, "pluginSources": [], "port": 456, "themeSources": [], @@ -106,6 +108,7 @@ exports[`Config Integration should load local configuration file 1`] = ` "mappings": {}, "mysqlPort": 13306, "phpVersion": null, + "phpmyadminPort": 9000, "pluginSources": [], "port": 123, "themeSources": [], @@ -135,6 +138,7 @@ exports[`Config Integration should load local configuration file 1`] = ` "mappings": {}, "mysqlPort": 23307, "phpVersion": null, + "phpmyadminPort": 9000, "pluginSources": [], "port": 8889, "themeSources": [], @@ -181,6 +185,7 @@ exports[`Config Integration should use default configuration 1`] = ` "mappings": {}, "mysqlPort": null, "phpVersion": null, + "phpmyadminPort": 9000, "pluginSources": [], "port": 8888, "themeSources": [], @@ -210,6 +215,7 @@ exports[`Config Integration should use default configuration 1`] = ` "mappings": {}, "mysqlPort": null, "phpVersion": null, + "phpmyadminPort": 9000, "pluginSources": [], "port": 8889, "themeSources": [], @@ -256,6 +262,7 @@ exports[`Config Integration should use environment variables over local and over "mappings": {}, "mysqlPort": 23306, "phpVersion": null, + "phpmyadminPort": 9000, "pluginSources": [], "port": 12345, "testsPort": 61234, @@ -286,6 +293,7 @@ exports[`Config Integration should use environment variables over local and over "mappings": {}, "mysqlPort": 23307, "phpVersion": null, + "phpmyadminPort": 9000, "pluginSources": [], "port": 61234, "testsPort": 61234, diff --git a/packages/env/lib/config/test/parse-config.js b/packages/env/lib/config/test/parse-config.js index 38e4db9860cb3c..6cd4f08280302d 100644 --- a/packages/env/lib/config/test/parse-config.js +++ b/packages/env/lib/config/test/parse-config.js @@ -22,6 +22,7 @@ const DEFAULT_CONFIG = { port: 8888, testsPort: 8889, mysqlPort: null, + phpmyadminPort: 9000, phpVersion: null, coreSource: { type: 'git', diff --git a/packages/env/lib/validate-run-container.js b/packages/env/lib/validate-run-container.js index 77e68d2a3a4dc7..fbb6670f6c1500 100644 --- a/packages/env/lib/validate-run-container.js +++ b/packages/env/lib/validate-run-container.js @@ -10,6 +10,7 @@ const RUN_CONTAINERS = [ 'tests-wordpress', 'cli', 'tests-cli', + 'phpmyadmin', ]; /** From e486ac893924d1e482b357b9d2bf2a697a847b08 Mon Sep 17 00:00:00 2001 From: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:32:43 +0000 Subject: [PATCH 2/6] wp-env start: Report listening port for phpMyAdmin --- packages/env/lib/commands/start.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/env/lib/commands/start.js b/packages/env/lib/commands/start.js index ae084d296b5ba1..529d5d4e3e0da4 100644 --- a/packages/env/lib/commands/start.js +++ b/packages/env/lib/commands/start.js @@ -250,6 +250,16 @@ module.exports = async function start( { ); const testsMySQLPort = testsMySQLAddress.split( ':' ).pop(); + let phpmyadminPort; + if ( phpmyadmin ) { + const { out: phpmyadminAddress } = await dockerCompose.port( + 'phpmyadmin', + 80, + dockerComposeConfig + ); + phpmyadminPort = phpmyadminAddress.split( ':' ).pop(); + } + spinner.prefixText = 'WordPress development site started' .concat( siteUrl ? ` at ${ siteUrl }` : '.' ) .concat( '\n' ) @@ -260,6 +270,11 @@ module.exports = async function start( { .concat( `MySQL for automated testing is listening on port ${ testsMySQLPort }` ) + .concat( + phpmyadminPort + ? `phpMyAdmin is listening on port ${ phpmyadminPort }` + : '' + ) .concat( '\n' ); spinner.text = 'Done!'; From b55682ebd258b1451cb375c26ce47aefacb0cfc9 Mon Sep 17 00:00:00 2001 From: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:22:55 +0000 Subject: [PATCH 3/6] wp-env: start: refactor computation of command output - Refactor repeating logic into getPublicDockerPort - Remove trailing newlines from dockerCompose output - Refactor evaluation of spinner.prefixText so as to clearly reveal newlines. --- packages/env/lib/commands/start.js | 62 +++++++++++++++--------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/packages/env/lib/commands/start.js b/packages/env/lib/commands/start.js index 529d5d4e3e0da4..e48ffd7602a8b9 100644 --- a/packages/env/lib/commands/start.js +++ b/packages/env/lib/commands/start.js @@ -236,50 +236,50 @@ module.exports = async function start( { const siteUrl = config.env.development.config.WP_SITEURL; const testsSiteUrl = config.env.tests.config.WP_SITEURL; - const { out: mySQLAddress } = await dockerCompose.port( + const mySQLPort = await getPublicDockerPort( 'mysql', 3306, dockerComposeConfig ); - const mySQLPort = mySQLAddress.split( ':' ).pop(); - const { out: testsMySQLAddress } = await dockerCompose.port( + const testsMySQLPort = await getPublicDockerPort( 'tests-mysql', 3306, dockerComposeConfig ); - const testsMySQLPort = testsMySQLAddress.split( ':' ).pop(); - - let phpmyadminPort; - if ( phpmyadmin ) { - const { out: phpmyadminAddress } = await dockerCompose.port( - 'phpmyadmin', - 80, - dockerComposeConfig - ); - phpmyadminPort = phpmyadminAddress.split( ':' ).pop(); - } - - spinner.prefixText = 'WordPress development site started' - .concat( siteUrl ? ` at ${ siteUrl }` : '.' ) - .concat( '\n' ) - .concat( 'WordPress test site started' ) - .concat( testsSiteUrl ? ` at ${ testsSiteUrl }` : '.' ) - .concat( '\n' ) - .concat( `MySQL is listening on port ${ mySQLPort }` ) - .concat( - `MySQL for automated testing is listening on port ${ testsMySQLPort }` - ) - .concat( - phpmyadminPort - ? `phpMyAdmin is listening on port ${ phpmyadminPort }` - : '' - ) - .concat( '\n' ); + const phpmyadminPort = phpmyadmin + ? await getPublicDockerPort( 'phpmyadmin', 80, dockerComposeConfig ) + : null; + + spinner.prefixText = [ + 'WordPress development site started' + + ( siteUrl ? ` at ${ siteUrl }` : '.' ), + 'WordPress test site started' + + ( testsSiteUrl ? ` at ${ testsSiteUrl }` : '.' ), + `MySQL is listening on port ${ mySQLPort }`, + `MySQL for automated testing is listening on port ${ testsMySQLPort }`, + phpmyadminPort && `phpMyAdmin is listening on port ${ phpmyadminPort }`, + ] + .filter( Boolean ) + .join( '\n' ); + spinner.prefixText += '\n\n'; spinner.text = 'Done!'; }; +async function getPublicDockerPort( + service, + containerPort, + dockerComposeConfig +) { + const { out: address } = await dockerCompose.port( + service, + containerPort, + dockerComposeConfig + ); + return address.split( ':' ).pop().trim(); +} + /** * Checks for legacy installs and provides * the user the option to delete them. From f7047c999b0210df4ad03abb36afb033856a5d9e Mon Sep 17 00:00:00 2001 From: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:46:50 +0000 Subject: [PATCH 4/6] wp-env phpMyAdmin support: use config keys, support both envs Two docker-compose services are now defined: `phpmyadmin` and `tests-phpmyadmin`. These are off by default. They can be individually turned on by specifying a port in the each enviroment's config: { env: { development: { ... phpmyadminPort: 9000 }, tests: { ... } } } --- .../env/lib/build-docker-compose-config.js | 18 +++++- packages/env/lib/cli.js | 6 -- packages/env/lib/commands/start.js | 38 +++++++++---- .../get-config-from-environment-vars.js | 4 ++ packages/env/lib/config/parse-config.js | 4 +- .../__snapshots__/config-integration.js.snap | 16 +++--- packages/env/lib/config/test/parse-config.js | 55 ++++++++++++++++++- 7 files changed, 112 insertions(+), 29 deletions(-) diff --git a/packages/env/lib/build-docker-compose-config.js b/packages/env/lib/build-docker-compose-config.js index 88e4d0bb241b28..a1a4f68256b688 100644 --- a/packages/env/lib/build-docker-compose-config.js +++ b/packages/env/lib/build-docker-compose-config.js @@ -173,9 +173,13 @@ module.exports = function buildDockerComposeConfig( config ) { const testsMysqlPorts = `\${WP_ENV_TESTS_MYSQL_PORT:-${ config.env.tests.mysqlPort ?? '' }}:3306`; - const phpmyadminPorts = `\${WP_ENV_PHPMYADMIN_PORT:-${ + + const developmentPhpmyadminPorts = `\${WP_ENV_PHPMYADMIN_PORT:-${ config.env.development.phpmyadminPort ?? '' }}:80`; + const testsPhpmyadminPorts = `\${WP_ENV_TESTS_PHPMYADMIN_PORT:-${ + config.env.tests.phpmyadminPort ?? '' + }}:80`; return { services: { @@ -271,7 +275,7 @@ module.exports = function buildDockerComposeConfig( config ) { }, phpmyadmin: { image: 'phpmyadmin', - ports: [ phpmyadminPorts ], + ports: [ developmentPhpmyadminPorts ], environment: { PMA_PORT: 3306, PMA_HOST: 'mysql', @@ -279,6 +283,16 @@ module.exports = function buildDockerComposeConfig( config ) { PMA_PASSWORD: 'password', }, }, + 'tests-phpmyadmin': { + image: 'phpmyadmin', + ports: [ testsPhpmyadminPorts ], + environment: { + PMA_PORT: 3306, + PMA_HOST: 'tests-mysql', + PMA_USER: 'root', + PMA_PASSWORD: 'password', + }, + }, }, volumes: { ...( ! config.env.development.coreSource && { wordpress: {} } ), diff --git a/packages/env/lib/cli.js b/packages/env/lib/cli.js index 5eefffa1983b40..896df6cd59fed0 100644 --- a/packages/env/lib/cli.js +++ b/packages/env/lib/cli.js @@ -133,12 +133,6 @@ module.exports = function cli() { 'Download source updates and apply WordPress configuration.', default: false, } ); - args.option( 'phpmyadmin', { - describe: - 'Enables PHPMyAdmin. By default, a PHPMyAdmin server will be available on port 9000 (override with WP_ENV_PHPMYADMIN_PORT).', - type: 'boolean', - default: false, - } ); args.option( 'xdebug', { describe: 'Enables Xdebug. If not passed, Xdebug is turned off. If no modes are set, uses "debug". You may set multiple Xdebug modes by passing them in a comma-separated list: `--xdebug=develop,coverage`. See https://xdebug.org/docs/all_settings#mode for information about Xdebug modes.', diff --git a/packages/env/lib/commands/start.js b/packages/env/lib/commands/start.js index e48ffd7602a8b9..24d57d71fd3c62 100644 --- a/packages/env/lib/commands/start.js +++ b/packages/env/lib/commands/start.js @@ -43,18 +43,16 @@ const CONFIG_CACHE_KEY = 'config_checksum'; * Starts the development server. * * @param {Object} options - * @param {Object} options.spinner A CLI spinner which indicates progress. - * @param {boolean} options.update If true, update sources. - * @param {string} options.xdebug The Xdebug mode to set. - * @param {string} options.phpmyadmin Indicated whether or not PHPMyAdmin should be started. - * @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed. - * @param {boolean} options.debug True if debug mode is enabled. + * @param {Object} options.spinner A CLI spinner which indicates progress. + * @param {boolean} options.update If true, update sources. + * @param {string} options.xdebug The Xdebug mode to set. + * @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed. + * @param {boolean} options.debug True if debug mode is enabled. */ module.exports = async function start( { spinner, update, xdebug, - phpmyadmin, scripts, debug, } ) { @@ -182,7 +180,7 @@ module.exports = async function start( { } ); - if ( phpmyadmin ) { + if ( config.env.development.phpmyadminPort ) { await dockerCompose.upOne( 'phpmyadmin', { ...dockerComposeConfig, commandOptions: shouldConfigureWp @@ -191,6 +189,15 @@ module.exports = async function start( { } ); } + if ( config.env.tests.phpmyadminPort ) { + await dockerCompose.upOne( 'tests-phpmyadmin', { + ...dockerComposeConfig, + commandOptions: shouldConfigureWp + ? [ '--build', '--force-recreate' ] + : [], + } ); + } + // Make sure we've consumed the custom CLI dockerfile. if ( shouldConfigureWp ) { await dockerCompose.buildOne( [ 'cli' ], { ...dockerComposeConfig } ); @@ -248,10 +255,18 @@ module.exports = async function start( { dockerComposeConfig ); - const phpmyadminPort = phpmyadmin + const phpmyadminPort = config.env.development.phpmyadminPort ? await getPublicDockerPort( 'phpmyadmin', 80, dockerComposeConfig ) : null; + const testsPhpmyadminPort = config.env.tests.phpmyadminPort + ? await getPublicDockerPort( + 'tests-phpmyadmin', + 80, + dockerComposeConfig + ) + : null; + spinner.prefixText = [ 'WordPress development site started' + ( siteUrl ? ` at ${ siteUrl }` : '.' ), @@ -259,7 +274,10 @@ module.exports = async function start( { ( testsSiteUrl ? ` at ${ testsSiteUrl }` : '.' ), `MySQL is listening on port ${ mySQLPort }`, `MySQL for automated testing is listening on port ${ testsMySQLPort }`, - phpmyadminPort && `phpMyAdmin is listening on port ${ phpmyadminPort }`, + phpmyadminPort && + `phpMyAdmin started at http://localhost:${ phpmyadminPort }`, + testsPhpmyadminPort && + `phpMyAdmin for automated testing started at http://localhost:${ testsPhpmyadminPort }`, ] .filter( Boolean ) .join( '\n' ); diff --git a/packages/env/lib/config/get-config-from-environment-vars.js b/packages/env/lib/config/get-config-from-environment-vars.js index 95058ee85bfd8f..618b5fff257920 100644 --- a/packages/env/lib/config/get-config-from-environment-vars.js +++ b/packages/env/lib/config/get-config-from-environment-vars.js @@ -20,6 +20,7 @@ const { checkPort, checkVersion, checkString } = require( './validate-config' ); * @property {?number} mysqlPort An override for the development environment's MySQL port. * @property {?number} testsPort An override for the testing environment's port. * @property {?number} testsMysqlPort An override for the testing environment's MySQL port. + * @property {?number} phpmyadminPort An override for the development environment's phpMyAdmin port. * @property {?WPSource} coreSource An override for all environment's coreSource. * @property {?string} phpVersion An override for all environment's PHP version. * @property {?Object.} lifecycleScripts An override for various lifecycle scripts. @@ -43,6 +44,9 @@ module.exports = function getConfigFromEnvironmentVars( cacheDirectoryPath ) { phpmyadminPort: getPortFromEnvironmentVariable( 'WP_ENV_PHPMYADMIN_PORT' ), + testsPhpmyadminPort: getPortFromEnvironmentVariable( + 'WP_ENV_TESTS_PHPMYADMIN_PORT' + ), lifecycleScripts: getLifecycleScriptOverrides(), }; diff --git a/packages/env/lib/config/parse-config.js b/packages/env/lib/config/parse-config.js index 91ecb54d80856b..bddd7bc72aaee0 100644 --- a/packages/env/lib/config/parse-config.js +++ b/packages/env/lib/config/parse-config.js @@ -51,7 +51,7 @@ const mergeConfigs = require( './merge-configs' ); * @property {WPSource[]} themeSources Themes to load in the environment. * @property {number} port The port to use. * @property {number} mysqlPort The port to use for MySQL. Random if empty. - * @property {number} phpmyadminPort The port to use for PHPMyAdmin. + * @property {number} phpmyadminPort The port to use for phpMyAdmin. If empty, disabled phpMyAdmin. * @property {Object} config Mapping of wp-config.php constants to their desired values. * @property {Object.} mappings Mapping of WordPress directories to local directories which should be mounted. * @property {string|null} phpVersion Version of PHP to use in the environments, of the format 0.0. @@ -88,7 +88,7 @@ const DEFAULT_ENVIRONMENT_CONFIG = { port: 8888, testsPort: 8889, mysqlPort: null, - phpmyadminPort: 9000, + phpmyadminPort: null, mappings: {}, config: { FS_METHOD: 'direct', diff --git a/packages/env/lib/config/test/__snapshots__/config-integration.js.snap b/packages/env/lib/config/test/__snapshots__/config-integration.js.snap index d91d44ff6f96b2..6b671a6bc858eb 100644 --- a/packages/env/lib/config/test/__snapshots__/config-integration.js.snap +++ b/packages/env/lib/config/test/__snapshots__/config-integration.js.snap @@ -31,7 +31,7 @@ exports[`Config Integration should load local and override configuration files 1 "mappings": {}, "mysqlPort": 23306, "phpVersion": null, - "phpmyadminPort": 9000, + "phpmyadminPort": null, "pluginSources": [], "port": 999, "themeSources": [], @@ -61,7 +61,7 @@ exports[`Config Integration should load local and override configuration files 1 "mappings": {}, "mysqlPort": 23307, "phpVersion": null, - "phpmyadminPort": 9000, + "phpmyadminPort": null, "pluginSources": [], "port": 456, "themeSources": [], @@ -108,7 +108,7 @@ exports[`Config Integration should load local configuration file 1`] = ` "mappings": {}, "mysqlPort": 13306, "phpVersion": null, - "phpmyadminPort": 9000, + "phpmyadminPort": null, "pluginSources": [], "port": 123, "themeSources": [], @@ -138,7 +138,7 @@ exports[`Config Integration should load local configuration file 1`] = ` "mappings": {}, "mysqlPort": 23307, "phpVersion": null, - "phpmyadminPort": 9000, + "phpmyadminPort": null, "pluginSources": [], "port": 8889, "themeSources": [], @@ -185,7 +185,7 @@ exports[`Config Integration should use default configuration 1`] = ` "mappings": {}, "mysqlPort": null, "phpVersion": null, - "phpmyadminPort": 9000, + "phpmyadminPort": null, "pluginSources": [], "port": 8888, "themeSources": [], @@ -215,7 +215,7 @@ exports[`Config Integration should use default configuration 1`] = ` "mappings": {}, "mysqlPort": null, "phpVersion": null, - "phpmyadminPort": 9000, + "phpmyadminPort": null, "pluginSources": [], "port": 8889, "themeSources": [], @@ -262,7 +262,7 @@ exports[`Config Integration should use environment variables over local and over "mappings": {}, "mysqlPort": 23306, "phpVersion": null, - "phpmyadminPort": 9000, + "phpmyadminPort": null, "pluginSources": [], "port": 12345, "testsPort": 61234, @@ -293,7 +293,7 @@ exports[`Config Integration should use environment variables over local and over "mappings": {}, "mysqlPort": 23307, "phpVersion": null, - "phpmyadminPort": 9000, + "phpmyadminPort": null, "pluginSources": [], "port": 61234, "testsPort": 61234, diff --git a/packages/env/lib/config/test/parse-config.js b/packages/env/lib/config/test/parse-config.js index 6cd4f08280302d..cc6e2c7a96bbc0 100644 --- a/packages/env/lib/config/test/parse-config.js +++ b/packages/env/lib/config/test/parse-config.js @@ -22,7 +22,7 @@ const DEFAULT_CONFIG = { port: 8888, testsPort: 8889, mysqlPort: null, - phpmyadminPort: 9000, + phpmyadminPort: null, phpVersion: null, coreSource: { type: 'git', @@ -401,4 +401,57 @@ describe( 'parseConfig', () => { ) ); } ); + + it( 'should parse phpmyadmin configuration for a given environment', async () => { + readRawConfigFile.mockImplementation( async ( configFile ) => { + if ( configFile === '/test/gutenberg/.wp-env.json' ) { + return { + core: 'WordPress/WordPress#Test', + phpVersion: '1.0', + lifecycleScripts: { + afterStart: 'test', + }, + env: { + development: { + phpmyadminPort: 9001, + }, + }, + }; + } + } ); + + const parsed = await parseConfig( '/test/gutenberg', '/cache' ); + + const expected = { + development: { + ...DEFAULT_CONFIG.env.development, + phpmyadminPort: 9001, + }, + tests: DEFAULT_CONFIG.env.tests, + }; + expect( parsed.env ).toEqual( expected ); + } ); + + it( 'should ignore root-level configuration for phpmyadmin', async () => { + readRawConfigFile.mockImplementation( async ( configFile ) => { + if ( configFile === '/test/gutenberg/.wp-env.json' ) { + return { + core: 'WordPress/WordPress#Test', + phpVersion: '1.0', + lifecycleScripts: { + afterStart: 'test', + }, + phpmyadminPort: 9001, + }; + } + } ); + + const parsed = await parseConfig( '/test/gutenberg', '/cache' ); + + const expected = { + development: DEFAULT_CONFIG.env.development, + tests: DEFAULT_CONFIG.env.tests, + }; + expect( parsed.env ).toEqual( expected ); + } ); } ); From 50ea645505d0bbeea7f9a92dc709dc9f225a661a Mon Sep 17 00:00:00 2001 From: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Date: Mon, 9 Dec 2024 15:38:46 +0000 Subject: [PATCH 5/6] Update changelog --- packages/env/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/env/CHANGELOG.md b/packages/env/CHANGELOG.md index 651d6b285e1bd6..6ee37efdf850c9 100644 --- a/packages/env/CHANGELOG.md +++ b/packages/env/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Enhancements + +- Add phpMyAdmin as an optional service. Enabled via the new `phpmyadminPort` environment config, as well as env vars `WP_ENV_PHPMYADMIN_PORT` and `WP_ENV_TESTS_PHPMYADMIN_PORT`. + ## 10.13.0 (2024-11-27) ## 10.12.0 (2024-11-16) From 95b664918912a69f7f19addbcee868d92eea90c8 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 9 Dec 2024 16:52:29 +0100 Subject: [PATCH 6/6] Opt-in in the Gutenberg environment --- .wp-env.json | 3 +++ schemas/json/wp-env.json | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.wp-env.json b/.wp-env.json index 05ea05b2809f9c..d368f3ea1c72a6 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -4,6 +4,9 @@ "plugins": [ "." ], "themes": [ "./test/emptytheme" ], "env": { + "development": { + "phpmyadminPort": 9000 + }, "tests": { "mappings": { "wp-content/plugins/gutenberg": ".", diff --git a/schemas/json/wp-env.json b/schemas/json/wp-env.json index 491d1f8cf73017..8aa604ed41ed1f 100644 --- a/schemas/json/wp-env.json +++ b/schemas/json/wp-env.json @@ -62,6 +62,10 @@ "description": "Mapping of WordPress directories to local directories to be mounted in the WordPress instance.", "type": "object", "default": {} + }, + "phpmyadminPort": { + "description": "The port number to access phpMyAdmin.", + "type": "integer" } } }, @@ -73,7 +77,8 @@ "themes", "port", "config", - "mappings" + "mappings", + "phpmyadminPort" ] } },