version: '3.8'

services:
  license-auth:
    build: ./services/auth
    container_name: license-auth
    environment:
      - JWT_SECRET=${JWT_SECRET:-your-secret-key-change-in-production}
      - DATABASE_URL=postgresql://admin:adminpass@postgres:5432/v2
      - REDIS_URL=redis://redis:6379
      - PORT=5001
    ports:
      - "5001:5001"
    depends_on:
      - postgres
      - redis
    networks:
      - v2_network
    restart: unless-stopped

  license-api:
    build: ./services/license_api
    container_name: license-api
    environment:
      - DATABASE_URL=postgresql://admin:adminpass@postgres:5432/v2
      - REDIS_URL=redis://redis:6379
      - RABBITMQ_URL=amqp://guest:guest@rabbitmq:5672
      - JWT_SECRET=${JWT_SECRET:-your-secret-key-change-in-production}
      - PORT=5002
    ports:
      - "5002:5002"
    depends_on:
      - postgres
      - redis
      - rabbitmq
    networks:
      - v2_network
    restart: unless-stopped

  license-analytics:
    build: ./services/analytics
    container_name: license-analytics
    environment:
      - DATABASE_URL=postgresql://admin:adminpass@postgres:5432/v2
      - REDIS_URL=redis://redis:6379
      - RABBITMQ_URL=amqp://guest:guest@rabbitmq:5672
      - PORT=5003
    ports:
      - "5003:5003"
    depends_on:
      - postgres
      - redis
      - rabbitmq
    networks:
      - v2_network
    restart: unless-stopped

  license-admin-api:
    build: ./services/admin_api
    container_name: license-admin-api
    environment:
      - DATABASE_URL=postgresql://admin:adminpass@postgres:5432/v2
      - REDIS_URL=redis://redis:6379
      - RABBITMQ_URL=amqp://guest:guest@rabbitmq:5672
      - JWT_SECRET=${JWT_SECRET:-your-secret-key-change-in-production}
      - PORT=5004
    ports:
      - "5004:5004"
    depends_on:
      - postgres
      - redis
      - rabbitmq
    networks:
      - v2_network
    restart: unless-stopped

  postgres:
    image: postgres:15-alpine
    container_name: license-postgres
    environment:
      - POSTGRES_DB=v2
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=adminpass
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - v2_network
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    container_name: license-redis
    command: redis-server --appendonly yes
    volumes:
      - redis_data:/data
    networks:
      - v2_network
    restart: unless-stopped

  rabbitmq:
    image: rabbitmq:3-management-alpine
    container_name: license-rabbitmq
    environment:
      - RABBITMQ_DEFAULT_USER=guest
      - RABBITMQ_DEFAULT_PASS=guest
    ports:
      - "5672:5672"
      - "15672:15672"
    volumes:
      - rabbitmq_data:/var/lib/rabbitmq
    networks:
      - v2_network
    restart: unless-stopped

volumes:
  postgres_data:
  redis_data:
  rabbitmq_data:

networks:
  v2_network:
    external: true