version: "3.9"

services:
  app:
    build:
      context: .
      dockerfile: docker/app/Dockerfile
    container_name: erlimaem_app
    volumes:
      - ./:/var/www/html
      - ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini:ro
    depends_on:
      - db
    networks: [appnet]

  nginx:
    image: nginx:1.25-alpine
    container_name: erlimaem_nginx
    ports:
      - "80:80"
    volumes:
      - ./:/var/www/html
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - app
    networks: [appnet]

  db:
    image: mysql:8.0
    container_name: erlimaem_db
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_DATABASE: erlimaem
      MYSQL_USER: erlimaem
      MYSQL_PASSWORD: secret
      MYSQL_ROOT_PASSWORD: root
    ports:
      - "3306:3306"   # opsional; enak buat akses via DBeaver/TablePlus
    volumes:
      - dbdata:/var/lib/mysql
    networks: [appnet]

  node:
    image: node:20-alpine
    container_name: erlimaem_node
    working_dir: /var/www/html
    volumes:
      - ./:/var/www/html
    # Vite dev server (HMR) di 0.0.0.0 agar bisa diakses dari host
    command: sh -c "npm install && npm run dev -- --host 0.0.0.0 --port 5173"
    ports:
      - "5173:5173"
    depends_on:
      - app
    networks: [appnet]

volumes:
  dbdata:

networks:
  appnet:
