-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile.fastapi
More file actions
88 lines (69 loc) · 3.33 KB
/
Dockerfile.fastapi
File metadata and controls
88 lines (69 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -----------------------------------------------------------
# 1. Builder Stage: 의존성 설치 및 모델 다운로드
# -----------------------------------------------------------
FROM python:3.11-slim AS builder
WORKDIR /app
# 빌드 도구 설치
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
libeigen3-dev \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --user --no-cache-dir -r requirements.txt
RUN pip install --user pybind11
# [핵심] Faster-Whisper 모델 미리 다운로드 (Pre-baking)
# PATH를 설정하여 설치된 라이브러리 인식
ENV PATH=/root/.local/bin:$PATH
# 모델 저장할 임시 디렉토리 생성
RUN mkdir -p /model_cache
# Python 스크립트로 모델 다운로드 실행
# 주의: 사용하는 모델 크기('base', 'medium' 등)를 여기에 맞춰주세요.
# 현재 'base'로 설정되어 있습니다. 필요시 'medium' 등으로 변경하세요.
RUN python -c "from faster_whisper import download_model; download_model('base', output_dir='/model_cache')"
# [NEW] C++ 엔진 소스 복사 및 컴파일
# transit-routing 폴더 전체를 복사하여 setup.py와 cpp_src를 가져옴
COPY transit-routing/ /app/transit-routing/
# 작업 디렉토리 변경 후 C++ 모듈 빌드 & 설치
WORKDIR /app/transit-routing
# --user 옵션으로 /root/.local에 설치되도록 함 (나중에 Final Stage로 복사됨)
# C++ 모듈 컴파일 및 검증
RUN pip install --user . && \
python -c "import pathfinding_cpp; print('✓ C++ module loaded successfully')" && \
python -c "from pathfinding_cpp import McRaptorEngine, DataContainer; print('✓ C++ classes imported successfully')"
# -----------------------------------------------------------
# 2. Final Stage: 실행 이미지 생성
# -----------------------------------------------------------
FROM python:3.11-slim
WORKDIR /app
# [필수] 런타임에 필요한 FFmpeg 설치 (Builder에서 복사되지 않음)
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*
# Builder에서 설치한 Python 패키지 복사
COPY --from=builder /root/.local /root/.local
# [핵심] Builder에서 다운로드한 모델 파일 복사
# 호스트 볼륨 마운트 없이도 이미지가 모델을 내장하게 됨
COPY --from=builder /model_cache /root/.cache/huggingface
# 환경 변수 설정
ENV PATH=/root/.local/bin:$PATH
# 앱이 이 경로에서 모델을 찾도록 설정 (config.py에서 이 변수 참조 필요)
ENV WHISPER_MODEL_DIR=/root/.cache/huggingface
# Python 버퍼링 비활성화 (로그 즉시 출력)
ENV PYTHONUNBUFFERED=1
ENV USE_CPP_ENGINE=true
# 소스 코드 복사
COPY transit-routing/app/ ./app/
EXPOSE 8001
# Healthcheck (시간 넉넉하게 조정)
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8001/health').read()" || exit 1
# [핵심] Gunicorn 실행 (타임아웃 120초 적용)
# workers=1: C++ 엔진 도입 및 레플리카 확장을 위해 컨테이너 당 워커를 1개로 줄임
CMD ["gunicorn", "app.main:app", \
"--workers", "1", \
"--worker-class", "uvicorn.workers.UvicornWorker", \
"--bind", "0.0.0.0:8001", \
"--timeout", "300", \
"--keep-alive", "120"]