Files
termanager2/docker/php/entrypoint.sh
root 4f197a5ecb Fix: persist APP_KEY across redeploys via Docker env vars
- Entrypoint now overrides .env with Docker environment variables
- Supports all key vars: APP_KEY, APP_URL, DB_*, REDIS_*
- Warns to save APP_KEY in Dokploy if auto-generated
- Fixes DecryptException on proclamatori encrypted fields
2026-04-05 20:02:07 +02:00

128 lines
4.0 KiB
Bash
Executable File

#!/bin/bash
set -e
echo "========================================="
echo " TerManager2 - Entrypoint"
echo "========================================="
# -----------------------------------------------
# 1. Composer install
# -----------------------------------------------
if [ ! -f vendor/autoload.php ]; then
echo "[*] Installing Composer dependencies..."
composer install --no-interaction --optimize-autoloader
else
echo "[✓] Composer dependencies already installed."
fi
# -----------------------------------------------
# 2. .env file
# -----------------------------------------------
if [ ! -f .env ]; then
echo "[*] Creating .env from .env.example..."
cp .env.example .env
fi
# Override .env values with Docker environment variables (if set)
# This ensures Dokploy env vars take precedence
if [ -n "$APP_KEY" ]; then
sed -i "s|^APP_KEY=.*|APP_KEY=${APP_KEY}|" .env
fi
if [ -n "$APP_URL" ]; then
sed -i "s|^APP_URL=.*|APP_URL=${APP_URL}|" .env
fi
if [ -n "$DB_HOST" ]; then
sed -i "s|^DB_HOST=.*|DB_HOST=${DB_HOST}|" .env
fi
if [ -n "$DB_DATABASE" ]; then
sed -i "s|^DB_DATABASE=.*|DB_DATABASE=${DB_DATABASE}|" .env
fi
if [ -n "$DB_USERNAME" ]; then
sed -i "s|^DB_USERNAME=.*|DB_USERNAME=${DB_USERNAME}|" .env
fi
if [ -n "$DB_PASSWORD" ]; then
sed -i "s|^DB_PASSWORD=.*|DB_PASSWORD=${DB_PASSWORD}|" .env
fi
if [ -n "$REDIS_HOST" ]; then
sed -i "s|^REDIS_HOST=.*|REDIS_HOST=${REDIS_HOST}|" .env
fi
if [ -n "$REDIS_PASSWORD" ]; then
sed -i "s|^REDIS_PASSWORD=.*|REDIS_PASSWORD=${REDIS_PASSWORD}|" .env
fi
echo "[✓] .env file ready."
# -----------------------------------------------
# 3. Application key
# -----------------------------------------------
if grep -q "^APP_KEY=$" .env; then
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 ""
else
echo "[✓] Application key already set."
fi
# -----------------------------------------------
# 4. NPM install & build assets
# -----------------------------------------------
if [ ! -d node_modules ]; then
echo "[*] Installing NPM dependencies..."
npm ci
else
echo "[✓] NPM dependencies already installed."
fi
if [ ! -d public/build ]; then
echo "[*] Building frontend assets..."
npm run build
else
echo "[✓] Frontend assets already built."
fi
# -----------------------------------------------
# 5. Storage link
# -----------------------------------------------
if [ ! -L public/storage ]; then
echo "[*] Creating storage symlink..."
php artisan storage:link
else
echo "[✓] Storage symlink already exists."
fi
# -----------------------------------------------
# 6. Create required storage directories
# -----------------------------------------------
mkdir -p storage/framework/{cache,sessions,views}
mkdir -p storage/logs
mkdir -p bootstrap/cache
# -----------------------------------------------
# 7. Run migrations
# -----------------------------------------------
echo "[*] Running database migrations..."
php artisan migrate --force
# -----------------------------------------------
# 8. Cache config/routes/views
# -----------------------------------------------
echo "[*] Caching configuration..."
php artisan config:cache
php artisan route:cache
php artisan view:cache
echo "========================================="
echo " TerManager2 - Ready!"
echo "========================================="
# -----------------------------------------------
# Execute CMD (default: php-fpm)
# -----------------------------------------------
exec "$@"