Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +29 -7
Dockerfile
CHANGED
|
@@ -1,21 +1,43 @@
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
|
|
| 5 |
RUN apt-get update && apt-get install -y \
|
| 6 |
build-essential \
|
| 7 |
curl \
|
| 8 |
-
software-properties-common \
|
| 9 |
git \
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
|
|
|
| 12 |
COPY requirements.txt ./
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
+
# 1. Thiết lập thư mục làm việc
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
+
# 2. Cài các gói hệ thống cần thiết, tạo user và cache directories có quyền ghi
|
| 7 |
RUN apt-get update && apt-get install -y \
|
| 8 |
build-essential \
|
| 9 |
curl \
|
|
|
|
| 10 |
git \
|
| 11 |
+
ffmpeg \
|
| 12 |
+
libsndfile1 \
|
| 13 |
+
&& rm -rf /var/lib/apt/lists/* \
|
| 14 |
+
&& useradd -m user \
|
| 15 |
+
&& mkdir -p /cache/hf_cache /cache/huggingface /cache/.cache /cache/.streamlit \
|
| 16 |
+
&& chown -R user:user /cache
|
| 17 |
|
| 18 |
+
# 3. Copy và cài dependencies Python (chạy với root để scripts streamlit được trong PATH)
|
| 19 |
COPY requirements.txt ./
|
| 20 |
+
RUN pip install --upgrade pip && \
|
| 21 |
+
pip install -r requirements.txt
|
| 22 |
|
| 23 |
+
# 4. Copy source code và gán owner
|
| 24 |
+
COPY --chown=user:user src/ ./src/
|
| 25 |
|
| 26 |
+
# 5. Chuyển sang user không phải root
|
| 27 |
+
USER user
|
| 28 |
+
|
| 29 |
+
# 6. Thiết lập biến môi trường
|
| 30 |
+
ENV TRANSFORMERS_CACHE=/cache/hf_cache
|
| 31 |
+
ENV HF_HOME=/cache/hf_cache
|
| 32 |
+
ENV XDG_CACHE_HOME=/cache/.cache
|
| 33 |
+
ENV STREAMLIT_CONFIG_DIR=/cache/.streamlit
|
| 34 |
+
ENV TOKENIZERS_PARALLELISM=false
|
| 35 |
|
| 36 |
+
# 7. Mở port và healthcheck
|
| 37 |
+
EXPOSE 8501
|
| 38 |
+
HEALTHCHECK --interval=30s --timeout=5s \
|
| 39 |
+
CMD curl --fail http://localhost:8501/_stcore/health || exit 1
|
| 40 |
|
| 41 |
+
# 8. Mặc định chạy Streamlit
|
| 42 |
+
ENTRYPOINT ["streamlit", "run"]
|
| 43 |
+
CMD ["src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableCORS=false", "--server.enableXsrfProtection=false"]
|