services:
  # Servicio de aplicación Laravel
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: all-panels-app
    restart: unless-stopped
    ports:
      - "${APP_PORT:-8000}:80"
    environment:
      - APP_NAME=${APP_NAME:-AllPanels}
      - APP_ENV=${APP_ENV:-local}
      - APP_DEBUG=${APP_DEBUG:-true}
      - APP_URL=${APP_URL:-http://localhost:8000}
      - DB_CONNECTION=mysql
      - DB_HOST=mysql
      - DB_PORT=3306
      - DB_DATABASE=${DB_DATABASE:-all-panel}
      - DB_USERNAME=${DB_USERNAME:-all_panel_user}
      - DB_PASSWORD=${DB_PASSWORD:-all_panel_password}
      - CACHE_DRIVER=file
      - QUEUE_CONNECTION=sync
      - SESSION_DRIVER=file
      - SESSION_LIFETIME=120
    volumes:
      - ./:/var/www/html
      - storage_data:/var/www/html/storage/app
      - logs_data:/var/www/html/storage/logs
    depends_on:
      mysql:
        condition: service_healthy
    networks:
      - all-panels-network

  # Servicio MySQL
  mysql:
    image: mysql:8.0
    container_name: all-panels-mysql
    restart: unless-stopped
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root_password}
      - MYSQL_DATABASE=${DB_DATABASE:-all-panel}
      - MYSQL_USER=${DB_USERNAME:-all_panel_user}
      - MYSQL_PASSWORD=${DB_PASSWORD:-all_panel_password}
    ports:
      - "${DB_PORT:-3306}:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./all-panel04082025.sql:/docker-entrypoint-initdb.d/all-panel04082025.sql:ro
      - ./docker/init-db.sh:/docker-entrypoint-initdb.d/init-db.sh:ro
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-root_password}"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
    networks:
      - all-panels-network

  # PhpMyAdmin (opcional, solo en desarrollo)
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: all-panels-phpmyadmin
    restart: unless-stopped
    environment:
      - PMA_HOST=mysql
      - PMA_PORT=3306
      - PMA_USER=${DB_USERNAME:-all_panel_user}
      - PMA_PASSWORD=${DB_PASSWORD:-all_panel_password}
      - UPLOAD_LIMIT=500M
    ports:
      - "${PHPMYADMIN_PORT:-8080}:80"
    depends_on:
      - mysql
    networks:
      - all-panels-network
    profiles:
      - dev

networks:
  all-panels-network:
    driver: bridge

volumes:
  mysql_data:
    driver: local
  storage_data:
    driver: local
  logs_data:
    driver: local
