Spaces:
Sleeping
Sleeping
File size: 1,331 Bytes
a1a2086 |
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 49 50 51 52 53 54 55 56 |
# Use a base image with Python
FROM python:3.10
# Set the working directory
WORKDIR /app
# Create a non-root user
RUN useradd -m -u 1000 appuser
# Install system dependencies
RUN apt update && apt install -y curl && \
curl -fsSL https://ollama.ai/install.sh | sh
# Create .ollama directory and set permissions
RUN mkdir -p /home/appuser/.ollama && \
chown -R appuser:appuser /home/appuser/.ollama
# Install Python dependencies
COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Copy application files
COPY . .
# Create a more robust startup script
RUN echo '#!/bin/bash\n\
echo "Starting Ollama server..."\n\
ollama serve &\n\
\n\
# Wait for Ollama server to be ready\n\
until curl -s http://localhost:11434/api/tags >/dev/null; do\n\
echo "Waiting for Ollama server to be ready..."\n\
sleep 2\n\
done\n\
\n\
echo "Pulling Mistral model..."\n\
ollama pull mistral\n\
\n\
echo "Starting FastAPI application..."\n\
uvicorn main:app --host 0.0.0.0 --port 7860' > start.sh && \
chmod +x start.sh
# Set ownership of the application files
RUN chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose the port FastAPI will run on
EXPOSE 7860
# Set the HOME environment variable
ENV HOME=/home/appuser
# Run the startup script
CMD ["./start.sh"] |