Skip to content

Commit

Permalink
Improve mysql container healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
jskowronski39 committed Oct 5, 2023
1 parent afbdb14 commit 4c7adb6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 18 deletions.
18 changes: 0 additions & 18 deletions .docker/php/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
if: failure()
run: |
docker compose logs php
docker compose logs mysql
docker_release:
name: Docker release
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 4c7adb6

Please sign in to comment.