Feature: Updating entrypoints, to support caching, migrations, etc

This commit is contained in:
2026-09-01 12:43:19 +03:00
parent 2d75bb9e01
commit ea6ebe435e
2 changed files with 95 additions and 33 deletions
+32 -11
View File
@@ -5,17 +5,38 @@ set -e
# by app only) — just wait for app's migration to finish, then start the process.
mkdir -p storage/app/public storage/framework/cache storage/framework/sessions storage/framework/views storage/logs storage/framework bootstrap/cache
if [ "$APP_ENV" != "production" ]; then
echo "[entrypoint] Waiting for migrations to complete..."
timeout=60
while [ ! -f storage/framework/migrated ] && [ "$timeout" -gt 0 ]; do
sleep 1
timeout=$((timeout - 1))
done
if [ ! -f storage/framework/migrated ]; then
echo "[entrypoint] Timed out waiting for migrations" >&2
exit 1
fi
# Same reasoning as entrypoint.sh: this container gets replaced on every deploy
# (dev and production alike), so this is a fresh boot clearing stale artifacts
# left on disk (cached config, compiled views), not a running process being
# told to forget in-memory code. queue:work/schedule:work themselves still
# can't pick up a later code change without an actual process restart — this
# only fixes what's stale on disk at boot.
echo "[entrypoint] Clearing cached config/routes/views..."
php artisan optimize:clear --quiet
echo "[entrypoint] Caches cleared"
# Universal, in both dev and production — app's entrypoint always writes this
# marker after `migrate --force` completes (single app instance, so there's
# exactly one writer), and queue/scheduler must never start against a database
# schema that migration hasn't finished bringing up to date yet.
echo "[entrypoint] Waiting for migrations to complete..."
timeout=60
while [ ! -f storage/framework/migrated ] && [ "$timeout" -gt 0 ]; do
sleep 1
timeout=$((timeout - 1))
done
if [ ! -f storage/framework/migrated ]; then
echo "[entrypoint] Timed out waiting for migrations" >&2
exit 1
fi
if [ "$APP_ENV" = "production" ]; then
# Same reasoning as entrypoint.sh's own production-only optimize step —
# queue:work/schedule:work read config on every job/tick too, so this
# avoids paying the same uncached-config cost app pays per request.
echo "[entrypoint] Caching config/routes/views for production..."
php artisan optimize --quiet
echo "[entrypoint] Production caches built"
fi
exec "$@"