Spaces:
Sleeping
Sleeping
FROM python:3.9-slim | |
WORKDIR /app | |
# Install system dependencies | |
RUN apt-get update && apt-get install -y \ | |
curl \ | |
procps \ | |
pkg-config \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Create streamlit config directory | |
RUN mkdir -p /app/.streamlit | |
# Create Streamlit config file | |
RUN echo "\ | |
[server]\n\ | |
headless = true\n\ | |
port = 8501\n\ | |
address = \"0.0.0.0\"\n\ | |
enableCORS = false\n\ | |
enableXsrfProtection = false\n\ | |
\n\ | |
[global]\n\ | |
disableWatchdogWarning = true\n\ | |
suppressDeprecationWarnings = true\n\ | |
\n\ | |
[browser]\n\ | |
gatherUsageStats = false\n\ | |
" > /app/.streamlit/config.toml | |
# Set environment variables | |
ENV STREAMLIT_CONFIG_DIR=/app/.streamlit | |
ENV STREAMLIT_SERVER_HEADLESS=true | |
ENV STREAMLIT_SERVER_PORT=8501 | |
ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0 | |
ENV STREAMLIT_GLOBAL_DISABLE_WATCHDOG_WARNING=true | |
ENV STREAMLIT_BROWSER_GATHER_USAGE_STATS=false | |
ENV PYTHONUNBUFFERED=1 | |
# Copy requirements first for better caching | |
COPY requirements.txt ./ | |
# Install Python dependencies | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Copy application files | |
COPY app.py ./ | |
COPY api.py ./ | |
COPY main.py ./ | |
COPY start.py ./ | |
# Create a non-root user for security | |
RUN useradd -m -u 1000 appuser && \ | |
chown -R appuser:appuser /app | |
USER appuser | |
# Expose ports | |
EXPOSE 8501 7861 | |
# Add healthcheck for Streamlit | |
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ | |
CMD curl -f http://localhost:8501/_stcore/health || exit 1 | |
# Use start.py as entrypoint | |
CMD ["python3", "start.py"] |