services:
    postgresql:
        container_name: authentik_postgresql
        env_file:
            - .env
        image: postgres:12-alpine
        healthcheck:
            test:
                [
                    "CMD-SHELL",
                    "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"
                ]
            start_period: 20s
            interval: 30s
            retries: 5
            timeout: 5s
        logging:
            driver: json-file
            options:
                max-size: 50m
                max-file: "3"
        networks:
            authentik:
                ipv4_address: 172.14.0.3
        restart: unless-stopped
        volumes:
            - postgressql:/var/lib/postgresql/data

    redis:
        command: --save 60 1 --loglevel warning
        container_name: authentik_redis
        healthcheck:
            test: [ "CMD-SHELL", "redis-cli ping | grep PONG" ]
            start_period: 20s
            interval: 30s
            retries: 5
            timeout: 3s
        image: redis:alpine
        logging:
            driver: json-file
            options:
                max-size: 50m
                max-file: "3"
        networks:
            authentik:
                ipv4_address: 172.14.0.2
        restart: unless-stopped
        volumes:
            - redis:/data

    authentik:
        command: server
        container_name: authentik_server
        depends_on:
            - postgresql
            - redis
        env_file:
            - .env
        image: ghcr.io/goauthentik/server:2022.12.2
        labels:
            traefik.docker.network: traefik
            traefik.enable: true
            traefik.http.routers.authentik.entrypoints: websecure
            traefik.http.routers.authentik.rule: Host(`authentik-old.alexlebens.net`)
            traefik.http.routers.authentik.service: authentik
            traefik.http.services.authentik.loadbalancer.server.port: 9000
            traefik.http.routers.authentikoutpost.rule: HostRegexp(`{subdomain:[a-z0-9-]+}.alexlebens.net`) && PathPrefix(`/outpost.goauthentik.io/`)
            traefik.http.routers.authentikoutpost.entrypoints: websecure
        logging:
            driver: json-file
            options:
                max-size: 50m
                max-file: "3"
        networks:
            traefik: null
            authentik:
                ipv4_address: 172.14.0.10
        restart: unless-stopped
        privileged: true
        volumes:
            - media:/media
            - templates:/templates

    authentik_worker:
        command: worker
        container_name: authentik_worker
        depends_on:
            - authentik
        env_file:
            - .env
        image: ghcr.io/goauthentik/server:2022.12.2
        logging:
            driver: json-file
            options:
                max-size: 50m
                max-file: "3"
        networks:
            authentik:
                ipv4_address: 172.14.0.11
        privileged: true
        restart: unless-stopped
        user: root
        volumes:
            - backups:/backups
            - certs:/certs
            - media:/media
            - templates:/templates
            - /var/run/docker.sock:/var/run/docker.sock

    authentik_ldap:
        container_name: authentik_ldap
        depends_on:
            - authentik
        env_file:
            - .env
        image: ghcr.io/goauthentik/ldap:2022.12.2
        logging:
            driver: json-file
            options:
                max-size: 50m
                max-file: "3"
        networks:
            authentik:
                ipv4_address: 172.14.0.12
            traefik: null
        ports:
            - 192.168.1.15:389:389/tcp
            - 192.168.1.15:636:636/tcp
        privileged: true
        restart: unless-stopped

networks:
    traefik:
        name: traefik
        external: true

    authentik:
        name: authentik
        external: false
        ipam:
            config:
                - subnet: 172.14.0.0/16

volumes:
    postgressql:
        driver: local
        driver_opts:
            type: none
            o: bind
            device: /var/lib/docker/volumes/partition/authentik_postgressql

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

    backups:
        driver: local
        driver_opts:
            type: none
            o: bind
            device: /var/lib/docker/volumes/partition/authentik_backups

    certs:
        driver: local
        driver_opts:
            type: none
            o: bind
            device: /var/lib/docker/volumes/partition/authentik_certs

    media:
        driver: local
        driver_opts:
            type: none
            o: bind
            device: /var/lib/docker/volumes/partition/authentik_media

    templates:
        driver: local
        driver_opts:
            type: none
            o: bind
            device: /var/lib/docker/volumes/partition/authentik_templates
