version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: uptime-sentinel-app
    restart: always
    ports:
      - "3090:3000" # Mapped to 3090 to avoid conflict with local `npm run dev` (3005)
    environment:
      - DATABASE_URL=mysql://user:password@db:3306/uptime_sentinel
      - NEXTAUTH_URL=http://localhost:3090
      - NEXTAUTH_SECRET=changeme_in_production_please
    depends_on:
      db:
        condition: service_healthy
    networks:
      - uptime-network

  db:
    image: mysql:8.0
    container_name: uptime-sentinel-db
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: uptime_sentinel
      MYSQL_USER: user
      MYSQL_PASSWORD: password
    ports:
      - "3306:3306" # HOST:CONTAINER - Port 3306 on host as requested
    volumes:
      - db-data:/var/lib/mysql
    healthcheck:
      test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
      timeout: 20s
      retries: 10
    networks:
      - uptime-network

networks:
  uptime-network:
    driver: bridge

volumes:
  db-data:
