diff --git a/docker/php/entrypoint.sh b/docker/php/entrypoint.sh index 0fa6e78..e34c869 100755 --- a/docker/php/entrypoint.sh +++ b/docker/php/entrypoint.sh @@ -59,21 +59,26 @@ fi echo "[✓] .env file ready." # ----------------------------------------------- -# 2. Application key +# 2. Application key (persisted in storage volume) # ----------------------------------------------- -if grep -q "^APP_KEY=$" .env; then +KEY_FILE="/var/www/html/storage/app/.app_key" + +if [ -f "$KEY_FILE" ]; then + # Restore key from persistent volume + STORED_KEY=$(cat "$KEY_FILE") + sed -i "s|^APP_KEY=.*|APP_KEY=${STORED_KEY}|" .env + echo "[✓] Application key restored from storage." +elif grep -q "^APP_KEY=$" .env; then + # No stored key and .env has empty key: generate new one echo "[*] Generating application key..." php artisan key:generate --ansi - echo "" - echo "╔══════════════════════════════════════════════════════╗" - echo "║ IMPORTANT: Save this APP_KEY in Dokploy env vars! ║" - echo "║ Otherwise encrypted data will be lost on redeploy. ║" - echo "╚══════════════════════════════════════════════════════╝" - echo "" - echo " APP_KEY=$(grep '^APP_KEY=' .env | cut -d= -f2-)" - echo "" + # Save to persistent volume + grep '^APP_KEY=' .env | cut -d= -f2- > "$KEY_FILE" + echo "[✓] Application key saved to persistent storage." else - echo "[✓] Application key already set." + # .env already has a key (from env var override or .env.example), persist it + grep '^APP_KEY=' .env | cut -d= -f2- > "$KEY_FILE" + echo "[✓] Application key already set, saved to persistent storage." fi # -----------------------------------------------