#!/bin/bash set -euo pipefail # 1. 자동 감지: Docker 컨테이너 내부인가? if [ -d "/repo" ] && [ -d "/runtime" ]; then echo "Detected Docker Container environment." SRC="/repo" DST="/runtime" else # 2. Host 환경: .env 로드 시도 if [ -f ".env" ]; then echo "Loading .env file..." set -a; source .env; set +a fi # 환경변수가 없으면 현재 디렉토리를 SRC로 SRC="${REPO_PATH:-$(pwd)}" DST="${RUNTIME_PATH:-/volume1/docker/webpage}" # 기본값 설정 if [ -z "$DST" ]; then echo "Error: RUNTIME_PATH is not set." exit 1 fi fi echo "Source: $SRC" echo "Target: $DST" git config --global --add safe.directory "$SRC" cd "$SRC" git fetch --all --prune git pull --ff-only # 릴리즈 백업(롤백용): 아래 5번과 연결 TAG="$(date +%Y%m%d-%H%M%S)" mkdir -p "$DST/.releases/$TAG" rsync -a --delete \ --exclude ".releases" \ "$DST/" "$DST/.releases/$TAG/" # 소스 → 운영 반영 (네가 이미 만든 deploy-nas.sh가 있으면 그걸 호출해도 됨) # 예: repo/scripts/deploy-nas.sh가 운영으로 복사/동기화하는 로직이라면: bash "$SRC/scripts/deploy-nas.sh" cd "$DST" docker-compose up -d --build backend travel-proxy frontend echo "DEPLOY_OK $TAG"