Spaces:
Runtime error
Runtime error
File size: 1,383 Bytes
85aa5a8 a9d55c8 85aa5a8 a9d55c8 85aa5a8 a9d55c8 85aa5a8 a9d55c8 85aa5a8 a9d55c8 85aa5a8 a9d55c8 85aa5a8 a9d55c8 85aa5a8 a9d55c8 85aa5a8 a9d55c8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
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"] |