services:
  mongo:
    image: mongo:7
    restart: unless-stopped
    ports:
      - '27017:27017'
    volumes:
      - trip_track_mongo_data:/data/db
    environment:
      MONGO_INITDB_DATABASE: trip_track
    healthcheck:
      test: ['CMD', 'mongosh', '--eval', "db.adminCommand('ping')"]
      interval: 5s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    restart: unless-stopped
    ports:
      - '6379:6379'
    volumes:
      - trip_track_redis_data:/data
    command: redis-server --appendonly yes

  api:
    build:
      context: .
      dockerfile: Dockerfile
    restart: unless-stopped
    ports:
      - '3000:3000'
    environment:
      NODE_ENV: production
      PORT: 3000
      HOST: 0.0.0.0
      MONGODB_URI: mongodb://mongo:27017/trip_track
      REDIS_URL: redis://redis:6379
      REDIS_ENABLED: 'true'
    depends_on:
      mongo:
        condition: service_healthy

volumes:
  trip_track_mongo_data:
  trip_track_redis_data:
