LaravelPublisher/docker/entrypoint.sh

45 lines
1.2 KiB
Bash

#!/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 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
mkdir -p /var/www/logs
supervisord -c /etc/supervisor/conf.d/supervisord.conf &
php-fpm -D
envsubst '${NGINX_HOST} ${NGINX_PORT}' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf
exec nginx -g "daemon off;"