FROM python:3.9 # Setup RUN apt-get update && apt-get install -y curl wget netcat-traditional && \ curl -fsSL https://ollama.com/install.sh | sh && \ useradd -m -u 1000 user WORKDIR /app # Install dependencies COPY --chown=user requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy files COPY --chown=user . . # Create files COPY --chown=user Modelfile /app/Modelfile # Start script RUN echo '#!/bin/bash ulimit -v unlimited ollama serve --verbose & timeout=60 until nc -z localhost 11434 || [ $timeout -le 0 ]; do sleep 1 ((timeout--)) done cd /app ollama create llama3.2:1b-papalia -f Modelfile exec uvicorn app:app --host 0.0.0.0 --port 7860 --workers 1 --limit-concurrency 1' > /app/start.sh RUN chmod +x /app/start.sh USER user ENV PATH="/home/user/.local/bin:$PATH" \ MALLOC_ARENA_MAX=2 HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ CMD curl -f http://localhost:7860/health || exit 1 CMD ["/app/start.sh"]