From d289731b2c068271ee9a6c3f9cccfd939ba8e614 Mon Sep 17 00:00:00 2001 From: Jeremy Massel <1123407+jkmassel@users.noreply.github.com> Date: Wed, 22 May 2024 13:18:29 -0600 Subject: [PATCH 1/2] Fix flaky network tests --- docker-compose.yml | 13 +------------ mysql_config/config.cnf | 4 ---- scripts/setup-test-site.sh | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 17 deletions(-) delete mode 100644 mysql_config/config.cnf diff --git a/docker-compose.yml b/docker-compose.yml index e0cafb8c0..8bd1298ec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,10 +16,6 @@ services: WORDPRESS_CONFIG_EXTRA: | # Allow application passwords to be used without HTTPS define( 'WP_ENVIRONMENT_TYPE', 'local' ); - - depends_on: - mysql: - condition: service_healthy healthcheck: test: ["CMD", "bash" ,"-c", "[ -f /var/www/html/wp-config.php ]"] interval: 4s @@ -27,7 +23,7 @@ services: retries: 30 mysql: - image: 'public.ecr.aws/docker/library/mysql:8.0' + image: 'public.ecr.aws/docker/library/mariadb:11.2' ports: - '3306:3306' environment: @@ -35,10 +31,3 @@ services: MYSQL_USER: 'wordpress' MYSQL_PASSWORD: 'wordpress' MYSQL_RANDOM_ROOT_PASSWORD: true - volumes: - - ./mysql_config:/mysql_config - healthcheck: - test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] - interval: 4s - timeout: 1s - retries: 30 diff --git a/mysql_config/config.cnf b/mysql_config/config.cnf deleted file mode 100644 index 3b5e793c6..000000000 --- a/mysql_config/config.cnf +++ /dev/null @@ -1,4 +0,0 @@ -[client] -user = "wordpress" -password = "wordpress" -host = "localhost" diff --git a/scripts/setup-test-site.sh b/scripts/setup-test-site.sh index 07ddef152..3aa95ef39 100755 --- a/scripts/setup-test-site.sh +++ b/scripts/setup-test-site.sh @@ -11,13 +11,46 @@ set -e curl https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar --output /usr/bin/wp chmod +x /usr/bin/wp +# Install `mysqlcheck` – needed for `wp db check` +apt update && apt install -y default-mysql-client + +# Create wpcli working directory (it can't be created by the `www-data` user`) +mkdir -p /var/www/.wp-cli +chown -R www-data:www-data /var/www/.wp-cli/ + # Run all the commands below as `www-data` (because that's what WordPress uses itself, so there shouldn't # be any weird permissions issues) su -s /bin/bash www-data -## Install WordPress +## Download WordPress wp core download --force +## Wait for the DB to be ready before attempting install – Docker can do this for us, but we get way better +## diagnostic information from `wp db check`, whereas if `wp core install` fails it won't tell us about issues +## like incompatible SSL cipher suites (which is a problem in the WP 5.7 image when used with MySQL 8+) +tries=0 +while true; do + + code=0 + wp db check || code=$? + + if [ $code == 0 ]; then + echo 'Database Ready' + break; + fi + + if [ $tries -gt 5 ]; then + echo 'Unable to connect to database' + exit 1 + fi + + echo 'The database is not ready yet – waiting 5 seconds' + sleep 5 + + tries=$(( $tries + 1 )) +done + +## Install WordPress wp core install \ --url=localhost \ --title=my-test-site \ From 6bf72d6ffa09994cd92bfcf13645ede9fed7cb22 Mon Sep 17 00:00:00 2001 From: Jeremy Massel <1123407+jkmassel@users.noreply.github.com> Date: Wed, 22 May 2024 16:20:13 -0600 Subject: [PATCH 2/2] Ensure e2e test compatibility --- .gitignore | 1 + Makefile | 4 ++-- docker-compose.yml | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 6ab1a9994..a81a88f5f 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ native/swift/Sources/wordpress-api-wrapper/*.swift .wordpress test_credentials /logs +dump.sql # CI Cache .cargo diff --git a/Makefile b/Makefile index c2bb2d432..48c378f62 100644 --- a/Makefile +++ b/Makefile @@ -195,10 +195,10 @@ stop-server: delete-wp-plugins-backup docker-compose down dump-mysql: - docker exec -it wordpress-rs-mysql-1 /bin/bash -c "mysqldump --defaults-extra-file=mysql_config/config.cnf --no-tablespaces wordpress > dump.sql" + docker exec -it wordpress-rs-database-1 mariadb-dump -u wordpress -pwordpress --no-tablespaces wordpress > dump.sql restore-mysql: - docker exec -it wordpress-rs-mysql-1 /bin/bash -c "mysql --defaults-extra-file=mysql_config/config.cnf --database wordpress < dump.sql" + cat dump.sql | docker exec -i wordpress-rs-database-1 mariadb -u wordpress -pwordpress --database wordpress backup-wp-content-plugins: docker exec -it wordpress /bin/bash -c "cp -R ./wp-content/plugins /tmp/backup_wp_plugins" diff --git a/docker-compose.yml b/docker-compose.yml index 8bd1298ec..edc140bbb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: - .wordpress:/var/www/html - ./test_credentials:/tmp/test_credentials environment: - WORDPRESS_DB_HOST: mysql + WORDPRESS_DB_HOST: database WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress WORDPRESS_DB_NAME: wordpress @@ -22,7 +22,7 @@ services: timeout: 1s retries: 30 - mysql: + database: image: 'public.ecr.aws/docker/library/mariadb:11.2' ports: - '3306:3306'