Spaces:
Sleeping
Sleeping
| FROM ubuntu:24.04 | |
| # Install all dependencies in one layer | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| python3 python3-pip python3-dev \ | |
| curl wget bash ca-certificates \ | |
| zstd \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Install Ollama | |
| RUN curl -fsSL https://ollama.ai/install.sh | sh | |
| # Set working directory | |
| WORKDIR /app | |
| # Copy and install Python dependencies | |
| COPY requirements.txt . | |
| RUN pip3 install --break-system-packages --no-cache-dir -r requirements.txt | |
| # Copy application code | |
| COPY app.py . | |
| # Create startup script | |
| RUN cat > /app/entrypoint.sh << 'SCRIPT' | |
| #!/bin/bash | |
| set -e | |
| echo "π Starting Ollama server..." | |
| /usr/bin/ollama serve > /tmp/ollama.log 2>&1 & | |
| OLLAMA_PID=$! | |
| echo "β³ Waiting for Ollama to initialize..." | |
| sleep 5 | |
| echo "π₯ Pulling Mistral model (this may take a few minutes on first run)..." | |
| timeout 600 /usr/bin/ollama pull mistral || echo "β οΈ Model pull timeout - will download on first request" | |
| echo "π Starting FastAPI server..." | |
| exec python3 /app/app.py | |
| SCRIPT | |
| RUN chmod +x /app/entrypoint.sh | |
| # Expose ports | |
| EXPOSE 7860 11434 | |
| # Environment variables | |
| ENV OLLAMA_HOST=0.0.0.0:11434 | |
| ENV PORT=7860 | |
| ENV PYTHONUNBUFFERED=1 | |
| # Run entrypoint | |
| ENTRYPOINT [] | |
| CMD ["/app/entrypoint.sh"] |