File size: 1,121 Bytes
252420e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
# Stage 1 — Build stage (to install Python dependencies)
FROM python:3.10-slim AS builder

# Set environment vars
ENV VIRTUAL_ENV=/opt/venv
RUN python -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# System dependencies
RUN apt-get update && apt-get install -y \

    git \
    && rm -rf /var/lib/apt/lists/*

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \

    pip install --no-cache-dir -r requirements.txt

# Stage 2 — Final minimal image
FROM python:3.10-slim

# Add non-root user
RUN useradd -m appuser

# Copy venv from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

# Set working directory
WORKDIR /home/appuser/app

# Copy app files
COPY --chown=appuser:appuser . .

# Set user to non-root
USER appuser

# Streamlit config to run in HF Spaces
ENV STREAMLIT_SERVER_PORT=7860
ENV STREAMLIT_SERVER_ENABLECORS=false
ENV STREAMLIT_SERVER_HEADLESS=true

# Expose port (optional — Spaces handles this)
EXPOSE 7860

# Run Streamlit app
CMD ["streamlit", "run", "app.py"]