version: '3.9'

services:
  nextcloud:
    image: nextcloud:27.1.3
    environment:
      - MYSQL_HOST=mariadb_primary
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD_FILE=/run/secrets/nextcloud_db_password
    secrets:
      - nextcloud_db_password
    volumes:
      - nextcloud_data:/var/www/html
    networks:
      - traefik-public
      - database-network
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost/status.php"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 90s
    deploy:
      resources:
        limits:
          memory: 2G
          cpus: '1.0'
        reservations:
          memory: 512M
          cpus: '0.25'
      placement:
        constraints:
          - "node.labels.role==web"
      labels:
        - traefik.enable=true
        - traefik.http.routers.nextcloud.rule=Host(`nextcloud.localhost`)
        - traefik.http.routers.nextcloud.entrypoints=websecure
        - traefik.http.routers.nextcloud.tls=true
        - traefik.http.services.nextcloud.loadbalancer.server.port=80

volumes:
  nextcloud_data:
    driver: local
    driver_opts:
      type: nfs
      o: addr=omv800.local,nolock,soft,rw
      device: :/export/nextcloud/html

secrets:
  nextcloud_db_password:
    external: true

networks:
  traefik-public:
    external: true
  database-network:
    external: true
