Skip to content

Commit 2e6ce92

Browse files
authored
Merge branch 'main' into claude/clever-lamport-8md283
2 parents 8c74ce7 + c87933c commit 2e6ce92

2 files changed

Lines changed: 37 additions & 9 deletions

File tree

‎utils/behat-parallel.php‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
*/
3333
const WP_CLI_TESTS_SHARED_RESOURCES = '#localhost:\d+|127\.0\.0\.1:\d+|built-in web server|launch in the background|\bwp server\b|_scaffold\b|install-wp-tests|/tmp/#';
3434

35+
/**
36+
* Directory in which the database container of a Docker worker puts its socket, in both of its containers.
37+
*/
38+
const WP_CLI_TESTS_DOCKER_SOCKET_DIR = '/run/wp-cli-tests-mysqld';
39+
3540
/**
3641
* Get the file that holds the scenarios which failed in the last parallel run.
3742
*
@@ -592,23 +597,40 @@ function wp_cli_tests_docker_worker_command( $name, $php_image, $db_image, array
592597
$network = '';
593598
$label = ' --label ' . escapeshellarg( 'wp-cli-tests.owner=' . wp_cli_tests_docker_owner() );
594599

600+
$env = [
601+
'HOME' => '/tmp/home',
602+
'WP_CLI_TEST_DBHOST' => '127.0.0.1:3306',
603+
'WP_CLI_TEST_DBROOTUSER' => 'root',
604+
'WP_CLI_TEST_DBROOTPASS' => 'root',
605+
];
606+
595607
if ( null !== $db_image ) {
608+
// The server's socket is shared with the worker through a directory of the host that both mount,
609+
// so that scenarios can connect through the socket as well as over TCP.
610+
$socket_dir = sys_get_temp_dir() . "/{$name}-mysqld";
611+
// The server takes the directory over, so it is left as it is when it is there from an earlier run.
612+
if ( ! is_dir( $socket_dir ) ) {
613+
mkdir( $socket_dir, 0777, true );
614+
chmod( $socket_dir, 0777 );
615+
}
616+
$socket = WP_CLI_TESTS_DOCKER_SOCKET_DIR . '/mysqld.sock';
617+
596618
exec(
597619
'docker run -d --rm --name ' . escapeshellarg( "{$name}-db" ) . $label
598620
. ' --tmpfs /var/lib/mysql'
621+
. ' -v ' . escapeshellarg( $socket_dir . ':' . WP_CLI_TESTS_DOCKER_SOCKET_DIR )
599622
. ' -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=wp_cli_test -e MYSQL_PASSWORD=password1'
600-
. ' ' . escapeshellarg( $db_image ) . ' ' . wp_cli_tests_docker_db_options( $db_image ) . ' 2>&1'
623+
. ' ' . escapeshellarg( $db_image ) . ' ' . wp_cli_tests_docker_db_options( $db_image )
624+
. ' --socket=' . escapeshellarg( $socket ) . ' 2>&1'
601625
);
602626
// Share the database container's network, so the server is at 127.0.0.1 and nothing else is.
603627
$network = ' --network ' . escapeshellarg( "container:{$name}-db" );
604-
}
605628

606-
$env = [
607-
'HOME' => '/tmp/home',
608-
'WP_CLI_TEST_DBHOST' => '127.0.0.1:3306',
609-
'WP_CLI_TEST_DBROOTUSER' => 'root',
610-
'WP_CLI_TEST_DBROOTPASS' => 'root',
611-
];
629+
// The settings the GitHub Actions workflows pass for the server of the runner, adapted to the container's.
630+
$env['MYSQL_HOST'] = '127.0.0.1';
631+
$env['MYSQL_TCP_PORT'] = '3306';
632+
$env['WP_CLI_TEST_DBSOCKET'] = $socket;
633+
}
612634

613635
foreach ( getenv() as $key => $value ) {
614636
if ( preg_match( '/^(WP_VERSION|NO_COLOR|CI|GITHUB_TOKEN|WP_CLI_TEST_(DBTYPE|OBJECT_CACHE|CORE_ZIP|QUIET|LOG_RUN_TIMES|PHP_TUNING|WP_VERSION_CACHE_TTL))$/', $key ) ) {
@@ -629,6 +651,10 @@ function wp_cli_tests_docker_worker_command( $name, $php_image, $db_image, array
629651
}
630652
}
631653

654+
if ( null !== $db_image ) {
655+
$command .= ' -v ' . escapeshellarg( sys_get_temp_dir() . "/{$name}-mysqld:" . WP_CLI_TESTS_DOCKER_SOCKET_DIR );
656+
}
657+
632658
foreach ( $env as $key => $value ) {
633659
$command .= ' -e ' . escapeshellarg( "{$key}={$value}" );
634660
}

‎utils/docker/Dockerfile‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ RUN . /etc/os-release \
1212
fi
1313

1414
# Images of older PHP versions are based on Debian releases whose packages have moved to the archive.
15+
# The extensions match those the PHP builds of shivammathur/setup-php have on the GitHub runners,
16+
# such as pcntl, which the official images leave out.
1517
RUN install_packages() { \
1618
apt-get update && apt-get install -y --no-install-recommends \
1719
curl git jq less libmariadb3 mariadb-client procps sqlite3 subversion unzip vim-tiny zip \
@@ -24,7 +26,7 @@ RUN install_packages() { \
2426
} ) \
2527
&& ( docker-php-ext-configure gd --with-freetype --with-jpeg \
2628
|| docker-php-ext-configure gd --with-freetype-dir=/usr --with-jpeg-dir=/usr ) \
27-
&& docker-php-ext-install exif gd mysqli pdo_mysql zip \
29+
&& docker-php-ext-install exif gd mysqli pcntl pdo_mysql zip \
2830
&& ( php -m | grep -qi '^zend opcache$' || docker-php-ext-install opcache ) \
2931
&& rm -rf /var/lib/apt/lists/*
3032

0 commit comments

Comments
 (0)