version: '2'

services:
  nextcloud:
    container_name: nextcloud
    restart: unless-stopped
    # image: arm64v8/nextcloud:latest
    image: nextcloud:latest
    networks:
      - traefik
    hostname: nextcloud.knast.cc
    volumes:
      - /srv/nextcloud/apps:/var/www/html/apps
      - /srv/nextcloud/config:/var/www/html/config
      - /srv/nextcloud/data:/var/www/html/data
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.nextcloud.tls=true"
      - "traefik.http.routers.nextcloud.entrypoints=websecure"
      - "traefik.http.routers.nextcloud.rule=Host(`nextcloud.$DOMAIN_NAME`)"
      - "traefik.http.routers.nextcloud.tls.certresolver=letsencr"
      - "traefik.http.routers.nextcloud.middlewares=nextcloud,nextcloud_redirect"
      - "traefik.http.middlewares.nextcloud.headers.stsSeconds=15552000"
      - "traefik.http.middlewares.nextcloud.headers.stsIncludeSubdomains=true"
      - "traefik.http.middlewares.nextcloud.headers.stsPreload=true"
      - "traefik.http.middlewares.nextcloud.headers.forceSTSHeader=true"
      - "traefik.http.middlewares.nextcloud.headers.contentSecurityPolicy=frame-ancestors 'self' knast.cc *.knast.cc"
      - "traefik.http.middlewares.nextcloud.headers.customFrameOptionsValue=SAMEORIGIN"
      - "traefik.http.middlewares.nextcloud.headers.customRequestHeaders.X-Forwarded-Proto=https" 
      # nextcloud_redirect
      - "traefik.http.middlewares.nextcloud_redirect.redirectregex.regex=/.well-known/(card|cal)dav"
      - "traefik.http.middlewares.nextcloud_redirect.redirectregex.replacement=/remote.php/dav/"
      # Service name and port
      - "traefik.http.routers.nextcloud.service=nextcloud"
      - "traefik.http.services.nextcloud.loadbalancer.server.port=80"
    depends_on:
      - db

  db:
    container_name: maria-db
    restart: unless-stopped
    networks:
      - traefik
    image: mariadb
    command: --innodb-read-only-compressed=OFF
    environment:
      MYSQL_ROOT_PASSWORD: '90sdg787s98dg796s5dgklsnv76'
      MYSQL_DATABASE: 'ncdb'
      MYSQL_USER: 'admin'
      MYSQL_PASSWORD: 'c0mput3r@1'
    volumes:
      - /srv/nextcloud/database:/var/lib/mysql
    labels:
      - "traefik.enable=false"


networks:
  traefik:
    external: true

