Changeset 60432
- Timestamp:
- 07/07/2025 11:40:32 PM (9 months ago)
- Location:
- branches/6.8
- Files:
-
- 7 edited
-
. (modified) (1 prop)
-
docker-compose.yml (modified) (1 diff)
-
package.json (modified) (1 diff)
-
tools/local-env/scripts/docker.js (modified) (2 diffs)
-
tools/local-env/scripts/install.js (modified) (2 diffs)
-
tools/local-env/scripts/start.js (modified) (3 diffs)
-
tools/local-env/scripts/utils.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/6.8
-
branches/6.8/docker-compose.yml
r60431 r60432 112 112 - ./:/var/www 113 113 114 # Keeps the service alive. 115 command: 'sleep infinity' 116 114 117 # The init directive ensures the command runs with a PID > 1, so Ctrl+C works correctly. 115 118 init: true -
branches/6.8/package.json
r60210 r60432 185 185 "env:reset": "node ./tools/local-env/scripts/docker.js down --rmi all -v --remove-orphans", 186 186 "env:install": "node ./tools/local-env/scripts/install.js", 187 "env:cli": "node ./tools/local-env/scripts/docker.js run --rm cli",187 "env:cli": "node ./tools/local-env/scripts/docker.js exec cli wp --allow-root", 188 188 "env:logs": "node ./tools/local-env/scripts/docker.js logs", 189 189 "env:pull": "node ./tools/local-env/scripts/docker.js pull", -
branches/6.8/tools/local-env/scripts/docker.js
r59659 r60432 1 const dotenv = require( 'dotenv' ); 1 /* jshint node:true */ 2 3 const dotenv = require( 'dotenv' ); 2 4 const dotenvExpand = require( 'dotenv-expand' ); 3 const { execSync } = require( 'child_process' );5 const { spawnSync } = require( 'child_process' ); 4 6 const local_env_utils = require( './utils' ); 5 7 … … 8 10 const composeFiles = local_env_utils.get_compose_files(); 9 11 10 if ( process.argv.includes('--coverage-html')) {12 if ( process.argv.includes( '--coverage-html' ) ) { 11 13 process.env.LOCAL_PHP_XDEBUG = 'true'; 12 14 process.env.LOCAL_PHP_XDEBUG_MODE = 'coverage'; 13 15 } 14 16 15 // This try-catch prevents the superfluous Node.js debugging information from being shown if the command fails. 16 try { 17 // Execute any Docker compose command passed to this script. 18 execSync( 'docker compose ' + composeFiles + ' ' + process.argv.slice( 2 ).join( ' ' ), { stdio: 'inherit' } ); 19 } catch ( error ) { 20 process.exit( 1 ); 17 // Add --no-TTY (-T) arg after exec and run commands when STDIN is not a TTY. 18 const dockerCommand = process.argv.slice( 2 ); 19 if ( [ 'exec', 'run' ].includes( dockerCommand[0] ) && ! process.stdin.isTTY ) { 20 dockerCommand.splice( 1, 0, '--no-TTY' ); 21 21 } 22 23 // Execute any Docker compose command passed to this script. 24 const returns = spawnSync( 25 'docker', 26 [ 27 'compose', 28 ...composeFiles 29 .map( ( composeFile ) => [ '-f', composeFile ] ) 30 .flat(), 31 ...dockerCommand, 32 ], 33 { stdio: 'inherit' } 34 ); 35 36 process.exit( returns.status ); -
branches/6.8/tools/local-env/scripts/install.js
r60431 r60432 15 15 16 16 // Create wp-config.php. 17 wp_cli( `config create --dbname=wordpress_develop --dbuser=root --dbpass=password --dbhost=mysql --force --config-file=${process.env.LOCAL_DIR}/../wp-config.php` ); 17 wp_cli( `config create --dbname=wordpress_develop --dbuser=root --dbpass=password --dbhost=mysql --force --config-file="wp-config.php"` ); 18 19 // Since WP-CLI runs as root, the wp-config.php created above will be read-only. This needs to be writable for the sake of E2E tests. 20 execSync( 'node ./tools/local-env/scripts/docker.js exec cli chmod 666 wp-config.php' ); 18 21 19 22 // Add the debug settings to wp-config.php. … … 63 66 */ 64 67 function wp_cli( cmd ) { 65 const composeFiles = local_env_utils.get_compose_files(); 66 67 execSync( `docker compose ${composeFiles} run --quiet-pull --rm cli ${cmd} --path=/var/www/${process.env.LOCAL_DIR}`, { stdio: 'inherit' } ); 68 execSync( `npm --silent run env:cli -- ${cmd} --path=/var/www/${process.env.LOCAL_DIR}`, { stdio: 'inherit' } ); 68 69 } -
branches/6.8/tools/local-env/scripts/start.js
r59658 r60432 1 /* jshint node:true */ 2 1 3 const dotenv = require( 'dotenv' ); 2 4 const dotenvExpand = require( 'dotenv-expand' ); 3 const { execSync } = require( 'child_process' );5 const { execSync, spawnSync } = require( 'child_process' ); 4 6 const local_env_utils = require( './utils' ); 5 7 const { constants, copyFile } = require( 'node:fs' ); 6 8 7 9 // Copy the default .env file when one is not present. 8 copyFile( '.env.example', '.env', constants.COPYFILE_EXCL, ( e) => {10 copyFile( '.env.example', '.env', constants.COPYFILE_EXCL, () => { 9 11 console.log( '.env file already exists. .env.example was not copied.' ); 10 12 }); … … 29 31 30 32 // Start the local-env containers. 31 const containers = ( process.env.LOCAL_PHP_MEMCACHED === 'true' ) 32 ? 'wordpress-develop memcached' 33 : 'wordpress-develop'; 34 execSync( `docker compose ${composeFiles} up --quiet-pull -d ${containers}`, { stdio: 'inherit' } ); 33 const containers = [ 'wordpress-develop', 'cli' ]; 34 if ( process.env.LOCAL_PHP_MEMCACHED === 'true' ) { 35 containers.push( 'memcached' ); 36 } 37 38 spawnSync( 39 'docker', 40 [ 41 'compose', 42 ...composeFiles.map( ( composeFile ) => [ '-f', composeFile ] ).flat(), 43 'up', 44 '--quiet-pull', 45 '-d', 46 ...containers, 47 ], 48 { stdio: 'inherit' } 49 ); 35 50 36 51 // If Docker Toolbox is being used, we need to manually forward LOCAL_PORT to the Docker VM. 37 52 if ( process.env.DOCKER_TOOLBOX_INSTALL_PATH ) { 38 53 // VBoxManage is added to the PATH on every platform except Windows. 39 const vboxmanage = process.env.VBOX_MSI_INSTALL_PATH ? `${ process.env.VBOX_MSI_INSTALL_PATH }/VBoxManage` : 'VBoxManage' 54 const vboxmanage = process.env.VBOX_MSI_INSTALL_PATH ? `${ process.env.VBOX_MSI_INSTALL_PATH }/VBoxManage` : 'VBoxManage'; 40 55 41 56 // Check if the port forwarding is already configured for this port. 42 const vminfoBuffer = execSync( `"${ vboxmanage }" showvminfo "${ process.env.DOCKER_MACHINE_NAME }" --machinereadable` ); 57 const vminfoBuffer = spawnSync( 58 vboxmanage, 59 [ 60 'showvminfo', 61 process.env.DOCKER_MACHINE_NAME, 62 '--machinereadable' 63 ] 64 ).stdout; 43 65 const vminfo = vminfoBuffer.toString().split( /[\r\n]+/ ); 44 66 … … 54 76 // Delete rules that are using the port we need. 55 77 if ( rule[ 3 ] === process.env.LOCAL_PORT || rule[ 5 ] === process.env.LOCAL_PORT ) { 56 execSync( `"${ vboxmanage }" controlvm "${ process.env.DOCKER_MACHINE_NAME }" natpf1 delete ${ rule[ 0 ] }`, { stdio: 'inherit' } ); 78 spawnSync( 79 vboxmanage, 80 [ 81 'controlvm', 82 process.env.DOCKER_MACHINE_NAME, 83 'natpf1', 84 'delete', 85 rule[ 0 ] 86 ], 87 { stdio: 'inherit' } 88 ); 57 89 } 58 90 } ); 59 91 60 92 // Add our port forwarding rule. 61 execSync( `"${ vboxmanage }" controlvm "${ process.env.DOCKER_MACHINE_NAME }" natpf1 "tcp-port${ process.env.LOCAL_PORT },tcp,127.0.0.1,${ process.env.LOCAL_PORT },,${ process.env.LOCAL_PORT }"`, { stdio: 'inherit' } ); 93 spawnSync( 94 vboxmanage, 95 [ 96 'controlvm', 97 process.env.DOCKER_MACHINE_NAME, 98 'natpf1', 99 `tcp-port${ process.env.LOCAL_PORT },tcp,127.0.0.1,${ process.env.LOCAL_PORT },,${ process.env.LOCAL_PORT }` 100 ], 101 { stdio: 'inherit' } 102 ); 62 103 } -
branches/6.8/tools/local-env/scripts/utils.js
r59283 r60432 1 /* jshint node:true */ 2 1 3 const { existsSync } = require( 'node:fs' ); 2 4 … … 11 13 * When PHP 7.2 or 7.3 is used in combination with MySQL 8.4, an override file will also be returned to ensure 12 14 * that the mysql_native_password plugin authentication plugin is on and available for use. 15 * 16 * @return {string[]} Compose files. 13 17 */ 14 18 get_compose_files: function() { 15 var composeFiles = '-f docker-compose.yml';19 const composeFiles = [ 'docker-compose.yml' ]; 16 20 17 21 if ( existsSync( 'docker-compose.override.yml' ) ) { 18 composeFiles = composeFiles + ' -f docker-compose.override.yml';22 composeFiles.push( 'docker-compose.override.yml' ); 19 23 } 20 24 … … 29 33 // PHP 7.2/7.3 in combination with MySQL 8.4 requires additional configuration to function properly. 30 34 if ( process.env.LOCAL_DB_VERSION === '8.4' ) { 31 composeFiles = composeFiles + ' -f tools/local-env/old-php-mysql-84.override.yml';35 composeFiles.push( 'tools/local-env/old-php-mysql-84.override.yml' ); 32 36 } 33 37
Note: See TracChangeset
for help on using the changeset viewer.