Skip to content

Commit a8a0bf0

Browse files
committed
Build/Test Tools: Ensure database containers are prepared for commands.
By default, Docker waits for a container to be started before considering it “ready”. But this does not necessarily mean that it’s ready to receive commands. This adds a check that ensures the database container is ready to receive commands before proceeding with running commands. Follow up to [56439], [56440], [56443]. Props rmccue, desrosj. See #30462, #58867. git-svn-id: https://develop.svn.wordpress.org/trunk@56464 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 218fbd9 commit a8a0bf0

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

‎docker-compose.yml‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ services:
2525
command: /bin/sh -c "envsubst '$$LOCAL_DIR' < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
2626

2727
depends_on:
28-
- php
28+
php:
29+
condition: service_started
30+
mysql:
31+
condition: service_healthy
2932

3033
##
3134
# The PHP container.
@@ -52,9 +55,6 @@ services:
5255
# Copy or delete the Memcached dropin plugin file as appropriate.
5356
command: /bin/sh -c "if [ $LOCAL_PHP_MEMCACHED = true ]; then cp -n /var/www/tests/phpunit/includes/object-cache.php /var/www/src/wp-content/object-cache.php; else rm -f /var/www/src/wp-content/object-cache.php; fi && exec php-fpm"
5457

55-
depends_on:
56-
- mysql
57-
5858
# The init directive ensures the command runs with a PID > 1, so Ctrl+C works correctly.
5959
init: true
6060

@@ -83,6 +83,12 @@ services:
8383
# For compatibility with PHP versions that don't support the caching_sha2_password auth plugin used in MySQL 8.0.
8484
command: --default-authentication-plugin=mysql_native_password
8585

86+
healthcheck:
87+
test: [ "CMD-SHELL", "if [ \"$LOCAL_DB_TYPE\" = \"mariadb\" ]; then mariadb-admin ping -h localhost; else mysqladmin ping -h localhost; fi" ]
88+
timeout: 5s
89+
interval: 5s
90+
retries: 10
91+
8692
##
8793
# The WP CLI container.
8894
##
@@ -107,6 +113,12 @@ services:
107113
extra_hosts:
108114
- localhost:host-gateway
109115

116+
depends_on:
117+
php:
118+
condition: service_started
119+
mysql:
120+
condition: service_healthy
121+
110122
##
111123
# The Memcached container.
112124
##
@@ -119,6 +131,10 @@ services:
119131
ports:
120132
- 11211:11211
121133

134+
depends_on:
135+
php:
136+
condition: service_started
137+
122138
volumes:
123139
# So that sites aren't wiped every time containers are restarted, MySQL uses a persistent volume.
124140
mysql: {}

0 commit comments

Comments
 (0)