version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile.debug
    ports:
      - "8080:8080"
      - "50051:50051"
    depends_on:
      - postgres
      - redis
    environment:
      - HOST=0.0.0.0
      - PORT=8080
      - DATABASE_URL=postgres://postgres:password@postgres/bluesmoke_ai
      - REDIS_URL=redis://redis:6379
      - GRPC_HOST=0.0.0.0
      - GRPC_PORT=50051
      - RUST_BACKTRACE=1
      - RUST_LOG=debug
    networks:
      - bluesmoke-network
    restart: unless-stopped
    # Add healthcheck for the app service
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 5s
    volumes:
      # Mount source code for easier debugging
      - ./src:/usr/src/app/src:ro
      - ./logs:/logs

  postgres:
    image: postgres:15
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=bluesmoke_ai
    volumes:
      - postgres-data:/var/lib/postgresql/data
    networks:
      - bluesmoke-network
    restart: unless-stopped
    # Add healthcheck for postgres
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
    networks:
      - bluesmoke-network
    restart: unless-stopped
    # Add healthcheck for redis
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

networks:
  bluesmoke-network:
    driver: bridge

volumes:
  postgres-data:
  redis-data: