Enhance Docker Configuration and Health Checks (#761)

* Enhance Docker Configuration and Health Checks

- Added PHP configuration settings in `docker-compose.dev.yml` and `docker-compose.yml` to improve memory management and execution limits, ensuring better performance for PHP applications.
- Introduced health checks for various services including `api`, `api-worker`, `api-scheduler`, `ui`, `redis`, and `db` to ensure service availability and reliability.
- Updated environment variables in `.env.docker` and `client/.env.docker` to include new keys for H-Captcha and reCAPTCHA, enhancing security features.
- Refactored the PHP-FPM entrypoint script to apply PHP configurations dynamically based on environment variables, improving flexibility in deployment.
- Removed outdated PHP configuration files to streamline the Docker setup.

These changes aim to enhance the overall stability, performance, and security of the application in a Dockerized environment.

* Refactor Dockerfile for Improved Build Process

- Changed the Dockerfile to utilize a multi-stage build approach, separating the build and runtime environments for better efficiency.
- Introduced a builder stage using the PHP CLI image to install dependencies and extensions, optimizing the final image size.
- Removed unnecessary installation steps and combined related commands to streamline the Dockerfile, enhancing readability and maintainability.
- Updated the runtime stage to use the PHP FPM Alpine image, ensuring a smaller and more secure production environment.

These changes aim to improve the build process, reduce image size, and enhance the overall performance of the Dockerized application.
This commit is contained in:
Julien Nahum
2025-05-20 19:20:44 +02:00
committed by GitHub
parent b2b04d7f2a
commit ae21cae8cd
16 changed files with 320 additions and 164 deletions

View File

@@ -3,42 +3,82 @@
main() {
if [ "$IS_API_WORKER" = "true" ]; then
# This is the API worker, skip setup and just run the command
apply_php_configuration
exec "$@"
else
# This is the API service, run full setup
# This is the API service or scheduler, run full setup
apply_php_configuration
prep_file_permissions
prep_storage
wait_for_db
apply_db_migrations
run_init_project
optimize_application
if [ "$CONTAINER_ROLE" = "scheduler" ]; then
echo "Initializing scheduler status for first run (entrypoint)"
./artisan app:scheduler-status --mode=record
fi
run_server "$@"
fi
}
apply_php_configuration() {
echo "Applying PHP configuration from environment variables"
# Create custom PHP config file
PHP_CUSTOM_CONFIG_FILE="/usr/local/etc/php/conf.d/99-custom.ini"
# Apply memory limit if provided
if [ -n "$PHP_MEMORY_LIMIT" ]; then
echo "memory_limit = $PHP_MEMORY_LIMIT" >> $PHP_CUSTOM_CONFIG_FILE
fi
# Apply max execution time if provided
if [ -n "$PHP_MAX_EXECUTION_TIME" ]; then
echo "max_execution_time = $PHP_MAX_EXECUTION_TIME" >> $PHP_CUSTOM_CONFIG_FILE
fi
# Apply upload max filesize if provided
if [ -n "$PHP_UPLOAD_MAX_FILESIZE" ]; then
echo "upload_max_filesize = $PHP_UPLOAD_MAX_FILESIZE" >> $PHP_CUSTOM_CONFIG_FILE
fi
# Apply post max size if provided
if [ -n "$PHP_POST_MAX_SIZE" ]; then
echo "post_max_size = $PHP_POST_MAX_SIZE" >> $PHP_CUSTOM_CONFIG_FILE
fi
# Log applied configuration
echo "Applied PHP configuration:"
cat $PHP_CUSTOM_CONFIG_FILE
}
prep_file_permissions() {
chmod a+x ./artisan
}
prep_storage() {
# Create Laravel-specific directories
mkdir -p /persist/storage/framework/cache/data
mkdir -p /persist/storage/framework/sessions
mkdir -p /persist/storage/framework/views
local app_storage_path="/usr/share/nginx/html/storage"
# Create Laravel-specific directories directly in the mounted volume
mkdir -p "$app_storage_path/app/public"
mkdir -p "$app_storage_path/framework/cache/data"
mkdir -p "$app_storage_path/framework/sessions"
mkdir -p "$app_storage_path/framework/views"
mkdir -p "$app_storage_path/logs"
# Set permissions for the entire storage directory
chown -R www-data:www-data /persist/storage
chmod -R 775 /persist/storage
# Create symlink to the correct storage location
ln -sf /persist/storage /usr/share/nginx/html/storage
chown -R www-data:www-data "$app_storage_path"
chmod -R 775 "$app_storage_path"
touch /var/log/opnform.log
chown www-data /var/log/opnform.log
# Ensure proper permissions for the storage directory
chown -R www-data:www-data /usr/share/nginx/html/storage
chmod -R 775 /usr/share/nginx/html/storage
# Run Laravel's storage link command (ensure script is run from app root or adjust path to artisan)
echo "Creating public storage symlink"
./artisan storage:link
}
wait_for_db() {