Keep/keep-notes/deploy.sh
sepehr 8617117dec fix: remove Ollama default fallbacks in factory and Docker
ROOT CAUSE: The factory was defaulting to 'ollama' when no provider
was configured, and docker-compose.yml was always setting OLLAMA_BASE_URL
even when using OpenAI. This caused the app to try connecting to Ollama
even when OpenAI was configured in the admin.

CRITICAL CHANGES:
1. lib/ai/factory.ts - Removed 'ollama' default fallback
   - getTagsProvider() now throws error if AI_PROVIDER_TAGS not set
   - getEmbeddingsProvider() now throws error if AI_PROVIDER_EMBEDDING not set
   - Forces explicit configuration instead of silent fallback to Ollama

2. docker-compose.yml - Removed default OLLAMA_BASE_URL
   - Changed: OLLAMA_BASE_URL=${OLLAMA_BASE_URL:-http://ollama:11434}
   - To: OLLAMA_BASE_URL=${OLLAMA_BASE_URL}
   - Only set if explicitly defined in .env.docker

3. Application name: Mento → Memento (correct spelling)
   - Updated in: sidebar, README, deploy.sh, DOCKER_DEPLOYMENT.md

4. app/api/ai/config/route.ts - Return 'not set' instead of 'ollama'
   - Makes it clear when provider is not configured

IMPACT: The app will now properly use OpenAI when configured in the
admin interface, instead of silently falling back to Ollama.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-12 23:08:20 +01:00

179 lines
5.1 KiB
Bash

#!/bin/bash
# Memento Docker Deployment Script
# This script helps you build and deploy Memento on Proxmox/Docker
set -e
echo "🚀 Memento Docker Deployment"
echo "================================"
echo ""
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if Docker is installed
if ! command -v docker &> /dev/null; then
echo -e "${RED}❌ Docker is not installed${NC}"
echo "Please install Docker first: https://docs.docker.com/get-docker/"
exit 1
fi
# Check if docker compose is available (modern Docker Compose v2)
if ! docker compose version &> /dev/null; then
echo -e "${RED}❌ Docker Compose is not installed${NC}"
echo "Please install Docker Compose first"
exit 1
fi
echo -e "${GREEN}✓ Docker and Docker Compose found${NC}"
echo ""
# Check if .env exists
if [ ! -f .env ]; then
echo -e "${YELLOW}⚠️ .env file not found${NC}"
echo "Creating .env file with defaults..."
# Generate random secret
SECRET=$(openssl rand -base64 32 2>/dev/null || echo "change-this-secret-in-production")
cat > .env << EOF
# Required: Application Configuration
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=$SECRET
# Optional: OpenAI API Key (uncomment to use)
# OPENAI_API_KEY=sk-your-key-here
# Optional: Ollama Configuration (uncomment to use local AI)
# OLLAMA_BASE_URL=http://ollama:11434
# OLLAMA_MODEL=granite4:latest
EOF
echo -e "${GREEN}✓ .env file created${NC}"
echo ""
echo -e "${YELLOW}⚠️ IMPORTANT: Edit .env and update NEXTAUTH_URL and NEXTAUTH_SECRET${NC}"
read -p "Press Enter to continue after editing .env..."
fi
# Parse command line arguments
COMMAND=${1:-"help"}
case $COMMAND in
build)
echo "🔨 Building Docker image..."
docker compose build
echo -e "${GREEN}✓ Build completed${NC}"
;;
start|up)
echo "🚀 Starting containers..."
docker compose up -d
echo -e "${GREEN}✓ Containers started${NC}"
echo ""
echo "📝 Application available at: http://localhost:3000"
;;
stop|down)
echo "⏹️ Stopping containers..."
docker compose down
echo -e "${GREEN}✓ Containers stopped${NC}"
;;
restart)
echo "🔄 Restarting containers..."
docker compose restart
echo -e "${GREEN}✓ Containers restarted${NC}"
;;
logs)
echo "📋 Showing logs (Ctrl+C to exit)..."
docker compose logs -f keep-notes
;;
status)
echo "📊 Container status:"
docker compose ps
;;
update)
echo "🔄 Updating application..."
echo "Pulling latest changes..."
git pull
echo "Rebuilding..."
docker compose build
echo "Restarting..."
docker compose down
docker compose up -d
echo -e "${GREEN}✓ Update completed${NC}"
;;
backup)
echo "💾 Creating database backup..."
BACKUP_DIR="./backups"
mkdir -p $BACKUP_DIR
DATE=$(date +%Y%m%d_%H%M%S)
docker exec keep-notes \
cp /app/prisma/dev.db /app/prisma/backup_$DATE.db 2>/dev/null || {
echo -e "${RED}❌ Container not running. Start it first with: $0 start${NC}"
exit 1
}
docker cp keep-notes:/app/prisma/backup_$DATE.db \
$BACKUP_DIR/keep-notes_$DATE.db
echo -e "${GREEN}✓ Backup created: $BACKUP_DIR/keep-notes_$DATE.db${NC}"
;;
clean)
echo "🧹 Cleaning up..."
echo "Stopping containers..."
docker compose down
echo "Removing old images..."
docker image prune -a -f
echo "Removing unused volumes..."
docker volume prune -f
echo -e "${GREEN}✓ Cleanup completed${NC}"
;;
ollama-pull)
MODEL=${2:-"granite4"}
echo "🤖 Pulling Ollama model: $MODEL"
docker compose exec -it ollama ollama pull $MODEL
echo -e "${GREEN}✓ Model pulled${NC}"
;;
shell)
echo "🐚 Opening shell in container..."
docker compose exec keep-notes sh
;;
*)
echo "Usage: $0 {build|start|stop|restart|logs|status|update|backup|clean|ollama-pull|shell}"
echo ""
echo "Commands:"
echo " build - Build Docker image"
echo " start, up - Start containers"
echo " stop, down - Stop containers"
echo " restart - Restart containers"
echo " logs - Show container logs"
echo " status - Show container status"
echo " update - Pull latest, rebuild, and restart"
echo " backup - Backup database"
echo " clean - Remove containers, images, and volumes"
echo " ollama-pull - Pull Ollama model (optional: model name)"
echo " shell - Open shell in container"
echo ""
echo "Examples:"
echo " $0 build"
echo " $0 start"
echo " $0 logs"
echo " $0 update"
echo " $0 ollama-pull llama2"
;;
esac