From e08f3b07650df8ae7acd34f682fdaba34883b9b2 Mon Sep 17 00:00:00 2001 From: tkrmagid Date: Wed, 20 May 2026 23:42:58 +0900 Subject: [PATCH] =?UTF-8?q?fix(backend):=20Dockerfile=20editable=20install?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0=20+=20PYTHONPATH?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 `pip install -e .` 두 줄은 두 가지 이유로 실패: 1. `app/` 가 COPY 되기 전 단계라 setuptools packages.find 결과가 비어 editable 빌드가 무의미. 2. Ubuntu 22.04 의 기본 pip 가 PEP 660 build_editable hook 을 요구하지만, build isolation 환경의 setuptools 가 노출 안 함 ("build backend is missing the 'build_editable' hook"). 수정: - editable install 자체를 제거. 런타임은 PYTHONPATH=/app 으로 `app.*` import 가 동작하므로 프로젝트를 wheel 로 설치할 필요 없음. - 의존성은 tomllib 로 pyproject.toml 에서 직접 추출해 단일 `pip install -r` 로 설치. ML 휠 (chronos/lgbm/transformers ...) 레이어 캐싱이 pyproject.toml 단위로 유지됨 → app 코드 변경시 재빌드 회피. - COPY app ./app 은 deps 설치 뒤로 유지 (캐시 분리). --- backend/Dockerfile | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 06cf30c..dc7bca0 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -7,6 +7,7 @@ ENV DEBIAN_FRONTEND=noninteractive \ PYTHONDONTWRITEBYTECODE=1 \ PIP_NO_CACHE_DIR=1 \ PIP_DISABLE_PIP_VERSION_CHECK=1 \ + PYTHONPATH=/app \ TZ=Asia/Seoul RUN apt-get update && apt-get install -y --no-install-recommends \ @@ -20,11 +21,20 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ WORKDIR /app COPY pyproject.toml ./ + # Install PyTorch (CUDA 12.1 wheels) first so the rest of deps don't downgrade it. RUN pip install --extra-index-url https://download.pytorch.org/whl/cu121 \ torch==2.3.1 torchvision==0.18.1 -RUN pip install --no-deps -e . || true -RUN pip install -e . + +# Install runtime deps from pyproject.toml WITHOUT installing the project itself. +# - 이전 `pip install -e .` 은 app/ 가 아직 COPY 되기 전이라 packages.find 결과가 비고, +# ubuntu 22.04 기본 pip 의 PEP 660 editable hook 과 충돌해 실패했음. +# - 런타임에는 PYTHONPATH=/app 으로 `app.*` 임포트가 동작하므로 프로젝트 설치 자체가 불필요. +# - deps 만 별도 레이어로 캐시 → 코드 변경 시 ML 휠 재빌드 회피. +RUN python -c "import tomllib; \ +deps = tomllib.load(open('pyproject.toml','rb'))['project']['dependencies']; \ +open('/tmp/reqs.txt','w').write('\n'.join(deps))" \ + && pip install -r /tmp/reqs.txt COPY app ./app