incr/docker/production/start-app.sh

31 lines
No EOL
933 B
Bash

#!/bin/sh
# Copy public files to shared volume if needed
cp -r /var/www/html/public/. /var/www/html/public_shared/ 2>/dev/null || true
# Create .env file if it doesn't exist
if [ ! -f /var/www/html/.env ]; then
cp /var/www/html/.env.example /var/www/html/.env 2>/dev/null || touch /var/www/html/.env
fi
# Wait for database to be ready
echo "Waiting for database..."
until mysql -h"${DB_HOST:-db}" -u"${DB_USERNAME:-incr_user}" -p"${DB_PASSWORD}" -e "SELECT 1" >/dev/null 2>&1; do
echo "Database not ready, waiting..."
sleep 2
done
echo "Database is ready!"
# Generate app key only if not already set
if ! grep -q "APP_KEY=base64:" /var/www/html/.env 2>/dev/null; then
php artisan key:generate --force
fi
# Laravel optimizations
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan migrate --force
# Start supervisor to manage nginx and php-fpm
supervisord -c /etc/supervisord.conf