services:
  web:
    build: .
    ports:
      # 8888 matches the baseUrl the Flutter app already uses.
      - "8888:80"
    volumes:
      # Live mount: PHP edits apply without rebuilding the image.
      - .:/var/www/html/manager
    environment:
      DB_HOST: db
      DB_USER: app_manager
      DB_PASSWORD: app_manager
      DB_NAME: app_manager
    depends_on:
      db:
        condition: service_healthy

  db:
    image: mariadb:10.4
    ports:
      # Published so a GUI client (TablePlus, Sequel Ace) can connect from the
      # host. 3307 because a standalone MySQL may already own 3306; bound to
      # 127.0.0.1 so the database is not reachable from the network. The
      # container talks to `db` on 3306 internally and ignores this.
      - "127.0.0.1:3307:3306"
    environment:
      MARIADB_ROOT_PASSWORD: root
      MARIADB_DATABASE: app_manager
      MARIADB_USER: app_manager
      MARIADB_PASSWORD: app_manager
    volumes:
      - db_data:/var/lib/mysql
      # Anything in this directory runs on first startup, so a fresh clone
      # comes up with the schema already applied.
      - ./database:/docker-entrypoint-initdb.d:ro
    healthcheck:
      # mysqladmin ping works on every MariaDB version; healthcheck.sh only
      # exists in newer images.
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-proot"]
      interval: 5s
      timeout: 5s
      retries: 20
      start_period: 30s

volumes:
  db_data:
