# docker-compose per deploy VPS con Traefik.
# Assume che Traefik sia già attivo sulla VPS con:
#   - network esterna "traefik" (adatta nome se diverso)
#   - entrypoint "websecure" su :443
#   - certresolver "mytlschallenge" configurato
#
# Adattare eventualmente: nome network, entrypoint, certresolver.

services:
  pm2d:
    build: .
    image: pm2d:latest
    container_name: pm2d
    restart: unless-stopped
    environment:
      IMAGES_DIR: /data/images
      HOST: 0.0.0.0
      PORT: ${PORT:-8080}
    volumes:
      # Persistenza immagini tra restart (upload/selezione)
      - ./images:/data/images
    networks:
      - traefik
    labels:
      - "traefik.enable=true"

      # Router HTTPS principale
      - "traefik.http.routers.pm2d.rule=Host(`pm.tielogic.xyz`)"
      - "traefik.http.routers.pm2d.entrypoints=websecure"
      - "traefik.http.routers.pm2d.tls=true"
      - "traefik.http.routers.pm2d.tls.certresolver=mytlschallenge"
      - "traefik.http.services.pm2d.loadbalancer.server.port=${PORT:-8080}"

      # Middleware: upload fino a 50MB (default Traefik bufferizza a 4MB)
      - "traefik.http.middlewares.pm2d-bodysize.buffering.maxRequestBodyBytes=52428800"
      - "traefik.http.routers.pm2d.middlewares=pm2d-bodysize"
      # Redirect HTTP → HTTPS è gestito globalmente dall'entrypoint `web` di Traefik

networks:
  traefik:
    external: true
