Skip to content

Add healthcheck commands for MySQL containers #70987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions packages/env/lib/build-docker-compose-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ module.exports = function buildDockerComposeConfig( config ) {
config.env.tests.phpmyadminPort ?? ''
}}:80`;

const healthcheck = {
test: [
'CMD-SHELL',
'if [ "$LOCAL_DB_TYPE" = "mariadb" ]; then case "$LOCAL_DB_VERSION" in 5.5|10.0|10.1|10.2|10.3) mysqladmin ping -h localhost || exit $?;; *) mariadb-admin ping -h localhost || exit $?;; esac; fi',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very familiar with Docker, but I think LOCAL_DB_TYPE and LOCAL_DB_VERSION are environment variables for core development. I think the image is always mariadb in wp-env, so can we simplify the command a bit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, you're right. Looks like lts is always used as the version as well. So there's no need to guard against differences in older versions.

],
timeout: '5s',
interval: '5s',
retries: 10,
};

return {
services: {
mysql: {
Expand All @@ -192,7 +202,7 @@ module.exports = function buildDockerComposeConfig( config ) {
dbEnv.credentials.WORDPRESS_DB_PASSWORD,
MYSQL_DATABASE: dbEnv.development.WORDPRESS_DB_NAME,
},
volumes: [ 'mysql:/var/lib/mysql' ],
healthcheck,
Comment on lines -195 to +205
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can delete the volumes field because the database is reset every time we restart the environment.

},
'tests-mysql': {
image: 'mariadb:lts',
Expand All @@ -204,9 +214,14 @@ module.exports = function buildDockerComposeConfig( config ) {
MYSQL_DATABASE: dbEnv.tests.WORDPRESS_DB_NAME,
},
volumes: [ 'mysql-test:/var/lib/mysql' ],
healthcheck,
},
wordpress: {
depends_on: [ 'mysql' ],
depends_on: {
mysql: {
condition: 'service_healthy',
},
},
build: {
context: '.',
dockerfile: 'WordPress.Dockerfile',
Expand All @@ -224,7 +239,11 @@ module.exports = function buildDockerComposeConfig( config ) {
extra_hosts: [ 'host.docker.internal:host-gateway' ],
},
'tests-wordpress': {
depends_on: [ 'tests-mysql' ],
depends_on: {
'tests-mysql': {
condition: 'service_healthy',
},
},
build: {
context: '.',
dockerfile: 'Tests-WordPress.Dockerfile',
Expand Down
Loading