Skip to content

Commit fbf0d4d

Browse files
committed
Build/Test Tools: Correct local environment failure handling.
Backport of [63416] to the 6.9 branch. `start.js` and `docker.js` report success when Docker Compose fails to start, exits non-zero, or is killed. Propagate the exit status, and keep SIGINT as cancellation for interactive commands. The `.env` half of [63416] is omitted. This branch already copies the configuration synchronously, from [62871].
1 parent a9a78fd commit fbf0d4d

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

tools/local-env/scripts/docker.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,13 @@ const returns = spawnSync(
3838
{ stdio: 'inherit' }
3939
);
4040

41-
process.exit( returns.status );
41+
if ( returns.error ) {
42+
console.error( `Could not run Docker Compose. ${ returns.error.message }` );
43+
} else if ( returns.signal && returns.signal !== 'SIGINT' ) {
44+
console.error( `Docker Compose was terminated by ${ returns.signal }.` );
45+
}
46+
47+
// `status` is null when Docker could not be spawned at all, or was killed by a signal. SIGINT is
48+
// how a long-running command such as `env:logs` is normally ended, so it is not a failure worth an
49+
// npm error block. Every other signal means the command was killed before it finished.
50+
process.exit( returns.signal === 'SIGINT' ? 0 : ( returns.status ?? 1 ) );

tools/local-env/scripts/start.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ if ( process.env.LOCAL_PHP_MEMCACHED === 'true' ) {
3535
containers.push( 'memcached' );
3636
}
3737

38-
spawnSync(
38+
const up = spawnSync(
3939
'docker',
4040
[
4141
'compose',
@@ -48,6 +48,17 @@ spawnSync(
4848
{ stdio: 'inherit' }
4949
);
5050

51+
// No signal is exempt here, unlike in `docker.js`: `env:start` runs `composer update -W` next, and
52+
// that must not run against containers that never came up.
53+
if ( up.status !== 0 ) {
54+
const reason = up.signal ? `It was terminated by ${ up.signal }.` : up.error?.message ?? '';
55+
56+
console.error( `Could not start the Docker containers. ${ reason }`.trim() );
57+
58+
// `status` is null when Docker could not be spawned at all, or was killed by a signal.
59+
process.exit( up.status ?? 1 );
60+
}
61+
5162
// If Docker Toolbox is being used, we need to manually forward LOCAL_PORT to the Docker VM.
5263
if ( process.env.DOCKER_TOOLBOX_INSTALL_PATH ) {
5364
// VBoxManage is added to the PATH on every platform except Windows.

0 commit comments

Comments
 (0)