92 lines
2.6 KiB
Bash
92 lines
2.6 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
# ----- LOGGING FUNCTIONS -----
|
|
log_info() { echo -e "\033[1;34m[INFO]\033[0m $1"; }
|
|
log_warn() { echo -e "\033[1;33m[WARN]\033[0m $1"; }
|
|
log_error() { echo -e "\033[1;31m[ERROR]\033[0m $1"; }
|
|
|
|
# ----- START -----
|
|
log_info "Starting Laravel container setup"
|
|
|
|
init=false
|
|
|
|
# Initialize environment
|
|
if [ ! -f /config/.env ]; then
|
|
log_info "Creating .env from example"
|
|
cp .env.example .env
|
|
# Ensure APP_KEY exists
|
|
if ! grep -q "^APP_KEY=base64" .env; then
|
|
log_info "Generating application key"
|
|
php artisan key:generate
|
|
fi
|
|
cp .env /config/.env
|
|
init=true
|
|
else
|
|
log_info "Using existing /config/.env"
|
|
cp /config/.env .env
|
|
fi
|
|
|
|
# SQLite database initialization
|
|
if { grep -iq "^DB_CONNECTION=sqlite" .env && [ "$DB_CONNECTION" = "sqlite" ]; } || [ "$DEPLOY_ENV" = "sqlite" ]; then
|
|
if [ ! -f database/database.sqlite ]; then
|
|
log_info "Creating empty SQLite database"
|
|
touch database/database.sqlite
|
|
init=true
|
|
fi
|
|
fi
|
|
|
|
# Composer dependencies
|
|
if [ "$init" = "true" ] || [ "$(echo "$APP_DEBUG" | tr '[:upper:]' '[:lower:]')" = "true" ]; then
|
|
log_info "Initial setup nebo debug mód - instalace Composeru s dev závislostmi"
|
|
composer install --prefer-dist --optimize-autoloader
|
|
else
|
|
log_info "Produkční instalace - Composer bez dev závislostí"
|
|
composer install --prefer-dist --no-dev --optimize-autoloader
|
|
fi
|
|
|
|
# Check Laravel module dependencies
|
|
log_info "Checking Laravel module dependencies..."
|
|
if php artisan app:check-module-dependencies; then
|
|
log_info "All module dependencies satisfied"
|
|
else
|
|
log_error "Missing module dependencies - exiting"
|
|
if [ "$init" != "true" ] && [ "$(echo "$APP_DEBUG" | tr '[:upper:]' '[:lower:]')" != "true" ]; then
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Link storage and seed database if first init
|
|
if [ "$init" = true ]; then
|
|
log_info "Linking storage directory"
|
|
php artisan storage:link
|
|
fi
|
|
|
|
# Migrate database
|
|
log_info "Running database migrations"
|
|
php artisan migrate --force --no-interaction
|
|
|
|
# Clear Laravel caches
|
|
log_info "Clearing Laravel caches"
|
|
php artisan cache:clear
|
|
php artisan config:clear
|
|
php artisan route:clear
|
|
php artisan view:clear
|
|
|
|
if [ "$(echo "$APP_DEBUG" | tr '[:upper:]' '[:lower:]')" = "false" ]; then
|
|
php artisan config:cache
|
|
php artisan route:cache
|
|
php artisan view:cache
|
|
sed -ri -e 's!opcache.enable=1!opcache.enable=0!g' "${PHP_INI_DIR}/conf.d/opcache.ini"
|
|
fi
|
|
|
|
#supervisord
|
|
/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
|
|
|
|
#Start Socket Server
|
|
php artisan reverb:start --host=0.0.0.0 --port=8899 --no-interaction --debug &
|
|
|
|
# Start Apache
|
|
log_info "Starting Apache server"
|
|
exec apache2-foreground
|