Files
nomina_ventas/docker/entrypoint.sh

100 lines
3.4 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -e
echo "========================================"
echo " Nomina Ventas - Entrypoint"
echo "========================================"
# Verificar que el código existe en /var/www/html
if [ ! -f /var/www/html/artisan ]; then
echo "ERROR: No se encontró el código en /var/www/html"
echo "Montando volumen con el código..."
exit 1
fi
# Asegurar que existan los directorios necesarios (importante para volúmenes montados)
mkdir -p /var/www/html/storage/framework/{cache,sessions,views}
mkdir -p /var/www/html/storage/logs
mkdir -p /var/www/html/bootstrap/cache
# Asegurar permisos
chown -R laravel:laravel /var/www/html/storage
chown -R laravel:laravel /var/www/html/bootstrap/cache
chmod -R 775 /var/www/html/storage
chmod -R 775 /var/www/html/bootstrap/cache
# ===== GENERAR O ACTUALIZAR .env =====
echo "Intentando sincronizar .env desde variables de Docker..."
# Generamos el contenido en un archivo temporal
cat > /tmp/.env.tmp << EOF
APP_NAME="${APP_NAME:-Laravel}"
APP_ENV="${APP_ENV:-production}"
APP_KEY=${APP_KEY}
APP_DEBUG=${APP_DEBUG:-false}
APP_URL=${APP_URL:-http://localhost}
APP_LOCALE=${APP_LOCALE:-es}
APP_FALLBACK_LOCALE=${APP_FALLBACK_LOCALE:-es}
LOG_CHANNEL=${LOG_CHANNEL:-stack}
LOG_LEVEL=${LOG_LEVEL:-debug}
DB_CONNECTION=${DB_CONNECTION:-mysql}
DB_HOST=${DB_HOST:-127.0.0.1}
DB_PORT=${DB_PORT:-3306}
DB_DATABASE=${DB_DATABASE:-laravel}
DB_USERNAME=${DB_USERNAME:-root}
DB_PASSWORD='${DB_PASSWORD}'
SESSION_DRIVER=${SESSION_DRIVER:-file}
SESSION_LIFETIME=${SESSION_LIFETIME:-120}
SESSION_ENCRYPT=${SESSION_ENCRYPT:-false}
SESSION_PATH=${SESSION_PATH:-/}
SESSION_DOMAIN=${SESSION_DOMAIN:-null}
BROADCAST_CONNECTION=${BROADCAST_CONNECTION:-log}
FILESYSTEM_DISK=${FILESYSTEM_DISK:-local}
QUEUE_CONNECTION=${QUEUE_CONNECTION:-sync}
CACHE_STORE=${CACHE_STORE:-database}
TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
TELEGRAM_WEBHOOK_URL=${TELEGRAM_WEBHOOK_URL}
BCRYPT_ROUNDS=${BCRYPT_ROUNDS:-12}
EOF
# Intentar mover el temporal al destino final
if cp /tmp/.env.tmp /var/www/html/.env 2>/dev/null; then
# Si pudimos copiarlo, aplicamos permisos
chown laravel:laravel /var/www/html/.env
chmod 640 /var/www/html/.env
# Generar APP_KEY si falta (solo si es escribible)
if [ -z "$APP_KEY" ] || [ "$APP_KEY" == "" ]; then
echo "APP_KEY no detectada, generando una nueva..."
NEW_KEY=$(php /var/www/html/artisan key:generate --show --no-ansi)
sed -i "s|APP_KEY=|APP_KEY=$NEW_KEY|g" /var/www/html/.env
export APP_KEY=$NEW_KEY
fi
echo "✅ Archivo .env sincronizado correctamente."
else
echo "⚠️ ADVERTENCIA: No se pudo escribir en /var/www/html/.env"
echo " Probablemente esté montado como volumen de solo lectura (:ro)."
echo " Se usarán los valores del archivo montado externamente."
fi
rm -f /tmp/.env.tmp
# ===== LIMPIAR CACHE =====
echo ">> Limpiando cache..."
php /var/www/html/artisan view:clear 2>/dev/null || true
php /var/www/html/artisan config:clear 2>/dev/null || true
php /var/www/html/artisan cache:clear 2>/dev/null || true
php /var/www/html/artisan route:clear 2>/dev/null || true
echo ">> Cacheando configuración..."
php /var/www/html/artisan config:cache 2>&1 || true
# ===== VERIFICAR =====
php /var/www/html/artisan about 2>&1 | head -10 || true
echo "========================================"
echo " Iniciando servicios..."
echo "========================================"
php-fpm &
nginx -g "daemon off;"