wing-ops/prediction/image/Dockerfile

85 lines
3.5 KiB
Docker

# ==============================================================================
# wing-image-analysis — 드론 영상 유류 분석 FastAPI 서버
#
# Base: PyTorch 1.9.1 + CUDA 11.1 + cuDNN 8
# (mmsegmentation 0.25.0 / mmcv-full 1.4.3 호환 환경)
# GPU: NVIDIA GPU 필수 (MMSegmentation 추론)
# Port: 5001
# ==============================================================================
FROM pytorch/pytorch:1.9.1-cuda11.1-cudnn8-devel
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR /app
# ------------------------------------------------------------------------------
# 시스템 패키지: GDAL / PROJ / GEOS (rasterio, geopandas 빌드 의존성)
# libpq-dev: psycopg2-binary 런타임 의존성
# libspatialindex-dev: geopandas 공간 인덱스
# ------------------------------------------------------------------------------
RUN apt-get update && apt-get install -y --no-install-recommends \
gdal-bin \
libgdal-dev \
libproj-dev \
libgeos-dev \
libspatialindex-dev \
gcc \
g++ \
git \
&& rm -rf /var/lib/apt/lists/*
# rasterio는 GDAL 헤더 버전을 맞춰 빌드해야 한다
ENV GDAL_VERSION=3.4.1
# ------------------------------------------------------------------------------
# mmcv-full 1.4.3 — CUDA 11.1 + PyTorch 1.9.0 pre-built 휠
# (소스 컴파일 없이 수 초 내 설치)
# ------------------------------------------------------------------------------
RUN pip install --no-cache-dir \
mmcv-full==1.4.3 \
-f https://download.openmmlab.com/mmcv/dist/cu111/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.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: GPU 모델을 프로세스 하나에서만 로드 (메모리 공유 불가)
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "5001", "--workers", "1"]