version: "3.9"

services:
  # PHP-FPM (Laravel backend)
  app:
    build:
      context: .                # Build from current folder (where Dockerfile is)
      dockerfile: Dockerfile
      target: app               # Use "app" stage from Dockerfile
    container_name: laravel_app
    restart: always
    volumes:
      # Persist storage/uploads
      - laravel_storage:/var/www/storage
      - ./php.ini:/usr/local/etc/php/conf.d/custom.ini  # 👈 mount custom php.ini
    depends_on:
      - db
    networks:
      - laravel
    command: >
      sh -c "php artisan storage:link && php-fpm"

  # MySQL Database
  db:
    image: mysql:8.0
    container_name: mysql_db
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: TMC@4321#
      MYSQL_DATABASE: qad
      MYSQL_USER: laravel
      MYSQL_PASSWORD: laravel
    volumes:
      # Persist MySQL data
      - db_data:/var/lib/mysql
    ports:
      - "3306:3306"  # forward for local dev (optional)
    networks:
      - laravel

  # Nginx Web Server
  nginx:
    build:
      context: .
      dockerfile: Dockerfile
      target: nginx             # Use "nginx" stage from Dockerfile
    container_name: nginx_web
    restart: always
    ports:
      - "8080:80"               # access Laravel via http://localhost:8080
    volumes:
      # Same persistent storage for uploaded files
      - laravel_storage:/var/www/storage
      # Custom nginx config
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - app
    networks:
      - laravel

volumes:
  # Persistent named volumes
  db_data:          # for MySQL
  laravel_storage:  # for Laravel storage/uploads

networks:
  laravel:
    driver: bridge
