Add entrypoint script for better container startup and debugging
Some checks failed
Deploy Production Email Reports (Unified) / deploy (push) Failing after 18s
Some checks failed
Deploy Production Email Reports (Unified) / deploy (push) Failing after 18s
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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"]
|
||||
|
||||
40
docker-entrypoint.sh
Normal file
40
docker-entrypoint.sh
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user