services:

  app:
    build:
      context: ./videodb
    container_name: videodb_app
    ports:
      - "6761:80"
    environment:
      DB_HOST: db
      DB_USER: videodb
      DB_PASSWORD: videodb_secret
      DB_NAME: videodb
      DB_PREFIX: videodb_
      INGEST_API_TOKEN: change_this_secret_token
    depends_on:
      db:
        condition: service_healthy
    volumes:
      # Persist cover images and cached thumbnails across rebuilds
      - videodb_cache:/var/www/html/cache
      - videodb_images:/var/www/html/images
    restart: unless-stopped

  db:
    image: mysql:8.0
    container_name: videodb_db
    environment:
      MYSQL_ROOT_PASSWORD: root_secret
      MYSQL_DATABASE: videodb
      MYSQL_USER: videodb
      MYSQL_PASSWORD: videodb_secret
    volumes:
      - videodb_db:/var/lib/mysql
    # MySQL 8 defaults to caching_sha2_password; keep native auth for broad client compat
    command: --default-authentication-plugin=mysql_native_password
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "videodb", "-pvideodb_secret"]
      interval: 10s
      timeout: 5s
      retries: 12
      start_period: 30s
    restart: unless-stopped

volumes:
  videodb_db:
  videodb_cache:
  videodb_images:
