# 1. 우분투 24.04 기반 이미지 사용 (GLIBC 2.39 포함, Python 3.12 내장) FROM ubuntu:24.04 # 2. 필요한 기본 패키지 설치 (빌드 도구, 기타 필수 라이브러리 / 파이썬은 이미 내장됨) RUN apt-get update && apt-get upgrade -y && \ apt-get install -y \ software-properties-common \ build-essential \ gcc g++ cmake \ python3-venv python3-dev python3-pip \ curl git # 3. 가상환경 생성 및 pip, setuptools, wheel 업그레이드 RUN python3 -m venv /opt/venv && \ /opt/venv/bin/pip install --upgrade pip setuptools wheel # 4. 환경 변수 설정 (가상환경 활성화) ENV PATH="/opt/venv/bin:${PATH}" ENV HF_HOME=/app/huggingface_cache # 5. 컨테이너 내부에 코드를 저장할 작업 폴더를 만듦 WORKDIR /app # 6. 보안을 위해 권한이 제한된 새로운 사용자(user)를 생성하고 소유권을 이전 RUN useradd -m -u 1010 user RUN chown -R user:user /app USER user # 7. requirements.txt 파일과 wheel 파일을 복사 COPY ./requirements.txt requirements.txt # COPY ./llama_cpp_python-0.3.11-cp39-cp39-linux_x86_64.whl . COPY ./llama_cpp_python-0.3.11-cp312-cp312-linux_x86_64.whl . # 8. llama-cpp-python을 wheel 파일로 설치 후 나머지 라이브러리 설치 (가상환경 내 pip 사용) # RUN pip install --no-cache-dir ./llama_cpp_python-0.3.11-cp39-cp39-linux_x86_64.whl RUN pip install --no-cache-dir ./llama_cpp_python-0.3.11-cp312-cp312-linux_x86_64.whl RUN pip install --no-cache-dir --upgrade -r requirements.txt # 9. 나머지 모든 소스 코드를 작업 폴더에 복사 COPY . /app # 10. 모든 준비가 끝나면, 서버를 실행 CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]