wing-ops/prediction/image/Dockerfile.cpu

113 lines
4.7 KiB
Docker

# ==============================================================================
# wing-image-analysis — 드론 영상 유류 분석 FastAPI 서버 (CPU 전용)
#
# Base: python:3.9-slim + PyTorch 1.9.0 CPU 빌드
# (mmsegmentation 0.25.0 / mmcv-full 1.4.3 호환 환경)
# python:3.9 필수 — numpy 1.26.4, geopandas 0.14.4가 Python >=3.9 요구
# GPU: 불필요 (CPU 추론)
# Port: 5001
# ==============================================================================
FROM python:3.9-slim
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
DEVICE=cpu
WORKDIR /app
# ------------------------------------------------------------------------------
# 시스템 패키지: GDAL / PROJ / GEOS (rasterio, geopandas 빌드 의존성)
# libspatialindex-dev: geopandas 공간 인덱스
# opencv-contrib-python-headless 런타임 SO 의존성 (python:3.9-slim에 미포함):
# libgl1 — libGL.so.1
# libglib2.0-0 — libgthread-2.0.so.0, libgobject-2.0.so.0, libglib-2.0.so.0
# libsm6 — libSM.so.6
# libxext6 — libXext.so.6
# libxrender1 — libXrender.so.1
# libgomp1 — libgomp.so.1 (OpenMP, numpy/opencv 병렬 처리)
# ------------------------------------------------------------------------------
RUN apt-get update && apt-get install -y --no-install-recommends \
gdal-bin \
libgdal-dev \
libproj-dev \
libgeos-dev \
libspatialindex-dev \
libgl1 \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender1 \
libgomp1 \
gcc \
g++ \
git \
&& rm -rf /var/lib/apt/lists/*
# rasterio는 GDAL 헤더 버전을 맞춰 빌드해야 한다
ENV GDAL_VERSION=3.4.1
# ------------------------------------------------------------------------------
# GDAL Python 바인딩 (osgeo 모듈) — 시스템 GDAL 버전과 일치해야 한다
# python:3.9-slim은 conda 없이 pip 환경이므로 명시적 설치 필요
# ------------------------------------------------------------------------------
RUN pip install --no-cache-dir GDAL=="$(gdal-config --version)"
# ------------------------------------------------------------------------------
# PyTorch 1.9.0 CPU 버전 설치
# (mmsegmentation 0.25.0 / mmcv-full 1.4.3 호환)
# ------------------------------------------------------------------------------
RUN pip install --no-cache-dir \
torch==1.9.0+cpu \
torchvision==0.10.0+cpu \
-f https://download.pytorch.org/whl/torch_stable.html
# ------------------------------------------------------------------------------
# mmcv-full 1.4.3 CPU 휠 (CUDA ops 없는 경량 빌드, 추론에 충분)
# ------------------------------------------------------------------------------
RUN pip install --no-cache-dir \
mmcv-full==1.4.3 \
-f https://download.openmmlab.com/mmcv/dist/cpu/torch1.9.0/index.html
# ------------------------------------------------------------------------------
# Python 의존성 설치
# ------------------------------------------------------------------------------
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# ------------------------------------------------------------------------------
# 로컬 mmsegmentation 설치 (mx15hdi/Detect/mmsegmentation/)
# 번들 소스를 먼저 복사한 뒤 editable 설치한다
# ------------------------------------------------------------------------------
COPY mx15hdi/Detect/mmsegmentation/ /tmp/mmsegmentation/
RUN pip install --no-cache-dir -e /tmp/mmsegmentation/
# ------------------------------------------------------------------------------
# 소스 코드 전체 복사
# 대용량 데이터 디렉토리(Original_Images, result 등)는
# docker-compose.cpu.yml의 볼륨 마운트로 외부에서 주입된다
# ------------------------------------------------------------------------------
COPY . .
# ------------------------------------------------------------------------------
# .dockerignore로 제외된 런타임 출력 디렉토리를 빈 폴더로 생성
# (볼륨 마운트 전에도 경로가 존재해야 한다)
# ------------------------------------------------------------------------------
RUN mkdir -p \
/app/stitch \
/app/mx15hdi/Detect/Mask_result \
/app/mx15hdi/Detect/result \
/app/mx15hdi/Georeference/Mask_Tif \
/app/mx15hdi/Georeference/Tif \
/app/mx15hdi/Metadata/CSV \
/app/mx15hdi/Metadata/Image/Original_Images \
/app/mx15hdi/Polygon/Shp
# ------------------------------------------------------------------------------
# 런타임 설정
# ------------------------------------------------------------------------------
EXPOSE 5001
# workers=1: 모델을 프로세스 하나에서만 로드 (메모리 공유 불가)
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "5001", "--workers", "1"]