feat(docker): add boot-container.sh and init-app.sh lifecycle scripts
This commit is contained in:
parent
d4abc61f24
commit
fa10d792fa
55
build/boot-container.sh
Executable file
55
build/boot-container.sh
Executable file
|
|
@ -0,0 +1,55 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd /app
|
||||||
|
|
||||||
|
echo "[boot] Starting pp-planer container boot..."
|
||||||
|
|
||||||
|
# Ensure all required directories exist (volumes may be freshly mounted)
|
||||||
|
mkdir -p \
|
||||||
|
storage/logs \
|
||||||
|
storage/framework/views \
|
||||||
|
storage/framework/cache/data \
|
||||||
|
storage/framework/sessions \
|
||||||
|
storage/app/public \
|
||||||
|
database \
|
||||||
|
public
|
||||||
|
|
||||||
|
# Run first-time initialization (idempotent — safe to call every boot)
|
||||||
|
/app/build/init-app.sh
|
||||||
|
|
||||||
|
# Fix permissions: www-data must own all writable directories.
|
||||||
|
# The || true prevents exit on macOS Docker Desktop (bind-mount ownership restrictions).
|
||||||
|
# On a Linux host running as root, chown will succeed silently.
|
||||||
|
chown -R www-data:www-data storage bootstrap/cache database 2>/dev/null || true
|
||||||
|
chmod -R 775 storage bootstrap/cache database 2>/dev/null || true
|
||||||
|
|
||||||
|
# Sync built Vite assets from the image (public-build/) into the
|
||||||
|
# bind-mounted public/ directory. This ensures Caddy always serves
|
||||||
|
# up-to-date assets even though public/ is a host bind-mount.
|
||||||
|
if [ -d /app/public-build ]; then
|
||||||
|
echo "[boot] Syncing built assets to public/..."
|
||||||
|
cp -r /app/public-build/. /app/public/
|
||||||
|
chown -R www-data:www-data /app/public 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create the storage symlink after volumes are mounted
|
||||||
|
# (public/storage → storage/app/public)
|
||||||
|
echo "[boot] Creating storage symlink..."
|
||||||
|
php artisan storage:link --force 2>/dev/null || true
|
||||||
|
|
||||||
|
# Run database migrations
|
||||||
|
echo "[boot] Running migrations..."
|
||||||
|
php artisan migrate --force
|
||||||
|
|
||||||
|
# Warm up Laravel caches
|
||||||
|
echo "[boot] Warming caches..."
|
||||||
|
php artisan config:cache
|
||||||
|
php artisan route:cache
|
||||||
|
php artisan view:cache
|
||||||
|
php artisan event:cache
|
||||||
|
|
||||||
|
echo "[boot] Boot complete. Starting supervisord..."
|
||||||
|
|
||||||
|
# Hand off to CMD (supervisord)
|
||||||
|
exec "$@"
|
||||||
23
build/init-app.sh
Executable file
23
build/init-app.sh
Executable file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd /app
|
||||||
|
|
||||||
|
DB_PATH="/app/database/database.sqlite"
|
||||||
|
|
||||||
|
if [ -f "$DB_PATH" ]; then
|
||||||
|
echo "[init] Database already exists, skipping first-run init."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[init] First run detected — initializing application..."
|
||||||
|
|
||||||
|
touch "$DB_PATH"
|
||||||
|
chmod 664 "$DB_PATH"
|
||||||
|
|
||||||
|
if [ -z "${APP_KEY}" ]; then
|
||||||
|
echo "[init] Generating application key..."
|
||||||
|
php artisan key:generate --force
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[init] First-run init complete."
|
||||||
Loading…
Reference in a new issue