version: '3.8'

services:
  redis:
    image: redis:7-alpine
    container_name: agent_bounty_redis
    restart: always
    ports:
      - "127.0.0.1:6379:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 5s
      retries: 10
    networks:
      - agent-bounty-network

  db:
    image: postgres:14-alpine
    container_name: agent_bounty_db
    restart: always
    environment:
      POSTGRES_USER: agent
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD is required}
      POSTGRES_DB: agent_bounty
    ports:
      - "127.0.0.1:5433:5432"
    volumes:
      - agent_bounty_pgdata:/var/lib/postgresql/data
    networks:
      - agent-bounty-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U agent"]
      interval: 5s
      timeout: 5s
      retries: 5


  web:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        NEXT_PUBLIC_ASSET_PREFIX: ${NEXT_PUBLIC_ASSET_PREFIX:-https://agent.wooo.work}
    container_name: agent_bounty_web
    restart: always
    ports:
      - "3004:3000"
    environment:
      # Use the docker internal network to connect to postgres
      - DATABASE_URL=${DATABASE_URL:-postgresql://agent:${POSTGRES_PASSWORD}@db:5432/agent_bounty?schema=public}
      - NODE_ENV=production
      - REDIS_URL=redis://redis:6379
      - API_KEY=${API_KEY:?API_KEY is required}
      - ADMIN_USERNAME=${ADMIN_USERNAME:-}
      - ADMIN_PASSWORD=${ADMIN_PASSWORD:-}
      - PUBLIC_MCP_BETA_TOKEN=${PUBLIC_MCP_BETA_TOKEN:-}
      - VIBEWORK_JOB_SECRET=${VIBEWORK_JOB_SECRET:-}
      - VIBEWORK_SITE_URL=${VIBEWORK_SITE_URL:-https://vibework.wooo.work}
      - NEXT_PUBLIC_VIBEWORK_SITE_URL=${NEXT_PUBLIC_VIBEWORK_SITE_URL:-https://vibework.wooo.work}
      - NEXT_PUBLIC_ASSET_PREFIX=${NEXT_PUBLIC_ASSET_PREFIX:-https://agent.wooo.work}
      - AGENT_GATEWAY_URL=${AGENT_GATEWAY_URL:-https://agent.wooo.work}
      - VIBEWORK_TREASURY_USDC_ADDRESS=${VIBEWORK_TREASURY_USDC_ADDRESS:-}
      - VIBEWORK_TREASURY_WALLET_LABEL=${VIBEWORK_TREASURY_WALLET_LABEL:-USDC Treasury}
      - A2A_GROWTH_ENABLE_OUTBOUND=${A2A_GROWTH_ENABLE_OUTBOUND:-false}
      - A2A_LEAD_GEN_DRY_RUN=${A2A_LEAD_GEN_DRY_RUN:-true}
      - A2A_LEAD_GEN_ENABLE_OUTBOUND=${A2A_LEAD_GEN_ENABLE_OUTBOUND:-false}
      - A2A_LEAD_GEN_AGENT_CARD_URLS=${A2A_LEAD_GEN_AGENT_CARD_URLS:-}
      - A2A_LEAD_GEN_ALLOWED_RPC_ORIGINS=${A2A_LEAD_GEN_ALLOWED_RPC_ORIGINS:-}
      - A2A_DISCOVERY_AGENT_CARD_URLS=${A2A_DISCOVERY_AGENT_CARD_URLS:-}
      - ENABLE_MOCK_STAKING=${ENABLE_MOCK_STAKING:-false}
      - ENABLE_MOCK_SETTLEMENT=${ENABLE_MOCK_SETTLEMENT:-false}
      - GITHUB_WEBHOOK_SECRET=${GITHUB_WEBHOOK_SECRET:-}
      - E2B_API_KEY=${E2B_API_KEY:-""}
      - AUTO_WHITELIST_EXTERNAL_AGENTS=${AUTO_WHITELIST_EXTERNAL_AGENTS:-false}
      - AUTO_APPROVE_BOUNTY_NEGOTIATION=${AUTO_APPROVE_BOUNTY_NEGOTIATION:-false}
      - ALLOW_MCP_CLAIM_WITHOUT_STRIPE=${ALLOW_MCP_CLAIM_WITHOUT_STRIPE:-false}
      - TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN:-}
      - TELEGRAM_CHAT_ID=${TELEGRAM_CHAT_ID:-}
      - A2A_TELEGRAM_CHAT_ID=${A2A_TELEGRAM_CHAT_ID:-}
      - A2A_TELEGRAM_BROADCAST_ENABLED=${A2A_TELEGRAM_BROADCAST_ENABLED:-false}
      - TELEGRAM_NOTIFY_EXTERNAL_ONLY=${TELEGRAM_NOTIFY_EXTERNAL_ONLY:-true}
      - TELEGRAM_NOTIFY_SYSTEM_WARN_INTERNAL_SUPPRESS=${TELEGRAM_NOTIFY_SYSTEM_WARN_INTERNAL_SUPPRESS:-true}
      - TRAFFIC_MONITOR_TOKEN=${TRAFFIC_MONITOR_TOKEN:-}
      - VIBEWORK_TRAFFIC_WEBHOOK_URL=${VIBEWORK_TRAFFIC_WEBHOOK_URL:-}
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    command: >
      sh -c "node apps/web/server.js"
    healthcheck:
      test: ["CMD-SHELL", "node -e \"const http=require('http');const req=http.get('http://127.0.0.1:3000/api/v1/health',(res)=>process.exit(res.statusCode===200?0:1));req.on('error',()=>process.exit(1));\""]
      interval: 10s
      timeout: 5s
      retries: 30
      start_period: 10s
    stop_grace_period: 30s
    networks:
      - agent-bounty-network


  agent:
    build:
      context: .
      dockerfile: Dockerfile.agent
    container_name: agent_bounty_agent
    restart: always
    ports:
      - "3001:3001"
    environment:
      - NODE_ENV=production
    networks:
      - agent-bounty-network

networks:
  agent-bounty-network:
    driver: bridge
    name: agent-bounty-network

volumes:
  agent_bounty_pgdata:
