# WalletPress Production Docker Compose
# Included with Pro license download (walletpress.cc/buy)
# Not available in the open source repository.

version: "3.8"

services:
  walletpress:
    build: .
    image: walletpress:pro
    container_name: walletpress
    restart: unless-stopped
    ports:
      - "127.0.0.1:8010:8010"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
    volumes:
      - wp_data:/data
      - ./rpc.json:/etc/walletpress/rpc.json:ro
      - ./license.key:/etc/walletpress/license.key:ro
    environment:
      - WP_HOST=0.0.0.0
      - WP_PORT=8010
      - WP_DATA_DIR=/data
      - WP_DATABASE_URL=postgresql://walletpress:${WP_DB_PASSWORD}@postgres:5432/walletpress
      - WP_REDIS_URL=redis://redis:6379/0
      - WP_ADMIN_KEY=${WP_ADMIN_KEY}
      - WP_VAULT_PASSWORD=${WP_VAULT_PASSWORD}
      - WP_LICENSE_KEY=${WP_LICENSE_KEY}
      - WP_CORS_ORIGINS=${WP_CORS_ORIGINS:-https://yourdomain.com}
      - WP_RATE_LIMIT=120
      - WP_SMTP_HOST=${WP_SMTP_HOST:-}
      - WP_SMTP_PORT=${WP_SMTP_PORT:-587}
      - WP_SMTP_USER=${WP_SMTP_USER:-}
      - WP_SMTP_PASS=${WP_SMTP_PASS:-}
      - WP_FROM_EMAIL=${WP_FROM_EMAIL:-walletpress@yourdomain.com}
      - WP_NOTIFY_EMAIL=${WP_NOTIFY_EMAIL:-}
      - WP_ALLOWED_IPS=${WP_ALLOWED_IPS:-}
    healthcheck:
      test: ["CMD", "python", "-c", "import httpx; httpx.get('http://localhost:8010/health', timeout=5)"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 10s

  postgres:
    image: postgres:16-alpine
    container_name: wp-postgres
    restart: unless-stopped
    volumes:
      - wp_postgres:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=walletpress
      - POSTGRES_PASSWORD=${WP_DB_PASSWORD}
      - POSTGRES_DB=walletpress
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U walletpress"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: wp-redis
    restart: unless-stopped
    volumes:
      - wp_redis:/data
    command: redis-server --appendonly yes

  nginx:
    image: nginx:alpine
    container_name: wp-nginx
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    depends_on:
      - walletpress
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
      - wp_ssl:/etc/letsencrypt
      - wp_ssl_data:/var/www/certbot
    command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"

  certbot:
    image: certbot/certbot
    container_name: wp-certbot
    restart: unless-stopped
    volumes:
      - wp_ssl:/etc/letsencrypt
      - wp_ssl_data:/var/www/certbot
    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done'"

volumes:
  wp_data:
  wp_postgres:
  wp_redis:
  wp_ssl:
  wp_ssl_data:
