Skip to content

An AI-powered search engine with a generative UI

feat: Add comprehensive Docker setup with PostgreSQL and Redis

Yoshiki Miurae845cf854089
diff --git a/.env.local.example b/.env.local.example
index b61e0ea7..5d870f1b 100644
--- a/.env.local.example
+++ b/.env.local.example
@@ -12,6 +12,15 @@
# -----------------------------------------------------------------------------
# PostgreSQL connection string (supports Neon, Supabase, or standard PostgreSQL)
# Format: postgresql://[user]:[password]@[host]/[database]?sslmode=require
+#
+# For local development: Use your local PostgreSQL instance
+# DATABASE_URL=postgresql://user:password@localhost:5432/morphic
+#
+# For Docker: Use the postgres service name from docker-compose.yaml
+# DATABASE_URL=postgresql://morphic:morphic@postgres:5432/morphic
+#
+# For cloud providers (Neon, Supabase, etc.): Add ?sslmode=require
+# DATABASE_URL=postgresql://user:password@host/database?sslmode=require
DATABASE_URL=[YOUR_DATABASE_URL]
# -----------------------------------------------------------------------------
@@ -144,6 +153,16 @@ NEXT_PUBLIC_SUPABASE_ANON_KEY=[YOUR_SUPABASE_ANON_KEY]
# Performance Logging
# ENABLE_PERF_LOGGING=true
+# -----------------------------------------------------------------------------
+# Docker Configuration (Optional)
+# -----------------------------------------------------------------------------
+# PostgreSQL credentials for Docker Compose
+# These are only used when running with docker-compose.yaml
+# POSTGRES_USER=morphic # Default: morphic
+# POSTGRES_PASSWORD=morphic # Default: morphic
+# POSTGRES_DB=morphic # Default: morphic
+# POSTGRES_PORT=5432 # Default: 5432
+
# -----------------------------------------------------------------------------
# Advanced Configuration
# -----------------------------------------------------------------------------
diff --git a/CLAUDE.md b/CLAUDE.md
index c0553824..5b204864 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -19,7 +19,9 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
### Docker
-- `docker compose up -d` - Run the application with Docker
+- `docker compose up -d` - Run the application with Docker (includes PostgreSQL 17, Redis, Morphic app, and SearXNG)
+- `docker compose down` - Stop all containers
+- `docker compose down -v` - Stop all containers and remove volumes (deletes database data)
- `docker pull ghcr.io/miurla/morphic:latest` - Pull prebuilt Docker image
## Architecture Overview
@@ -30,8 +32,8 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
- **React 19.2.0** with TypeScript for type safety
- **Vercel AI SDK 5.0.0-alpha.2** for AI streaming and GenerativeUI
- **Supabase** for authentication and backend services
-- **PostgreSQL** with Drizzle ORM for database
-- **Redis** (Upstash or local) for chat history storage
+- **PostgreSQL** with Drizzle ORM for database and chat history storage
+- **Redis** (Upstash or local) for SearXNG advanced search caching
- **Tailwind CSS** with shadcn/ui components
### Core Architecture
diff --git a/Dockerfile b/Dockerfile
index 5ca01344..210cef84 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -23,5 +23,19 @@ COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/bun.lock ./bun.lock
COPY --from=builder /app/node_modules ./node_modules
-# Start production server
+# Copy migration files and scripts
+COPY --from=builder /app/drizzle ./drizzle
+COPY --from=builder /app/lib/db ./lib/db
+COPY --from=builder /app/drizzle.config.ts ./drizzle.config.ts
+
+# Create entrypoint script for database migration
+RUN echo '#!/bin/sh\n\
+set -e\n\
+echo "Running database migrations..."\n\
+bun run migrate\n\
+echo "Migrations completed. Starting server..."\n\
+exec "$@"\n' > /app/docker-entrypoint.sh && chmod +x /app/docker-entrypoint.sh
+
+# Start production server with migration
+ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["bun", "start", "-H", "0.0.0.0"]
diff --git a/README.md b/README.md
index a8dbacb5..3120c939 100644
--- a/README.md
+++ b/README.md
@@ -202,11 +202,56 @@ bun dev
#### Using Docker
+1. Configure environment variables for Docker:
+
+```bash
+cp .env.local.example .env.local
+```
+
+Edit `.env.local` and set the DATABASE_URL to use the Docker PostgreSQL service:
+
+```bash
+# Database Configuration for Docker
+DATABASE_URL=postgresql://morphic:morphic@postgres:5432/morphic
+
+# Required API Keys
+OPENAI_API_KEY= # Get from https://platform.openai.com/api-keys
+TAVILY_API_KEY= # Get from https://app.tavily.com/home
+BRAVE_SEARCH_API_KEY= # Get from https://brave.com/search/api/
+NEXT_PUBLIC_SUPABASE_URL= # Your Supabase project URL
+NEXT_PUBLIC_SUPABASE_ANON_KEY= # Your Supabase anonymous key
+```
+
+**Optional**: Customize PostgreSQL credentials by setting environment variables in `.env.local`:
+
+```bash
+POSTGRES_USER=morphic # Default: morphic
+POSTGRES_PASSWORD=morphic # Default: morphic
+POSTGRES_DB=morphic # Default: morphic
+POSTGRES_PORT=5432 # Default: 5432
+```
+
+2. Start the Docker containers:
+
```bash
docker compose up -d
```
-Visit http://localhost:3000 in your browser.
+The application will:
+- Start PostgreSQL 17 with health checks
+- Start Redis for SearXNG search caching
+- Wait for the database to be ready
+- Run database migrations automatically
+- Start the Morphic application
+- Start SearXNG (optional search provider)
+
+3. Visit http://localhost:3000 in your browser.
+
+**Note**: Database data is persisted in a Docker volume. To reset the database, run:
+
+```bash
+docker compose down -v # This will delete all data
+```
## 🌐 Deploy
@@ -216,6 +261,16 @@ Host your own live version of Morphic with Vercel or Docker.
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fmiurla%2Fmorphic&env=DATABASE_URL,OPENAI_API_KEY,TAVILY_API_KEY,BRAVE_SEARCH_API_KEY,NEXT_PUBLIC_SUPABASE_URL,NEXT_PUBLIC_SUPABASE_ANON_KEY)
+### Docker
+
+You can deploy Morphic using the prebuilt Docker image:
+
+```bash
+docker pull ghcr.io/miurla/morphic:latest
+```
+
+Or use Docker Compose for a complete setup with PostgreSQL, Redis, and SearXNG. See the [Using Docker](#using-docker) section for detailed instructions.
+
## 👥 Contributing
We welcome contributions to Morphic! Whether it's bug reports, feature requests, or pull requests, all contributions are appreciated.
diff --git a/docker-compose.yaml b/docker-compose.yaml
index cad1303a..019d2d41 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -12,11 +12,36 @@ services:
- morphic:builder
- morphic:latest
env_file: .env.local # Load environment variables
+ environment:
+ # Set NODE_ENV to development for local Docker environment
+ NODE_ENV: development
+ # Override DATABASE_URL for Docker Compose (without sslmode, handled by NODE_ENV)
+ DATABASE_URL: postgresql://${POSTGRES_USER:-morphic}:${POSTGRES_PASSWORD:-morphic}@postgres:5432/${POSTGRES_DB:-morphic}
ports:
- '3000:3000' # Maps port 3000 on the host to port 3000 in the container.
depends_on:
- - redis
- - searxng
+ postgres:
+ condition: service_healthy
+ redis:
+ condition: service_started
+ searxng:
+ condition: service_started
+
+ postgres:
+ image: postgres:17-alpine
+ environment:
+ POSTGRES_USER: ${POSTGRES_USER:-morphic}
+ POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-morphic}
+ POSTGRES_DB: ${POSTGRES_DB:-morphic}
+ ports:
+ - '${POSTGRES_PORT:-5432}:5432'
+ volumes:
+ - postgres_data:/var/lib/postgresql/data
+ healthcheck:
+ test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER:-morphic}']
+ interval: 10s
+ timeout: 5s
+ retries: 5
redis:
image: redis:alpine
@@ -37,5 +62,6 @@ services:
- searxng_data:/data
volumes:
+ postgres_data:
redis_data:
searxng_data:
diff --git a/lib/db/migrate.ts b/lib/db/migrate.ts
index dceda0bc..b8ee820a 100644
--- a/lib/db/migrate.ts
+++ b/lib/db/migrate.ts
@@ -14,10 +14,14 @@ const runMigrations = async () => {
}
const connectionString = process.env.DATABASE_URL
- // For Supabase connections, we need to disable SSL verification in some environments
- // and disable prepared statements for transaction pooling mode
+ // For production (Supabase, Neon, etc.), use SSL with rejectUnauthorized: false
+ // For development/local (Docker, localhost), disable SSL
+ // This follows Drizzle's best practice of environment-based configuration
const sql = postgres(connectionString, {
- ssl: { rejectUnauthorized: false },
+ ssl:
+ process.env.NODE_ENV === 'production'
+ ? { rejectUnauthorized: false }
+ : false,
prepare: false
})