lthn.io/utils/scripts/laravel-entrypoint.sh
Claude c89bee8e51
feat: add FrankenPHP + Octane Dockerfile and docker-compose
Copied production-quality Dockerfile from hostuk (FrankenPHP 1-php8.5,
Octane, Supervisor, Redis). Added docker-compose.yml with Traefik
labels for lthn.io, api.lthn.io, docs.lthn.io, explorer.lthn.io.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 10:36:42 +01:00

57 lines
1.9 KiB
Bash

#!/bin/sh
set -e
# Laravel Container Startup Script
# Runs migrations and clears all caches on container start
# Critical for FrankenPHP/Octane where workers cache state in memory
echo "[Laravel] Starting container setup..."
cd /app
# Force clear ALL cached files (belt and braces approach)
# This handles edge cases where artisan clear commands fail silently
echo "[Laravel] Purging all cached files..."
rm -rf bootstrap/cache/*.php 2>/dev/null || true
rm -rf storage/framework/cache/data/* 2>/dev/null || true
rm -rf storage/framework/views/* 2>/dev/null || true
# Ensure directories exist with correct permissions
mkdir -p storage/framework/{cache/data,sessions,views}
mkdir -p storage/logs
chown -R www-data:www-data storage bootstrap/cache 2>/dev/null || true
# Regenerate package manifest
echo "[Laravel] Discovering packages..."
php artisan package:discover --ansi 2>/dev/null || true
# Create storage link if it doesn't exist
if [ ! -L "/app/public/storage" ]; then
echo "[Laravel] Creating storage link..."
php artisan storage:link 2>/dev/null || true
fi
# Run migrations (only if DB is accessible)
echo "[Laravel] Running migrations..."
if php artisan migrate --force 2>/dev/null; then
echo "[Laravel] Migrations completed"
# Run seeders (idempotent - uses updateOrCreate patterns)
echo "[Laravel] Running seeders..."
if php artisan db:seed --force 2>/dev/null; then
echo "[Laravel] Seeders completed"
else
echo "[Laravel] Warning: Seeders failed"
fi
else
echo "[Laravel] Warning: Migrations skipped (database may not be ready)"
fi
# Clear Laravel's internal caches via artisan (backup to rm -rf above)
echo "[Laravel] Clearing artisan caches..."
php artisan config:clear 2>/dev/null || true
php artisan route:clear 2>/dev/null || true
php artisan view:clear 2>/dev/null || true
php artisan event:clear 2>/dev/null || true
echo "[Laravel] Setup complete - ready for Octane"