version: '3.8'

services:
  # Base de datos MySQL
  mysql:
    image: mysql:8.0
    container_name: margarita_mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: margarita_intra
      MYSQL_USER: margarita_user
      MYSQL_PASSWORD: margarita_password
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./init-db.sql:/docker-entrypoint-initdb.d/01-init.sql
      - ./intranet/db.sql:/docker-entrypoint-initdb.d/02-data.sql
    networks:
      - margarita_network

  # PHPMyAdmin
  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    container_name: margarita_phpmyadmin
    restart: unless-stopped
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3306
      PMA_USER: margarita_user
      PMA_PASSWORD: margarita_password
      MYSQL_ROOT_PASSWORD: root_password
      UPLOAD_LIMIT: 50M
      MEMORY_LIMIT: 256M
      MAX_EXECUTION_TIME: 300
      POST_MAX_SIZE: 50M
    ports:
      - "8080:80"
    depends_on:
      - mysql
    networks:
      - margarita_network

  # Aplicación PHP/Apache
  web:
    build: .
    container_name: margarita_web
    restart: unless-stopped
    ports:
      - "80:80"
    volumes:
      - ./intranet:/var/www/html
    depends_on:
      - mysql
    networks:
      - margarita_network
    environment:
      - APACHE_DOCUMENT_ROOT=/var/www/html

volumes:
  mysql_data:

networks:
  margarita_network:
    driver: bridge
