From afa05d272e329f8bffd57663255b8d13d8a66db4 Mon Sep 17 00:00:00 2001 From: Frank John Begornia Date: Fri, 2 Jan 2026 01:44:36 +0800 Subject: [PATCH] Add entrypoint script for better container startup and debugging --- .gitea/workflows/deploy.yml | 17 ++++++++++++++-- Dockerfile | 8 ++++++-- docker-entrypoint.sh | 40 +++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 docker-entrypoint.sh diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 7a2bcde..c9e1acb 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -105,8 +105,21 @@ jobs: echo "Starting unified container (env vars from .env file)" docker compose up -d - echo "Waiting for container to start" - sleep 10 + echo "Waiting for container to start (30 seconds)..." + sleep 5 + + # Check if container is running or restarting + CONTAINER_STATE=$(docker inspect --format='{{.State.Status}}' email_reports_unified 2>/dev/null || echo "not_found") + echo "Container state: $CONTAINER_STATE" + + if [ "$CONTAINER_STATE" = "restarting" ]; then + echo "Container is restarting - showing logs:" + docker logs email_reports_unified + exit 1 + fi + + # Wait a bit more for initialization + sleep 25 if docker ps --format '{{.Names}}' | grep -q email_reports_unified; then echo "✓ Container is running" diff --git a/Dockerfile b/Dockerfile index 5a98c7c..7b3c0de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,10 @@ COPY . /app/ RUN mkdir -p /app/daily_order_reports_crew /app/daily_order_reports_merchbay && \ chmod 755 /app/daily_order_reports_crew /app/daily_order_reports_merchbay +# Copy entrypoint script +COPY docker-entrypoint.sh /docker-entrypoint.sh +RUN chmod +x /docker-entrypoint.sh + # Create crontab with both reports RUN echo "55 23 * * * BRAND=crew php /app/send_report.php >> /var/log/cron.log 2>&1" > /etc/crontabs/root && \ echo "56 23 * * * BRAND=merchbay php /app/send_report.php >> /var/log/cron.log 2>&1" >> /etc/crontabs/root && \ @@ -35,5 +39,5 @@ RUN touch /var/log/cron.log && \ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD ps aux | grep -v grep | grep -q crond || exit 1 -# Start cron in foreground -CMD crond -f -l 2 +# Use entrypoint script +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..a03a555 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,40 @@ +#!/bin/sh +set -e + +echo "Email Reports Container Starting..." +echo "Current time: $(date)" +echo "Timezone: $(date +%Z)" + +# Verify crontab is configured +echo "" +echo "Cron schedule:" +crontab -l || echo "Warning: No crontab found" + +# Create log file if it doesn't exist +touch /var/log/cron.log +chmod 666 /var/log/cron.log + +# Create email log if it doesn't exist +touch /app/email.log +chmod 666 /app/email.log + +# Test PHP +echo "" +echo "Testing PHP..." +php -v || { echo "PHP test failed"; exit 1; } + +# Test database connectivity (optional - won't fail if not reachable) +echo "" +echo "Environment variables loaded:" +echo " DB_HOST_CREW: ${DB_HOST_CREW:-not set}" +echo " DB_HOST_MERCHBAY: ${DB_HOST_MERCHBAY:-not set}" +echo " SMTP_HOST: ${SMTP_HOST:-not set}" + +# Start crond in foreground +echo "" +echo "Starting cron daemon in foreground..." +echo "Logs will be written to:" +echo " - Cron output: /var/log/cron.log" +echo " - Email logs: /app/email.log" +echo "" +exec crond -f -l 2