FROM python:3.9-slim # 1. Thiết lập thư mục làm việc WORKDIR /app # 2. Cài các gói hệ thống cần thiết, tạo user và cache directories có quyền ghi RUN apt-get update && apt-get install -y \ build-essential \ curl \ git \ ffmpeg \ libsndfile1 \ && rm -rf /var/lib/apt/lists/* \ && useradd -m user \ && mkdir -p /cache/hf_cache /cache/huggingface /cache/.cache /cache/.streamlit \ && chown -R user:user /cache # 3. Copy và cài dependencies Python (chạy với root để scripts streamlit được trong PATH) COPY requirements.txt ./ RUN pip install --upgrade pip && \ pip install -r requirements.txt # 4. Copy source code và gán owner COPY --chown=user:user src/ ./src/ # 5. Chuyển sang user không phải root USER user # 6. Thiết lập biến môi trường ENV TRANSFORMERS_CACHE=/cache/hf_cache ENV HF_HOME=/cache/hf_cache ENV XDG_CACHE_HOME=/cache/.cache ENV STREAMLIT_CONFIG_DIR=/cache/.streamlit ENV TOKENIZERS_PARALLELISM=false # 7. Mở port và healthcheck EXPOSE 8501 HEALTHCHECK --interval=30s --timeout=5s \ CMD curl --fail http://localhost:8501/_stcore/health || exit 1 # 8. Mặc định chạy Streamlit ENTRYPOINT ["streamlit", "run"] CMD ["src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableCORS=false", "--server.enableXsrfProtection=false"]