Skip to content
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

Adds delay to allow mysql to provision before starting application #20

Closed
wants to merge 1 commit into from

Conversation

vitaleg
Copy link

@vitaleg vitaleg commented Nov 8, 2024

Fixes a problem where on first run the application tries to create tables in the database before the mysql server is ready.

Fixes a problem where on first run the application tries to create tables in the database before the mysql server is ready.
@hackeresq
Copy link
Collaborator

Appreciate the thoughtful PR!

Curious on the 1 second interval. What are you thoughts on increasing that to 30 seconds?

@vitaleg
Copy link
Author

vitaleg commented Nov 9, 2024

I think 30s is too much. Maybe 10s would be optimal.
At the same time, don't forget that the start-period parameter gives time before the checks are executed.

@hackeresq hackeresq changed the title Update docker-compose.yml Adds delay to allow mysql to provision before starting application Nov 14, 2024
@hackeresq
Copy link
Collaborator

Hi @vitaleg, thanks for your contribution. While I've added your depends_on to the app service, I had decided to adopt a different solution in the entrypoint.sh, which uses bash. Frankly I'm much more competent in bash (and will likely be more maintainable over time):

echo "====================== Running migrations...  ====================== "
run_migrations() {
    /usr/local/bin/php artisan migrate --force
}
RETRIES=30
DELAY=5
until run_migrations; do
  RETRIES=$((RETRIES-1))
  if [ $RETRIES -le 0 ]; then
    echo "Database is not ready after multiple attempts. Exiting..."
    exit 1
  fi
  echo "Waiting for database to be ready... retrying in $DELAY seconds."
  sleep $DELAY
done

@hackeresq hackeresq closed this Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants