From 4c7adb6545e964a70b83bffa6803e15866c75718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Skowro=C5=84ski?= Date: Fri, 6 Oct 2023 01:31:35 +0200 Subject: [PATCH] Improve mysql container healthcheck --- .docker/php/docker-entrypoint.sh | 18 ------------------ .github/workflows/application.yml | 1 + docker-compose.override.yml | 2 ++ docker-compose.test.yml | 2 ++ 4 files changed, 5 insertions(+), 18 deletions(-) diff --git a/.docker/php/docker-entrypoint.sh b/.docker/php/docker-entrypoint.sh index 408a3316..496f0c33 100644 --- a/.docker/php/docker-entrypoint.sh +++ b/.docker/php/docker-entrypoint.sh @@ -16,24 +16,6 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then composer install --prefer-dist --no-progress --no-interaction || true fi - if grep -q DATABASE_URL= .env; then - echo "Waiting for database to be ready..." - ATTEMPTS_LEFT_TO_REACH_DATABASE=30 - until [ $ATTEMPTS_LEFT_TO_REACH_DATABASE -eq 0 ] || DATABASE_ERROR=$(php bin/console dbal:run-sql -q "SELECT 1" 2>&1); do - sleep 1 - ATTEMPTS_LEFT_TO_REACH_DATABASE=$((ATTEMPTS_LEFT_TO_REACH_DATABASE - 1)) - echo "Still waiting for database to be ready... Or maybe the database is not reachable. $ATTEMPTS_LEFT_TO_REACH_DATABASE attempts left." - done - - if [ $ATTEMPTS_LEFT_TO_REACH_DATABASE -eq 0 ]; then - echo "The database is not up or not reachable:" - echo "$DATABASE_ERROR" - exit 1 - else - echo "The database is now ready and reachable" - fi - fi - if [ "$APP_ENV" = 'prod' ]; then php bin/console doctrine:migrations:migrate --allow-no-migration --no-interaction fi diff --git a/.github/workflows/application.yml b/.github/workflows/application.yml index 34826685..be634808 100644 --- a/.github/workflows/application.yml +++ b/.github/workflows/application.yml @@ -46,6 +46,7 @@ jobs: if: failure() run: | docker compose logs php + docker compose logs mysql docker_release: name: Docker release diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 7fd3d17d..d0d33c78 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -24,6 +24,8 @@ services: image: mysql:5.7 env_file: - .docker/mysql/vars.env + healthcheck: + test: [ "CMD", "mysqladmin", "ping", "--protocol", "tcp" ] ports: - "33060:3306" diff --git a/docker-compose.test.yml b/docker-compose.test.yml index b0658156..11b28ce6 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -28,5 +28,7 @@ services: - .docker/mysql/vars.env environment: MYSQL_DATABASE: 'af_website_test' + healthcheck: + test: [ "CMD", "mysqladmin", "ping", "--protocol", "tcp" ] ports: - "3306:3306"