services:
  # Servicio de aplicación Laravel para Unraid
  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:-production}
      - APP_DEBUG=${APP_DEBUG:-false}
      - APP_URL=${APP_URL:-http://localhost:8000}
      - DB_CONNECTION=mysql
      - DB_HOST=all-panels-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:
      # Mapear código fuente
      - .:/var/www/html
      # Usar rutas específicas de Unraid para persistencia
      - /mnt/user/appdata/all-panels/storage:/var/www/html/storage/app
      - /mnt/user/appdata/all-panels/logs:/var/www/html/storage/logs
    depends_on:
      mysql:
        condition: service_healthy
    networks:
      - all-panels-network
    # Usuario para Unraid (nobody:users = 99:100)
    user: "99:100"

  # Servicio MySQL para Unraid
  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}
      - TZ=${TZ:-America/New_York}
    ports:
      - "${DB_PORT:-3306}:3306"
    volumes:
      # Persistencia de datos MySQL en Unraid
      - /mnt/user/appdata/all-panels/mysql:/var/lib/mysql
      # SQL de inicialización
      - ./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
    # Usuario MySQL (se ejecuta como mysql dentro del contenedor)
    # No necesita user override

  # PhpMyAdmin para Unraid
  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    container_name: all-panels-phpmyadmin
    restart: unless-stopped
    environment:
      - PMA_HOST=all-panels-mysql
      - PMA_PORT=3306
      - PMA_USER=${DB_USERNAME:-all_panel_user}
      - PMA_PASSWORD=${DB_PASSWORD:-all_panel_password}
      - UPLOAD_LIMIT=500M
      - TZ=${TZ:-America/New_York}
    ports:
      - "${PHPMYADMIN_PORT:-8080}:80"
    depends_on:
      - mysql
    networks:
      - all-panels-network

networks:
  all-panels-network:
    driver: bridge
    name: all-panels-network

# En Unraid, los volúmenes se mapean directamente a /mnt/user/appdata
# No necesitamos volúmenes con nombre ya que usamos rutas absolutas
