Files
web-inspector/.claude/skills/deployment-standards.md
jungwoo choi c37cda5b13 Initial commit: 프로젝트 초기 구성
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 16:10:57 +09:00

3.3 KiB

Docker 배포 규칙 (Deployment Standards)

Docker 배포 표준입니다.

Dockerfile 패턴

Python 마이크로서비스 (Worker)

FROM python:3.11-slim

WORKDIR /app

# 필요한 시스템 패키지 설치 (git은 공통 라이브러리 설치에 필요)
RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*

# 의존성 설치 (공통 라이브러리 포함 시)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt && \
    pip install --no-cache-dir git+http://gitea.yakenator.io/yakenator/{공통라이브러리}.git

# 애플리케이션 코드 복사
COPY *.py .

# 워커 실행
CMD ["python", "worker.py"]

Python API 서비스

FROM python:3.11-slim

WORKDIR /app

# curl은 healthcheck에 필요
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY app/ ./app/

EXPOSE 8000

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

docker-compose.yml 패턴

서비스 구조

services:
  # ===================
  # Infrastructure (독립 포트 사용)
  # ===================
  mongodb:
    image: mongo:7.0
    container_name: {프로젝트}-mongodb
    restart: unless-stopped
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER:-admin}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD:-password123}
    ports:
      - "{호스트포트}:27017"  # 호스트 포트는 충돌 방지를 위해 변경
    volumes:
      - {프로젝트}_mongodb_data:/data/db
    networks:
      - {프로젝트}-network
    healthcheck:
      test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
      interval: 30s
      timeout: 10s
      retries: 3

Worker 서비스 패턴

  {서비스명}:
    build:
      context: ./repos/{서비스명}
      dockerfile: Dockerfile
    container_name: {프로젝트}-{서비스명}
    restart: unless-stopped
    environment:
      - REDIS_URL=redis://redis:6379
      - MONGODB_URL=mongodb://${MONGO_USER}:${MONGO_PASSWORD}@mongodb:27017/
      - DB_NAME={데이터베이스명}
      - TARGET_COLLECTION={컬렉션명}
    depends_on:
      redis:
        condition: service_healthy
      mongodb:
        condition: service_healthy
    networks:
      - {프로젝트}-network

컨테이너 네이밍 규칙

  • 컨테이너명: {프로젝트}-{서비스명}
  • 볼륨명: {프로젝트}_{데이터유형}_data
  • 네트워크: {프로젝트}-network

환경 변수 관리

  • .env 파일로 민감 정보 관리
  • docker-compose.yml에서 ${VAR:-default} 형태로 기본값 제공
  • 공통 변수: MONGO_USER, MONGO_PASSWORD, REDIS_URL, JWT_SECRET_KEY

헬스체크 패턴

Redis

healthcheck:
  test: ["CMD", "redis-cli", "ping"]
  interval: 30s
  timeout: 10s
  retries: 3

MongoDB

healthcheck:
  test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
  interval: 30s
  timeout: 10s
  retries: 3

FastAPI 서비스

healthcheck:
  test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
  interval: 30s
  timeout: 10s
  retries: 3

참고 리포지토리