# Use Python 3.9 slim as the base image FROM python:3.9-slim # Set working directory WORKDIR /app # Install necessary dependencies for OpenCV, PyTorch, and other utilities RUN apt-get update && apt-get install -y \ build-essential \ curl \ software-properties-common \ git \ libgl1-mesa-glx \ libglib2.0-0 \ && rm -rf /var/lib/apt/lists/* # Create a non-root user to avoid permission issues RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app # Switch to non-root user USER appuser # Set environment variables for Streamlit and Hugging Face ENV STREAMLIT_CONFIG_DIR=/app/.streamlit ENV HF_HOME=/app/.cache/huggingface ENV STREAMLIT_SERVER_FILE_WATCHER_TYPE=none ENV PATH=/home/appuser/.local/bin:$PATH # Create necessary directories with correct permissions RUN mkdir -p /app/.streamlit /app/.cache/huggingface RUN chmod -R 777 /app/.streamlit /app/.cache # Copy the requirements and install them COPY --chown=appuser:appuser requirements.txt ./ RUN pip3 install --user --no-cache-dir -r requirements.txt RUN pip3 install --user --no-cache-dir streamlit # Verify Streamlit installation RUN streamlit --version || { echo "Streamlit installation failed"; exit 1; } # Copy the source code and modules directory COPY --chown=appuser:appuser src/ ./src/ COPY --chown=appuser:appuser modules/ ./modules/ # Expose the port that Streamlit will run on EXPOSE 8501 # Health check to ensure the container is running properly HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1 # Set the entry point to run the Streamlit app ENTRYPOINT ["/home/appuser/.local/bin/streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]