2e5955beea
FrankenPHP/Caddy does not reliably follow the public/storage symlink when serving static files, causing 404 on all media URLs (/storage/…). Add CADDY_SERVER_EXTRA_DIRECTIVES with an explicit handle_path block that maps /storage/* directly to /app/storage/app/public, avoiding the symlink entirely. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
59 lines
2.4 KiB
Bash
59 lines
2.4 KiB
Bash
#!/bin/sh
|
|
set -e
|
|
|
|
cd /app
|
|
|
|
# Ensure storage subdirs exist
|
|
mkdir -p storage/framework/{cache,sessions,views,testing} storage/logs storage/app/public bootstrap/cache
|
|
chown -R www-data:www-data storage bootstrap/cache 2>/dev/null || true
|
|
|
|
# DESTRUCTIVE: drops all tables + re-runs migrations + seed.
|
|
# Set in Coolify only when intentionally resetting DB. Remove after.
|
|
if [ "${RUN_FRESH_MIGRATE:-false}" = "true" ]; then
|
|
echo "[entrypoint] !!! RUN_FRESH_MIGRATE=true — dropping all tables !!!"
|
|
php artisan migrate:fresh --force --seed --no-interaction || echo "[entrypoint] fresh failed"
|
|
elif [ "${RUN_MIGRATIONS:-true}" = "true" ]; then
|
|
echo "[entrypoint] Running migrations..."
|
|
php artisan migrate --force --no-interaction || echo "[entrypoint] migrate failed (non-fatal)"
|
|
fi
|
|
|
|
# Run seeders if requested. Uses firstOrCreate so it's idempotent.
|
|
if [ "${RUN_SEED:-false}" = "true" ] && [ "${RUN_FRESH_MIGRATE:-false}" != "true" ]; then
|
|
echo "[entrypoint] Running database seed..."
|
|
php artisan db:seed --force --no-interaction || echo "[entrypoint] seed failed (non-fatal)"
|
|
fi
|
|
|
|
# Production caches
|
|
if [ "${APP_ENV:-production}" = "production" ]; then
|
|
echo "[entrypoint] Caching config/routes/views..."
|
|
php artisan config:cache --no-interaction || true
|
|
php artisan route:cache --no-interaction || true
|
|
php artisan view:clear --no-interaction || true
|
|
php artisan view:cache --no-interaction || true
|
|
php artisan event:cache --no-interaction || true
|
|
php artisan filament:cache-components --no-interaction || true
|
|
fi
|
|
|
|
# Storage symlink (idempotent)
|
|
php artisan storage:link --no-interaction 2>/dev/null || true
|
|
|
|
# FrankenPHP/Caddy does not follow the public/storage→storage/app/public symlink
|
|
# reliably. Add an explicit Caddy route that serves /storage/* directly from the
|
|
# real directory, bypassing symlink resolution entirely.
|
|
export CADDY_SERVER_EXTRA_DIRECTIVES='handle_path /storage/* { root * /app/storage/app/public; file_server }'
|
|
|
|
# Background scheduler — fires every minute. Drives backup:tenants and other cron jobs.
|
|
# Skipped if RUN_SCHEDULER=false (e.g., when running multiple replicas).
|
|
if [ "${RUN_SCHEDULER:-true}" = "true" ]; then
|
|
echo "[entrypoint] Starting Laravel scheduler in background..."
|
|
(
|
|
while true; do
|
|
php artisan schedule:run --no-interaction >> storage/logs/scheduler.log 2>&1 || true
|
|
sleep 60
|
|
done
|
|
) &
|
|
fi
|
|
|
|
echo "[entrypoint] Starting: $@"
|
|
exec "$@"
|