#!/bin/bash # BookWyrm Web Container Entrypoint # Simplified - init containers handle database/migrations set -e echo "[$(date +'%Y-%m-%d %H:%M:%S')] Starting BookWyrm Web Container..." # Only handle web-specific tasks (database/migrations handled by init containers) # Compile themes FIRST - must happen before static file collection echo "[$(date +'%Y-%m-%d %H:%M:%S')] Checking if theme compilation is needed..." if [ "${FORCE_COMPILE_THEMES:-false}" = "true" ] || [ ! -f "/tmp/.themes_compiled" ]; then echo "[$(date +'%Y-%m-%d %H:%M:%S')] Compiling themes..." if python manage.py compile_themes; then touch /tmp/.themes_compiled echo "[$(date +'%Y-%m-%d %H:%M:%S')] Theme compilation completed successfully" else echo "WARNING: Theme compilation failed" fi else echo "[$(date +'%Y-%m-%d %H:%M:%S')] Themes already compiled, skipping (set FORCE_COMPILE_THEMES=true to force)" fi # Collect static files AFTER theme compilation - includes compiled CSS files echo "[$(date +'%Y-%m-%d %H:%M:%S')] Checking if static files collection is needed..." if [ "${FORCE_COLLECTSTATIC:-false}" = "true" ] || [ ! -f "/tmp/.collectstatic_done" ]; then echo "[$(date +'%Y-%m-%d %H:%M:%S')] Collecting static files to S3..." if python manage.py collectstatic --noinput --clear; then touch /tmp/.collectstatic_done echo "[$(date +'%Y-%m-%d %H:%M:%S')] Static files collection completed successfully" else echo "WARNING: Static files collection to S3 failed" fi else echo "[$(date +'%Y-%m-%d %H:%M:%S')] Static files already collected, skipping (set FORCE_COLLECTSTATIC=true to force)" fi # Ensure nginx configuration is valid echo "[$(date +'%Y-%m-%d %H:%M:%S')] Validating Nginx configuration..." nginx -t # Clean up any stale supervisor sockets and pid files echo "[$(date +'%Y-%m-%d %H:%M:%S')] Cleaning up stale supervisor files..." rm -f /tmp/bookwyrm-web-supervisor.sock rm -f /tmp/supervisord-web.pid echo "[$(date +'%Y-%m-%d %H:%M:%S')] BookWyrm web container initialization completed" echo "[$(date +'%Y-%m-%d %H:%M:%S')] Starting web services..." # Execute the provided command (usually supervisord) exec "$@"