Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp-env: Add phpMyAdmin support #67588

Merged
merged 6 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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`
  • Loading branch information
mcsf committed Dec 9, 2024
commit 69c4c9607870b338bcc7ba39f05db6da84406f23
2 changes: 1 addition & 1 deletion packages/env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions packages/env/lib/build-docker-compose-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {} } ),
Expand Down
6 changes: 6 additions & 0 deletions packages/env/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
21 changes: 16 additions & 5 deletions packages/env/lib/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
} ) {
Expand Down Expand Up @@ -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 } );
Expand Down
3 changes: 3 additions & 0 deletions packages/env/lib/config/get-config-from-environment-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ module.exports = function getConfigFromEnvironmentVars( cacheDirectoryPath ) {
testsMysqlPort: getPortFromEnvironmentVariable(
'WP_ENV_TESTS_MYSQL_PORT'
),
phpmyadminPort: getPortFromEnvironmentVariable(
'WP_ENV_PHPMYADMIN_PORT'
),
lifecycleScripts: getLifecycleScriptOverrides(),
};

Expand Down
27 changes: 19 additions & 8 deletions packages/env/lib/config/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<string, WPSource>} 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.<string, WPSource>} 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.
*/

/**
Expand Down Expand Up @@ -87,6 +88,7 @@ const DEFAULT_ENVIRONMENT_CONFIG = {
port: 8888,
testsPort: 8889,
mysqlPort: null,
phpmyadminPort: 9000,
mappings: {},
config: {
FS_METHOD: 'direct',
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down Expand Up @@ -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": [],
Expand Down Expand Up @@ -106,6 +108,7 @@ exports[`Config Integration should load local configuration file 1`] = `
"mappings": {},
"mysqlPort": 13306,
"phpVersion": null,
"phpmyadminPort": 9000,
"pluginSources": [],
"port": 123,
"themeSources": [],
Expand Down Expand Up @@ -135,6 +138,7 @@ exports[`Config Integration should load local configuration file 1`] = `
"mappings": {},
"mysqlPort": 23307,
"phpVersion": null,
"phpmyadminPort": 9000,
"pluginSources": [],
"port": 8889,
"themeSources": [],
Expand Down Expand Up @@ -181,6 +185,7 @@ exports[`Config Integration should use default configuration 1`] = `
"mappings": {},
"mysqlPort": null,
"phpVersion": null,
"phpmyadminPort": 9000,
"pluginSources": [],
"port": 8888,
"themeSources": [],
Expand Down Expand Up @@ -210,6 +215,7 @@ exports[`Config Integration should use default configuration 1`] = `
"mappings": {},
"mysqlPort": null,
"phpVersion": null,
"phpmyadminPort": 9000,
"pluginSources": [],
"port": 8889,
"themeSources": [],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/env/lib/config/test/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const DEFAULT_CONFIG = {
port: 8888,
testsPort: 8889,
mysqlPort: null,
phpmyadminPort: 9000,
phpVersion: null,
coreSource: {
type: 'git',
Expand Down
1 change: 1 addition & 0 deletions packages/env/lib/validate-run-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const RUN_CONTAINERS = [
'tests-wordpress',
'cli',
'tests-cli',
'phpmyadmin',
];

/**
Expand Down