-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
41 lines (30 loc) · 1.22 KB
/
Copy pathDockerfile
File metadata and controls
41 lines (30 loc) · 1.22 KB
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
# Use the official Python image
FROM python:3.11-slim
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# Set up user 1000 (Hugging Face Spaces requirement)
RUN useradd -m -u 1000 user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME/app
# Copy requirements first for Docker layer caching
COPY --chown=user:user requirements.txt $HOME/app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Copy application files
COPY --chown=user:user . $HOME/app
# Pre-build ML model artifacts inside the image
RUN python scripts/build_artifacts.py
# Ensure user owns all files in home directory and has full write permissions
RUN chown -R user:user /home/user && chmod -R 777 /home/user
# Switch to non-root user
USER user
# Expose port 7860 (Hugging Face Spaces default port)
EXPOSE 7860
# Healthcheck
HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health || exit 1
# Command to run Streamlit on port 7860 with iframe compatibility
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.enableCORS=false", "--server.enableXsrfProtection=false"]