services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: absensi-sekolah-qr-code
    container_name: absensi-app
    restart: unless-stopped
    tty: true
    environment:
      SERVICE_NAME: app
      SERVICE_TAGS: dev
      TZ: Asia/Jakarta
    working_dir: /var/www/html
    env_file:
      - .env.docker
    volumes:
      - ./:/var/www/html
      # Map .env.docker as .env inside container so CI4 reads Docker config.
      # Host's .env (with 127.0.0.1) stays untouched for local php spark serve.
      - ./.env.docker:/var/www/html/.env
    networks:
      - app-network
    ports:
      - "8080:80"
    depends_on:
      db:
        condition: service_healthy

  db:
    image: mysql:8.0
    container_name: absensi-db
    restart: unless-stopped
    tty: true
    ports:
      - "3306:3306"
    environment:
      SERVICE_NAME: db
      SERVICE_TAGS: dev
      TZ: Asia/Jakarta
    env_file:
      - .env.docker
    volumes:
      - dbdata:/var/lib/mysql
    networks:
      - app-network
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "mysql -h localhost -u root -p$$MYSQL_ROOT_PASSWORD --ssl-mode=DISABLED -e 'SELECT 1'",
        ]
      interval: 5s
      timeout: 5s
      retries: 10
      start_period: 30s

  pma:
    image: phpmyadmin/phpmyadmin
    container_name: absensi-pma
    restart: unless-stopped
    environment:
      PMA_HOST: db
      PMA_PORT: 3306
    ports:
      - "8081:80"
    networks:
      - app-network

  adminer:
    image: adminer
    container_name: absensi-adminer
    restart: unless-stopped
    ports:
      - "8082:8080"
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

volumes:
  dbdata:
    driver: local
