#!/usr/bin/env bash set -e REPO_URL=${REPO_URL} BRANCH=${BRANCH:-main} TARGET_DIR=/var/www/html # 1) 初次 clone 或拉取 if [ -z "$(ls -A "$TARGET_DIR")" ]; then echo "[entrypoint] Cloning $BRANCH from $REPO_URL ..." git clone --branch "$BRANCH" "$REPO_URL" "$TARGET_DIR" else echo "[entrypoint] Repository already present, skipping first clone." fi cd "$TARGET_DIR" # 2) Laravel 基礎安裝 composer install --no-interaction --prefer-dist [ -f .env ] || cp .env.example .env update_env() { local k=$1 v=$2; grep -q "^$k=" .env && sed -i "s|^$k=.*|$k=$v|" .env || echo "$k=$v" >> .env; } update_env APP_NAME "$APP_NAME" update_env APP_URL "${APP_URL%/}" update_env DB_HOST "$DB_HOST" update_env DB_PORT "$DB_PORT" update_env DB_DATABASE "$DB_DATABASE" update_env DB_USERNAME "$DB_USERNAME" update_env DB_PASSWORD "$DB_PASSWORD" php artisan key:generate --force php artisan migrate --force [ -d node_modules ] || npm install npm run build chown -R www-data:www-data storage bootstrap/cache chmod -R 775 storage bootstrap/cache echo "[entrypoint] Starting supervisord ..." supervisord -c /etc/supervisor/conf.d/supervisord.conf & exec "$@"