services:
  mongodb:
    image: mongo:7.0
    container_name: mcp_adcp_mongodb
    restart: always
    ports:
      - "27123:27017"  # Randomized host port
    environment:
      MONGO_INITDB_ROOT_USERNAME: admin
      MONGO_INITDB_ROOT_PASSWORD: admin123
      MONGO_INITDB_DATABASE: mcp_adcp_db
    volumes:
      - mongodb_data:/data/db
      - mongodb_config:/data/configdb
      - ./init-scripts:/docker-entrypoint-initdb.d:ro
    networks:
      - mcp_network
    healthcheck:
      test: echo 'db.runCommand("ping").ok' | mongosh --username admin --password admin123 --authenticationDatabase admin localhost:27017/test --quiet
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 40s

  mongo-express:
    image: mongo-express:latest
    container_name: mcp_adcp_mongo_express
    restart: always
    ports:
      - "8099:8081"  # Randomized host port
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: admin
      ME_CONFIG_MONGODB_ADMINPASSWORD: admin123
      ME_CONFIG_MONGODB_URL: mongodb://admin:admin123@mongodb:27017/
      ME_CONFIG_BASICAUTH_USERNAME: admin
      ME_CONFIG_BASICAUTH_PASSWORD: admin123
    depends_on:
      mongodb:
        condition: service_healthy
    networks:
      - mcp_network

  api:
    build: src
    container_name: acdp_api
    restart: always
    depends_on:
      - mongodb
    environment:
      - MONGO_URI=mongodb://mongodb:27017/
    ports:
      - "8123:8000"  # Randomized host port
    volumes:
      - .:/app
    networks:
      - mcp_network

volumes:
  mongodb_data:
    driver: local
  mongodb_config:
    driver: local

networks:
  mcp_network:
    driver: bridge