Update startup.sh
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243#!/bin/bashecho "=== Starting Ollama Generate API ==="# Set HOME to /tmp to avoid permission issues with /.ollamaexport HOME=/tmp# Use /tmp to avoid any permission issuesexport OLLAMA_HOST=0.0.0.0:11434export OLLAMA_MODELS=/tmp/ollama/modelsexport OLLAMA_HOME=/tmp/ollamaexport OLLAMA_ORIGINS="*"# Create directoriesmkdir -p /tmp/ollama/modelsmkdir -p /tmp/.ollamaecho "✅ Created Ollama directories in /tmp"# Start Ollama serverecho "Starting Ollama server..."ollama serve &OLLAMA_PID=$!# Wait for server to startecho "Waiting for Ollama server..."sleep 10# Check if server is runningif curl -s http://localhost:11434/api/tags > /dev/null; thenecho "✅ Ollama server is running!"elseecho "❌ Ollama server failed to start"kill $OLLAMA_PID 2>/dev/null || trueexit 1fi# Pull tiny model in backgroundecho "Pulling TinyLlama model..."ollama pull tinyllama &# Start FastAPI appecho "Starting FastAPI application..."python3 app.py1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556# Use Ubuntu as base image for better Ollama compatibilityFROM ubuntu:22.04# Prevent interactive prompts during package installationENV DEBIAN_FRONTEND=noninteractive# Set working directoryWORKDIR /app# Install system dependenciesRUN apt-get update && apt-get install -y \curl \python3 \python3-pip \python3-venv \wget \ca-certificates \sudo \&& rm -rf /var/lib/apt/lists/*# Create and activate virtual environmentRUN python3 -m venv /opt/venvENV PATH="/opt/venv/bin:$PATH"# Install Python dependenciesCOPY requirements.txt .RUN pip install --no-cache-dir --upgrade pip && \pip install --no-cache-dir -r requirements.txt# Install OllamaRUN curl -fsSL https://ollama.ai/install.sh | sh# No need to create ollama directories - will use /tmp# Copy application filesCOPY app.py .COPY startup.sh .# Make startup script executableRUN chmod +x startup.sh# Set environment variables for Ollama (using /tmp for guaranteed write access)ENV HOME=/tmpENV OLLAMA_HOST=0.0.0.0:11434ENV OLLAMA_MODELS=/tmp/ollama/modelsENV OLLAMA_HOME=/tmp/ollama# Expose portsEXPOSE 7860 11434# Health checkHEALTHCHECK --interval=30s --timeout=30s --start-period=60s --retries=3 \CMD curl -f http://localhost:7860/health || exit 1# Start both Ollama server and FastAPI appCMD ["./startup.sh"]
startup.sh+56-43