Files
web-page-backend/scripts/deploy-nas.sh
gahusb b70caddff1 feat(image-lab): Dockerfile + compose entry + scripts 6위치 + nginx 차단
Task 5 of Video Studio backend plan. Wires image-lab Python code (T1-T4)
into NAS Docker infrastructure on port 18802.

- image-lab/Dockerfile (python:3.12-slim + uvicorn)
- image-lab/requirements.txt (fastapi, redis, httpx)
- image-lab/env.example (INTERNAL_API_KEY, IMAGE_DATA_DIR, REDIS_URL, CORS)
- docker-compose.yml: image-lab service block (port 18802, redis depends_on,
  healthcheck, volume ${RUNTIME_PATH}/image-data:/app/data) + frontend
  depends_on entry
- scripts/deploy-nas.sh: SERVICES += image-lab
- scripts/deploy.sh: BUILD_TARGETS/CONTAINER_NAMES/HEALTH_ENDPOINTS += image-lab,
  DATA_DIRS += image
- nginx/default.conf: /api/internal/image/ 3-layer block (IP allowlist +
  deny all + X-Internal-Key forward) mirroring /api/internal/video/

Plan-B-Video lesson: 6-location registration enforced per
feedback_nas_deploy_paths.md rule 3 to avoid 'transferring dockerfile: 2B'
deploy failure.

Tests: image-lab pytest 11 passed (no regression).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 11:46:45 +09:00

71 lines
2.2 KiB
Bash

#!/bin/bash
set -euo pipefail
# ── 서비스 목록 (한 곳에서만 관리) ──
SERVICES="lotto travel-proxy deployer stock music-lab insta-lab realestate-lab agent-office personal packs-lab video-lab image-lab nginx scripts"
# 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:-}"
if [ -z "$DST" ]; then
echo "Error: RUNTIME_PATH is not set. Please create .env file with RUNTIME_PATH defined."
exit 1
fi
fi
echo "Source: $SRC"
echo "Target: $DST"
cd "$SRC"
# 레포에서 운영으로 반영할 항목들만 복사/동기화
RSYNC_OPTS="-rl --delete --no-owner --no-group --exclude .git --exclude __pycache__ --exclude *.pyc --exclude data/"
# 파일 권한 설정값 (numeric UID/GID 사용 — 컨테이너에 username 없을 수 있음)
DEPLOY_UID="${PUID:-1026}"
DEPLOY_GID="${PGID:-100}"
DEPLOY_MODE="755"
for dir in $SERVICES; do
# rsync 전 대상 디렉토리 권한 확보 (Docker root 소유 파일 대응)
if [ -d "$DST/$dir" ]; then
chmod -R u+rwX "$DST/$dir/" 2>/dev/null || true
fi
rsync $RSYNC_OPTS "$SRC/$dir/" "$DST/$dir/" || {
rc=$?
if [ $rc -ne 23 ]; then
echo "rsync failed for $dir with exit code $rc"
exit $rc
fi
}
done
# compose 파일만 동기화 (.env는 절대 동기화하지 않음 — 운영 시크릿 보호)
rsync -rl --no-owner --no-group "$SRC/docker-compose.yml" "$DST/docker-compose.yml" || {
rc=$?
if [ $rc -ne 23 ]; then
echo "rsync failed for docker-compose.yml with exit code $rc"
exit $rc
fi
}
# 파일 권한 설정 — 전체 런타임 디렉토리에 일괄 적용
echo "Setting ownership ${DEPLOY_UID}:${DEPLOY_GID} and mode ${DEPLOY_MODE} on $DST ..."
chown -R "${DEPLOY_UID}:${DEPLOY_GID}" "$DST" 2>/dev/null || true
chmod -R "$DEPLOY_MODE" "$DST" 2>/dev/null || true
echo "SYNC_OK"