Production & Development Setup: - Multi-stage Dockerfile with optimized build (node:20-alpine) - docker-compose.yml for production with PostgreSQL - docker-compose.dev.yml for development with hot reload - Dockerfile.dev for development environment - .dockerignore to reduce build context Features: - Health checks for both app and database - Non-root user security (nextjs:nodejs) - Resource limits (CPU/memory) - Volume persistence for logs and database - PostgreSQL 16 with automatic initialization - Network isolation with custom bridge network Helper Scripts: - docker-build.sh - Build production image - docker-start.sh - Start all services - docker-stop.sh - Stop containers safely - docker-logs.sh - View real-time logs Documentation: - DOCKER.md - Complete deployment guide with: * Quick start commands * Production deployment steps * Development hot reload setup * Configuration examples * Docker commands reference * Troubleshooting guide * Best practices for security & performance Configuration: - Environment-based configuration via .env - Safe defaults for testing ($50 positions) - Separate dev/prod compose files - Debug mode with Node.js inspector (port 9229) - Log rotation and resource monitoring Ready for deployment with: cd v4 && ./docker-start.sh
136 lines
3.6 KiB
YAML
136 lines
3.6 KiB
YAML
# Trading Bot v4 - Docker Compose Configuration
|
|
# Production-ready setup with PostgreSQL and monitoring
|
|
|
|
version: '3.9'
|
|
|
|
services:
|
|
# ================================
|
|
# Trading Bot Application
|
|
# ================================
|
|
trading-bot:
|
|
build:
|
|
context: ..
|
|
dockerfile: v4/Dockerfile
|
|
container_name: trading-bot-v4
|
|
restart: unless-stopped
|
|
ports:
|
|
- "3000:3000"
|
|
environment:
|
|
# Node environment
|
|
NODE_ENV: production
|
|
PORT: 3000
|
|
|
|
# Load from .env file (create from .env.example)
|
|
DRIFT_WALLET_PRIVATE_KEY: ${DRIFT_WALLET_PRIVATE_KEY}
|
|
DRIFT_ENV: ${DRIFT_ENV:-mainnet-beta}
|
|
API_SECRET_KEY: ${API_SECRET_KEY}
|
|
SOLANA_RPC_URL: ${SOLANA_RPC_URL}
|
|
PYTH_HERMES_URL: ${PYTH_HERMES_URL:-https://hermes.pyth.network}
|
|
|
|
# Trading configuration
|
|
MAX_POSITION_SIZE_USD: ${MAX_POSITION_SIZE_USD:-50}
|
|
LEVERAGE: ${LEVERAGE:-10}
|
|
STOP_LOSS_PERCENT: ${STOP_LOSS_PERCENT:--1.5}
|
|
TAKE_PROFIT_1_PERCENT: ${TAKE_PROFIT_1_PERCENT:-0.7}
|
|
TAKE_PROFIT_2_PERCENT: ${TAKE_PROFIT_2_PERCENT:-1.5}
|
|
|
|
# Database (if using PostgreSQL)
|
|
DATABASE_URL: ${DATABASE_URL:-postgresql://postgres:postgres@postgres:5432/trading_bot_v4}
|
|
|
|
# Notifications
|
|
TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN:-}
|
|
TELEGRAM_CHAT_ID: ${TELEGRAM_CHAT_ID:-}
|
|
DISCORD_WEBHOOK_URL: ${DISCORD_WEBHOOK_URL:-}
|
|
|
|
# n8n integration
|
|
N8N_WEBHOOK_URL: ${N8N_WEBHOOK_URL:-}
|
|
TRADINGVIEW_WEBHOOK_SECRET: ${TRADINGVIEW_WEBHOOK_SECRET:-}
|
|
|
|
# Monitoring
|
|
LOG_LEVEL: ${LOG_LEVEL:-info}
|
|
DRY_RUN: ${DRY_RUN:-false}
|
|
|
|
volumes:
|
|
# Mount logs directory
|
|
- ./logs:/app/logs
|
|
|
|
# Mount for hot reload in development (comment out in production)
|
|
# - ./v4:/app/v4:ro
|
|
|
|
networks:
|
|
- trading-net
|
|
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
|
|
healthcheck:
|
|
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/api/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 40s
|
|
|
|
# Resource limits (adjust based on your needs)
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '1'
|
|
memory: 1G
|
|
reservations:
|
|
cpus: '0.5'
|
|
memory: 512M
|
|
|
|
# ================================
|
|
# PostgreSQL Database (Optional)
|
|
# ================================
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
container_name: trading-bot-postgres
|
|
restart: unless-stopped
|
|
ports:
|
|
- "5432:5432"
|
|
environment:
|
|
POSTGRES_DB: trading_bot_v4
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
|
|
POSTGRES_INITDB_ARGS: "--encoding=UTF8 --locale=en_US.UTF-8"
|
|
volumes:
|
|
# Persist database data
|
|
- postgres-data:/var/lib/postgresql/data
|
|
|
|
# Custom initialization scripts (optional)
|
|
- ./prisma/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
|
|
networks:
|
|
- trading-net
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.5'
|
|
memory: 512M
|
|
reservations:
|
|
cpus: '0.25'
|
|
memory: 256M
|
|
|
|
# ================================
|
|
# Networks
|
|
# ================================
|
|
networks:
|
|
trading-net:
|
|
driver: bridge
|
|
ipam:
|
|
config:
|
|
- subnet: 172.25.0.0/16
|
|
|
|
# ================================
|
|
# Volumes
|
|
# ================================
|
|
volumes:
|
|
postgres-data:
|
|
driver: local
|