docker-mautic icon indicating copy to clipboard operation
docker-mautic copied to clipboard

feat: adding checks for safer startup

Open O-Mutt opened this issue 7 months ago • 2 comments

Description

This PR is to run several checks on docker container startup.

  1. Check to ensure that the three volumes: logs, media, and config exist
  2. Ensure the step 1s listed volumes have the correct ownership
  3. check that the MAUTIC_DB_* env variables are set
  4. 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.sh to 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.sh to 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.sh to 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 new MAUTIC_VOLUMES array 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.

O-Mutt avatar May 29 '25 20:05 O-Mutt

Resolves #411 and #413

O-Mutt avatar May 30 '25 10:05 O-Mutt

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

O-Mutt avatar Jun 05 '25 11:06 O-Mutt

All good!

Thanks @O-Mutt, nice work :)

cibero42 avatar Jul 10 '25 20:07 cibero42