2020-04-02 13:41:06 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
const { spawnSync } = require( 'child_process' );
|
|
|
|
const program = require( 'commander' );
|
|
|
|
const path = require( 'path' );
|
|
|
|
const fs = require( 'fs' );
|
|
|
|
const getAppPath = require( '../utils/app-root' );
|
|
|
|
|
|
|
|
const dockerArgs = [];
|
|
|
|
let command = '';
|
|
|
|
|
|
|
|
program
|
|
|
|
.command( 'up', 'Start and build the Docker container' )
|
|
|
|
.command( 'down', 'Stop the Docker container and remove volumes' )
|
|
|
|
.action( ( cmd, options ) => {
|
2020-05-08 19:26:30 +00:00
|
|
|
arg = options.args ? options.args[ 0 ] : options[ 0 ];
|
|
|
|
if ( 'up' === arg ) {
|
2020-04-02 13:41:06 +00:00
|
|
|
command = 'up';
|
|
|
|
dockerArgs.push( 'up', '--build', '-d' );
|
|
|
|
}
|
|
|
|
|
2020-05-08 19:26:30 +00:00
|
|
|
if ( 'down' === arg ) {
|
2020-04-02 13:41:06 +00:00
|
|
|
command = 'down';
|
|
|
|
dockerArgs.push( 'down', '-v' );
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.parse( process.argv );
|
|
|
|
|
|
|
|
const appPath = getAppPath();
|
|
|
|
const envVars = {};
|
|
|
|
|
|
|
|
if ( appPath ) {
|
|
|
|
if ( 'up' === command ) {
|
|
|
|
// Look for an initialization script in the dependent app.
|
2020-04-28 20:14:11 +00:00
|
|
|
const appInitFile = path.resolve( appPath, 'tests/e2e/docker/initialize.sh' );
|
2020-04-02 13:41:06 +00:00
|
|
|
|
|
|
|
// If found, copy it into the wp-cli Docker context so
|
|
|
|
// it gets picked up by the entrypoint script.
|
|
|
|
if ( fs.existsSync( appInitFile ) ) {
|
|
|
|
fs.copyFileSync(
|
|
|
|
appInitFile,
|
|
|
|
path.resolve( __dirname, '../docker/wp-cli/initialize.sh' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Provide an "app name" to use in Docker container names.
|
|
|
|
envVars.APP_NAME = path.basename( appPath );
|
|
|
|
}
|
|
|
|
|
2020-07-23 18:38:40 +00:00
|
|
|
if ( ! process.env.WC_E2E_FOLDER_MAPPING ) {
|
|
|
|
envVars.WC_E2E_FOLDER_MAPPING = '/var/www/html/wp-content/plugins/' + envVars.APP_NAME;
|
|
|
|
}
|
|
|
|
|
2020-04-02 13:41:06 +00:00
|
|
|
// Ensure that the first Docker compose file loaded is from our local env.
|
|
|
|
dockerArgs.unshift( '-f', path.resolve( __dirname, '../docker-compose.yaml' ) );
|
|
|
|
|
|
|
|
const dockerProcess = spawnSync(
|
|
|
|
'docker-compose',
|
|
|
|
dockerArgs,
|
|
|
|
{
|
|
|
|
stdio: 'inherit',
|
|
|
|
env: Object.assign( {}, process.env, envVars ),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log( 'Docker exit code: ' + dockerProcess.status );
|
|
|
|
|
|
|
|
// Pass Docker exit code to npm
|
|
|
|
process.exit( dockerProcess.status );
|