services:
    mariadb:
        container_name: nextcloud_mariadb
        env_file:
            - .db.env
        image: mariadb:10
        logging:
            driver: json-file
            options:
                max-size: 50m
                max-file: "3"
        networks:
            traefik:
                ipv4_address: 172.27.1.91
        restart: always
        volumes:
            - db:/var/lib/mysql

    redis:
        container_name: nextcloud_redis
        image: redis:6
        logging:
            driver: json-file
            options:
                max-size: 50m
                max-file: "3"
        networks:
            traefik: null
        restart: always
        volumes:
            - redis:/var/lib/redis
            - redis_data:/data

    nextcloud:
        container_name: nextcloud_server
        depends_on:
            - mariadb
            - redis
        env_file:
            - .env
        image: nextcloud:stable
        labels:
            traefik.docker.network: traefik
            traefik.enable: true
            traefik.http.routers.nextcloud.entrypoints: websecure
            traefik.http.routers.nextcloud.rule: Host(`nextcloud.alexlebens.net`)
            traefik.http.routers.nextcloud.service: nextcloud-nextcloud
            traefik.http.routers.nextcloud.middlewares: nextcloud,nextcloud_redirect
            traefik.http.middlewares.nextcloud.headers.customFrameOptionsValue: ALLOW-FROM https://nextcloud.alexlebens.net
            traefik.http.middlewares.nextcloud.headers.contentSecurityPolicy: frame-ancestors 'self' nextcloud.alexlebens.net *.nextcloud.alexlebens.net
            traefik.http.middlewares.nextcloud.headers.stsSeconds: 155520011
            traefik.http.middlewares.nextcloud.headers.stsIncludeSubdomains: true
            traefik.http.middlewares.nextcloud.headers.stsPreload: true
            traefik.http.middlewares.nextcloud.headers.customresponseheaders.X-Frame-Options: SAMEORIGIN
            traefik.http.middlewares.nextcloud_redirect.redirectregex.permanent: true
            traefik.http.middlewares.nextcloud_redirect.redirectregex.regex: https://(.*)/.well-known/(card|cal)dav
            traefik.http.middlewares.nextcloud_redirect.redirectregex.replacement: https://$${1}/remote.php/dav/
        logging:
            driver: json-file
            options:
                max-size: 50m
                max-file: "3"
        networks:
            traefik: null
        restart: always
        volumes:
            - data:/var/www/html

networks:
    traefik:
        name: traefik
        external: true

volumes:
    db:
        driver: local
        driver_opts:
            type: none
            o: bind
            device: /var/lib/docker/volumes/partition/nextcloud_db

    redis:
        driver: local
        driver_opts:
            type: none
            o: bind
            device: /var/lib/docker/volumes/partition/nextcloud_redis

    redis_data:
        driver: local
        driver_opts:
            type: none
            o: bind
            device: /var/lib/docker/volumes/partition/nextcloud_redis_data

    data:
        driver: local
        driver_opts:
            type: none
            o: bind
            device: /var/lib/docker/volumes/partition/nextcloud_data
