# Spec 034 — Nextcloud Hub (VM124)
# Traefik CT114 → http://10.10.10.116:8080 (or target IP)
# Usage: docker compose --env-file .env up -d

services:
  db:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-nextcloud}
      POSTGRES_USER: ${POSTGRES_USER:-nextcloud}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}
    volumes:
      - nc-db:/var/lib/postgresql/data
    command: postgres -c shared_buffers=128MB -c max_connections=80
    mem_limit: 384m
    networks: [nextcloud]

  redis:
    image: redis:7-alpine
    restart: unless-stopped
    command: redis-server --save 60 1000 --loglevel warning
    volumes:
      - nc-redis:/data
    mem_limit: 64m
    networks: [nextcloud]

  nextcloud:
    image: nextcloud:30-apache
    restart: unless-stopped
    ports:
      - "${NC_HTTP_PORT:-8080}:80"
    environment:
      POSTGRES_HOST: db
      POSTGRES_DB: ${POSTGRES_DB:-nextcloud}
      POSTGRES_USER: ${POSTGRES_USER:-nextcloud}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      REDIS_HOST: redis
      NEXTCLOUD_ADMIN_USER: ${NC_ADMIN_USER:-ligbox-provisioner}
      NEXTCLOUD_ADMIN_PASSWORD: ${NC_ADMIN_PASSWORD:?set NC_ADMIN_PASSWORD}
      NEXTCLOUD_TRUSTED_DOMAINS: ${NC_TRUSTED_DOMAINS:-cloud.ligbox.com.br}
      APACHE_BODY_LIMIT: 1073741824
      PHP_MEMORY_LIMIT: 384M
      PHP_UPLOAD_LIMIT: 512M
    volumes:
      - nc-data:/var/www/html
    depends_on:
      - db
      - redis
    mem_limit: 1024m
    networks: [nextcloud]

  cron:
    image: nextcloud:30-apache
    restart: unless-stopped
    entrypoint: /cron.sh
    volumes:
      - nc-data:/var/www/html
    depends_on:
      - nextcloud
    mem_limit: 128m
    networks: [nextcloud]

volumes:
  nc-db:
  nc-redis:
  nc-data:

networks:
  nextcloud:
    driver: bridge
