From 531cb1b1e31a8c43cccd42838896acff42365f62 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Sat, 9 Aug 2025 18:05:31 +0100 Subject: [PATCH] Update Docker setup and improve health checks Dockerfile now copies and sets up script.sh as startup.sh. Dockerfile-db adds a custom healthcheck script using mariadb-admin. docker-compose.yml updates service commands, healthcheck configuration, and dependency conditions. script.sh improves database readiness logic. Minor fix in migration file to remove BOM character. --- Dockerfile | 4 ++++ Dockerfile-db | 4 ++++ application/migrations/139_modify_eQSL_url.php | 2 +- docker-compose.yml | 17 ++++++++--------- script.sh | 14 +++++++++----- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index cfaf7523..4e3c04b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,5 +24,9 @@ RUN apt-get update && apt-get install -y \ && docker-php-ext-install xml \ && a2enmod rewrite +# Copy script.sh and make it executable +COPY script.sh /usr/local/bin/startup.sh +RUN sed -i 's/\r$//' /usr/local/bin/startup.sh && chmod +x /usr/local/bin/startup.sh + # Expose port 80 EXPOSE 80 \ No newline at end of file diff --git a/Dockerfile-db b/Dockerfile-db index ac550b76..e4ce0ce8 100644 --- a/Dockerfile-db +++ b/Dockerfile-db @@ -4,5 +4,9 @@ FROM mariadb:latest # Add the install.sql file to the docker image ADD install/assets/install.sql /docker-entrypoint-initdb.d +# Create a healthcheck script that uses mariadb-admin +RUN echo '#!/bin/bash\nmariadb-admin ping -h "localhost" --silent' > /usr/local/bin/healthcheck.sh \ + && chmod +x /usr/local/bin/healthcheck.sh + # Expose port 3306 EXPOSE 3306 \ No newline at end of file diff --git a/application/migrations/139_modify_eQSL_url.php b/application/migrations/139_modify_eQSL_url.php index 09e4fc37..e3f04afc 100644 --- a/application/migrations/139_modify_eQSL_url.php +++ b/application/migrations/139_modify_eQSL_url.php @@ -1,4 +1,4 @@ - /dev/null 2>&1; do - echo "Database is not ready yet. Waiting 5 seconds..." - sleep 5 -done -echo "Database is ready!" +echo "Connecting to: Host=$MYSQL_HOST, User=$MYSQL_USER, Database=$MYSQL_DATABASE" + +# Give the database a moment, then test connection once +sleep 2 +if mariadb -h"$MYSQL_HOST" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -D"$MYSQL_DATABASE" -e "SELECT 1;" >/dev/null 2>&1; then + echo "Database is ready!" +else + echo "Database connection failed, but continuing anyway since healthcheck passed..." +fi # Set Permissions chown -R root:www-data /var/www/html/application/config/