feat: adding checks for safer startup
Description
This PR is to run several checks on docker container startup.
- Check to ensure that the three volumes: logs, media, and config exist
- Ensure the step 1s listed volumes have the correct ownership
- check that the
MAUTIC_DB_*env variables are set - Attempt to connect to the DB using step 3s credentials (with a timeout)
In using these 4 steps we create a more friendly user experience for starting up the containers
Another split from #359, pt 2.
Copilot summary
This pull request refactors and improves the initialization process for a Docker-based Mautic setup by introducing modular checks for environment variables, database connectivity, and volume existence/ownership. It also simplifies and organizes the entrypoint scripts for better maintainability.
Refactoring and modularization of checks:
- Environment variable validation: Added a new script
check_environment_variables.shto ensure required environment variables (MAUTIC_DB_HOST,MAUTIC_DB_PORT,MAUTIC_DB_USER,MAUTIC_DB_PASSWORD,DOCKER_MAUTIC_ROLE) are set before proceeding. - Database connection check: Introduced
check_database_connection.shto handle MySQL connectivity validation with retry logic and clear error handling if the database is not responsive after a maximum number of attempts. - Volume existence and ownership validation: Added
check_volumes_exist_ownership.shto verify that specified volumes exist and have the correct ownership (MAUTIC_WWW_USER:MAUTIC_WWW_GROUP), applying ownership changes if necessary.
Simplification of entrypoint scripts:
- Streamlined
docker-entrypoint.sh: Replaced inline checks with modular scripts (check_volumes_exist_ownership.sh,check_environment_variables.sh,check_database_connection.sh) for better organization and maintainability. Also introduced a newMAUTIC_VOLUMESarray to manage volume paths more effectively. - Removed redundant logic from
entrypoint_mautic_web.sh: Eliminated direct ownership checks and database connection wait logic, delegating these tasks to the newly added modular scripts.
Resolves #411 and #413
The code looks good to me.
I'd just suggest having a look at what Copilot wrote.
When that's solved, I'll proceed with testing!
Copilot be copiloting: https://github.com/mautic/docker-mautic/pull/412#discussion_r2116262873 contradicts https://github.com/mautic/docker-mautic/pull/412#discussion_r2115782532
All good!
Thanks @O-Mutt, nice work :)