services:
  mysql:
    image: mysql:8.0
    container_name: Mitica_mysql
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: Mitica_intra
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_USER: Mitica_user
      MYSQL_PASSWORD: Mitica_password
    ports:
      - "3307:3306"  # Puerto 3307 en host para evitar conflicto con MySQL existente
    volumes:
      - Mitica_mysql_data:/var/lib/mysql
      - ./../viejo/db.sql:/docker-entrypoint-initdb.d/db.sql:ro
    networks:
      - Mitica_network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-proot_password"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s

  php-fpm:
    build:
      context: .
      dockerfile: Dockerfile.php
    container_name: Mitica_php-fpm
    restart: unless-stopped
    working_dir: /var/www/html
    volumes:
      - .:/var/www/html
      - Mitica_php_data:/var/www/html/storage
    networks:
      - Mitica_network
    depends_on:
      mysql:
        condition: service_healthy
    environment:
      - DB_HOST=mysql
      - DB_PORT=3306
      - DB_DATABASE=Mitica_intra
      - DB_USERNAME=Mitica_user
      - DB_PASSWORD=Mitica_password

  nginx:
    image: nginx:alpine
    container_name: Mitica_nginx
    restart: unless-stopped
    ports:
      - "8000:80"
    volumes:
      - .:/var/www/html
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    networks:
      - Mitica_network
    depends_on:
      - php-fpm

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    container_name: Mitica_phpmyadmin
    restart: unless-stopped
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3306
      PMA_USER: root
      PMA_PASSWORD: root_password
      UPLOAD_LIMIT: 300M
    ports:
      - "8080:80"
    depends_on:
      mysql:
        condition: service_healthy
    networks:
      - Mitica_network

volumes:
  Mitica_mysql_data:
    name: Mitica_mysql_data
  Mitica_php_data:
    name: Mitica_php_data

networks:
  Mitica_network:
    name: Mitica_network
    driver: bridge
