Files
nofx/docker-compose.yml
icy 6426696258 feat: migrate from SQLite to PostgreSQL + Redis architecture
Major database migration to modernize the AI trading system:
• **Database Migration**:
  - Add PostgreSQL 15 and Redis 7 services to docker-compose
  - Create comprehensive PostgreSQL schema with proper indexes and triggers
  - Implement DatabaseInterface for multi-database support
  - Add automatic environment-based database selection
• **Infrastructure**:
  - PostgreSQL: ACID transactions, better concurrency, JSON support
  - Redis: High-performance caching layer (prepared for future use)
  - Docker services with health checks and dependency management
  - Persistent volumes for data safety
• **Code Refactoring**:
  - Abstract database operations through DatabaseInterface
  - Implement PostgreSQL-specific operations with proper syntax
  - Update all SQL queries to support both SQLite and PostgreSQL
  - Fix foreign key constraints and data type conversions
• **Migration Tools**:
  - Automated data migration script from SQLite to PostgreSQL
  - Complete backup and restore procedures
  - One-click migration script with validation
• **Compatibility**:
  - Backward compatible with existing SQLite deployments
  - Environment variable driven database selection
  - Preserved all existing functionality and data
🎯 Benefits: Better performance, scalability, and reliability for production deployments
2025-11-04 15:09:11 +08:00

107 lines
2.8 KiB
YAML

services:
# PostgreSQL Database
postgres:
image: postgres:15-alpine
container_name: nofx-postgres
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB:-nofx}
POSTGRES_USER: ${POSTGRES_USER:-nofx}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-nofx123456}
volumes:
- postgres_data:/var/lib/postgresql/data
- ./db/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
ports:
- "${POSTGRES_PORT:-5433}:5432"
networks:
- nofx-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-nofx}"]
interval: 10s
timeout: 5s
retries: 5
# Redis Cache
redis:
image: redis:7-alpine
container_name: nofx-redis
restart: unless-stopped
command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD:-redis123456}
volumes:
- redis_data:/data
ports:
- "${REDIS_PORT:-6380}:6379"
networks:
- nofx-network
healthcheck:
test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
interval: 10s
timeout: 3s
retries: 5
# Backend service (API and core logic)
nofx:
build:
context: .
dockerfile: ./docker/Dockerfile.backend
container_name: nofx-trading
restart: unless-stopped
ports:
- "${NOFX_BACKEND_PORT:-8080}:8080"
volumes:
- ./config.json:/app/config.json:ro
- ./beta_codes.txt:/app/beta_codes.txt:ro
- ./decision_logs:/app/decision_logs
- ./prompts:/app/prompts
- /etc/localtime:/etc/localtime:ro # Sync host time
environment:
- TZ=${NOFX_TIMEZONE:-Asia/Shanghai} # Set timezone
- POSTGRES_HOST=postgres
- POSTGRES_PORT=5432
- POSTGRES_DB=${POSTGRES_DB:-nofx}
- POSTGRES_USER=${POSTGRES_USER:-nofx}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-nofx123456}
- REDIS_HOST=redis
- REDIS_PORT=6379
- REDIS_PASSWORD=${REDIS_PASSWORD:-redis123456}
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
networks:
- nofx-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/api/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
# Frontend service (static serving and proxy)
nofx-frontend:
build:
context: .
dockerfile: ./docker/Dockerfile.frontend
container_name: nofx-frontend
restart: unless-stopped
ports:
- "${NOFX_FRONTEND_PORT:-3000}:80"
networks:
- nofx-network
depends_on:
- nofx
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 5s
networks:
nofx-network:
driver: bridge
volumes:
postgres_data:
redis_data: