# Local AI Dockerfile with Ollama support FROM node:20-slim # Create non-root user for security RUN useradd -m -u 1000 user # Set working directory WORKDIR $HOME/app # Install system dependencies including curl for Ollama RUN apt-get update && apt-get install -y \ git \ curl \ wget \ ca-certificates \ && rm -rf /var/lib/apt/lists/* # Install Ollama (commented out for external deployment) # RUN curl -fsSL https://ollama.com/install.sh | sh # Copy package files first for better caching COPY --chown=user package*.json ./ COPY --chown=user backend/package*.json ./backend/ COPY --chown=user frontend/package*.json ./frontend/ # Install backend dependencies WORKDIR $HOME/app/backend RUN npm ci --only=production # Install frontend dependencies and build WORKDIR $HOME/app/frontend RUN npm ci COPY --chown=user frontend/ ./ RUN npm run build # Copy backend source code WORKDIR $HOME/app COPY --chown=user backend/ ./backend/ COPY --chown=user *.md ./ # Create production startup script for local AI RUN echo '#!/bin/bash\n\ cd $HOME/app/backend\n\ echo "🎓 Starting edi.chat Local AI Server..."\n\ echo "PORT: ${PORT:-7860}"\n\ echo "AI Configuration:"\n\ echo " USE_LOCAL_AI: ${USE_LOCAL_AI:-true}"\n\ echo " LOCAL_AI_URL: ${LOCAL_AI_URL:-http://host.docker.internal:11434}"\n\ echo " LOCAL_AI_MODEL: ${LOCAL_AI_MODEL:-llama3}"\n\ echo " DISABLE_ONLINE_AI: true"\n\ echo "Environment: ${NODE_ENV:-production}"\n\ echo ""\n\ echo "🤖 Checking Ollama connection..."\n\ curl -s ${LOCAL_AI_URL:-http://host.docker.internal:11434}/api/tags || echo "⚠️ Ollama not accessible at ${LOCAL_AI_URL:-http://host.docker.internal:11434}"\n\ echo ""\n\ \n\ # Serve frontend static files from backend\n\ cp -r ../frontend/build/* ./public/ 2>/dev/null || echo "No frontend build found, using fallback"\n\ \n\ # Start the server\n\ exec node server.js' > /home/user/start.sh RUN chmod +x /home/user/start.sh # Switch to non-root user USER user # Expose port EXPOSE 7860 # Set environment variables for LOCAL AI ONLY ENV PORT=7860 ENV NODE_ENV=production ENV USE_LOCAL_AI=true ENV USE_HUGGINGFACE=false ENV USE_OPENAI=false ENV LOCAL_AI_URL=http://host.docker.internal:11434 ENV LOCAL_AI_MODEL=llama3 ENV MONGODB_URI= ENV JWT_SECRET=local-ai-secret-change-in-production ENV JWT_REFRESH_SECRET=local-ai-refresh-secret-change-in-production # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD curl -f http://localhost:7860/health || exit 1 # Start the application CMD ["/home/user/start.sh"]