summaryrefslogtreecommitdiffstatshomepage
path: root/tools/local-env/scripts/start.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/local-env/scripts/start.js')
-rw-r--r--tools/local-env/scripts/start.js61
1 files changed, 51 insertions, 10 deletions
diff --git a/tools/local-env/scripts/start.js b/tools/local-env/scripts/start.js
index 0dc8b95700..b0389b2fb0 100644
--- a/tools/local-env/scripts/start.js
+++ b/tools/local-env/scripts/start.js
@@ -1,11 +1,13 @@
+/* jshint node:true */
+
const dotenv = require( 'dotenv' );
const dotenvExpand = require( 'dotenv-expand' );
-const { execSync } = require( 'child_process' );
+const { execSync, spawnSync } = require( 'child_process' );
const local_env_utils = require( './utils' );
const { constants, copyFile } = require( 'node:fs' );
// Copy the default .env file when one is not present.
-copyFile( '.env.example', '.env', constants.COPYFILE_EXCL, (e) => {
+copyFile( '.env.example', '.env', constants.COPYFILE_EXCL, () => {
console.log( '.env file already exists. .env.example was not copied.' );
});
@@ -28,18 +30,38 @@ try {
}
// Start the local-env containers.
-const containers = ( process.env.LOCAL_PHP_MEMCACHED === 'true' )
- ? 'wordpress-develop memcached'
- : 'wordpress-develop';
-execSync( `docker compose ${composeFiles} up --quiet-pull -d ${containers}`, { stdio: 'inherit' } );
+const containers = [ 'wordpress-develop', 'cli' ];
+if ( process.env.LOCAL_PHP_MEMCACHED === 'true' ) {
+ containers.push( 'memcached' );
+}
+
+spawnSync(
+ 'docker',
+ [
+ 'compose',
+ ...composeFiles.map( ( composeFile ) => [ '-f', composeFile ] ).flat(),
+ 'up',
+ '--quiet-pull',
+ '-d',
+ ...containers,
+ ],
+ { stdio: 'inherit' }
+);
// If Docker Toolbox is being used, we need to manually forward LOCAL_PORT to the Docker VM.
if ( process.env.DOCKER_TOOLBOX_INSTALL_PATH ) {
// VBoxManage is added to the PATH on every platform except Windows.
- const vboxmanage = process.env.VBOX_MSI_INSTALL_PATH ? `${ process.env.VBOX_MSI_INSTALL_PATH }/VBoxManage` : 'VBoxManage'
+ const vboxmanage = process.env.VBOX_MSI_INSTALL_PATH ? `${ process.env.VBOX_MSI_INSTALL_PATH }/VBoxManage` : 'VBoxManage';
// Check if the port forwarding is already configured for this port.
- const vminfoBuffer = execSync( `"${ vboxmanage }" showvminfo "${ process.env.DOCKER_MACHINE_NAME }" --machinereadable` );
+ const vminfoBuffer = spawnSync(
+ vboxmanage,
+ [
+ 'showvminfo',
+ process.env.DOCKER_MACHINE_NAME,
+ '--machinereadable'
+ ]
+ ).stdout;
const vminfo = vminfoBuffer.toString().split( /[\r\n]+/ );
vminfo.forEach( ( info ) => {
@@ -53,10 +75,29 @@ if ( process.env.DOCKER_TOOLBOX_INSTALL_PATH ) {
// Delete rules that are using the port we need.
if ( rule[ 3 ] === process.env.LOCAL_PORT || rule[ 5 ] === process.env.LOCAL_PORT ) {
- execSync( `"${ vboxmanage }" controlvm "${ process.env.DOCKER_MACHINE_NAME }" natpf1 delete ${ rule[ 0 ] }`, { stdio: 'inherit' } );
+ spawnSync(
+ vboxmanage,
+ [
+ 'controlvm',
+ process.env.DOCKER_MACHINE_NAME,
+ 'natpf1',
+ 'delete',
+ rule[ 0 ]
+ ],
+ { stdio: 'inherit' }
+ );
}
} );
// Add our port forwarding rule.
- 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' } );
+ spawnSync(
+ 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' }
+ );
}