version: '3.8'

services:
  # Servicio MySQL
  mysql:
    image: mysql:8.0
    container_name: empenios_mysql
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: msplus2bdempenios
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: empenios_user
      MYSQL_PASSWORD: empenios_pass
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./docker/mysql/init:/docker-entrypoint-initdb.d
    networks:
      - empenios_network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-proot"]
      interval: 10s
      timeout: 5s
      retries: 5

  # Servicio PHP-FPM (Laravel)
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: empenios_app
    restart: unless-stopped
    working_dir: /var/www
    volumes:
      - ./:/var/www
      - ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
    networks:
      - empenios_network
    depends_on:
      mysql:
        condition: service_healthy

  # Servicio Nginx
  nginx:
    image: nginx:alpine
    container_name: empenios_nginx
    restart: unless-stopped
    ports:
      - "8000:80"
    volumes:
      - ./:/var/www
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    networks:
      - empenios_network
    depends_on:
      - app

  # PhpMyAdmin (opcional, para gestionar la BD)
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: empenios_phpmyadmin
    restart: unless-stopped
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3306
      PMA_USER: root
      PMA_PASSWORD: root
    ports:
      - "8080:80"
    networks:
      - empenios_network
    depends_on:
      - mysql

networks:
  empenios_network:
    driver: bridge

volumes:
  mysql_data:
    driver: local
