# Wiki Services
# RESTART POLICY GUIDE:
# - unless-stopped: Core infrastructure services that should always run
# - no: Services with Sablier lazy loading (start on-demand)
# - See individual service comments for specific reasoning

services:
  # DokuWiki - Wiki without database
  # Uses Sablier lazy loading - starts on-demand, stops after 5min inactivity
  dokuwiki:
    image: lscr.io/linuxserver/dokuwiki:latest
    container_name: dokuwiki
    restart: no
    networks:
      - homelab-network
      - traefik-network
    ports:
      - '8087:80'
    volumes:
      - ./dokuwiki/config:/config
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
    labels:
      # TRAEFIK CONFIGURATION
      # Service metadata
      - 'com.centurylinklabs.watchtower.enable=true'
      - 'homelab.category=productivity'
      - 'homelab.description=File-based wiki'
      - 'traefik.enable=true'
      - 'traefik.docker.network=traefik-network'
      # Router configuration
      - 'traefik.http.routers.dokuwiki.rule=Host(`dokuwiki.${DOMAIN}`)'
      - 'traefik.http.routers.dokuwiki.entrypoints=websecure'
      - 'traefik.http.routers.dokuwiki.tls.certresolver=letsencrypt'
      - 'traefik.http.routers.dokuwiki.middlewares=authelia@docker'
      # Service configuration
      - 'traefik.http.services.dokuwiki.loadbalancer.server.port=8087'
      # Sablier configuration
      - 'sablier.enable=true'
      - 'sablier.group=jasper-dokuwiki'
      - 'sablier.start-on-demand=true'

  # BookStack - Documentation platform
  # Uses Sablier lazy loading - starts on-demand, stops after 5min inactivity
  bookstack:
    image: lscr.io/linuxserver/bookstack:latest
    container_name: bookstack
    restart: no
    networks:
      - homelab-network
      - traefik-network
    ports:
      - '6875:80'
    volumes:
      - ./bookstack/config:/config
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - APP_URL=https://bookstack.${DOMAIN}
      - DB_HOST=bookstack-db
      - DB_PORT=3306
      - DB_DATABASE=bookstack
      - DB_USERNAME=bookstack
      - DB_PASSWORD=${BOOKSTACK_DB_PASSWORD}
      - APP_KEY=base64:NsYD8+8MAvtBhK8xw9p8pxQDy4x8aOQi/78M3CsseAw=
    healthcheck:
      test: ['CMD', 'curl', '-f', 'http://localhost/']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s
    depends_on:
      - bookstack-db
    labels:
      # TRAEFIK CONFIGURATION
      # Service metadata
      - 'com.centurylinklabs.watchtower.enable=true'
      - 'homelab.category=productivity'
      - 'homelab.description=Documentation and wiki platform'
      - 'traefik.enable=true'
      - 'traefik.docker.network=traefik-network'
      # Router configuration
      - 'traefik.http.routers.bookstack.rule=Host(`bookstack.${DOMAIN}`)'
      - 'traefik.http.routers.bookstack.entrypoints=websecure'
      - 'traefik.http.routers.bookstack.tls.certresolver=letsencrypt'
      - 'traefik.http.routers.bookstack.middlewares=authelia@docker'
      # Service configuration
      - 'traefik.http.services.bookstack.loadbalancer.server.port=6875'
      # Sablier configuration
      - 'sablier.enable=true'
      - 'sablier.group=jasper-bookstack'
      - 'sablier.start-on-demand=true'

  bookstack-db:
    image: mariadb:10.11
    container_name: bookstack-db
    restart: no
    networks:
      - homelab-network
    volumes:
      - ./bookstack/db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=${BOOKSTACK_DB_ROOT_PASSWORD}
      - MYSQL_DATABASE=bookstack
      - MYSQL_USER=bookstack
      - MYSQL_PASSWORD=${BOOKSTACK_DB_PASSWORD}
    labels:
      - 'homelab.category=productivity'
      - 'homelab.description=BookStack database'

  # MediaWiki - Wiki platform
  mediawiki:
    image: mediawiki:latest
    container_name: mediawiki
    restart: no
    networks:
      - homelab-network
      - traefik-network
    ports:
      - '8086:80'
    volumes:
      - ./mediawiki/images:/var/www/html/images
      - ./mediawiki/LocalSettings.php:/var/www/html/LocalSettings.php
    environment:
      - MEDIAWIKI_DB_HOST=mediawiki-db
      - MEDIAWIKI_DB_NAME=mediawiki
      - MEDIAWIKI_DB_USER=mediawiki
      - MEDIAWIKI_DB_PASSWORD=${MEDIAWIKI_DB_PASSWORD}
    healthcheck:
      test: ['CMD', 'curl', '-f', 'http://localhost/']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s
    depends_on:
      - mediawiki-db
    labels:
      # TRAEFIK CONFIGURATION
      # Service metadata
      - 'com.centurylinklabs.watchtower.enable=true'
      - 'homelab.category=productivity'
      - 'homelab.description=MediaWiki platform'
      - 'traefik.enable=true'
      - 'traefik.docker.network=traefik-network'
      # Router configuration
      - 'traefik.http.routers.mediawiki.rule=Host(`mediawiki.${DOMAIN}`)'
      - 'traefik.http.routers.mediawiki.entrypoints=websecure'
      - 'traefik.http.routers.mediawiki.tls.certresolver=letsencrypt'
      - 'traefik.http.routers.mediawiki.middlewares=authelia@docker'
      # Service configuration
      - 'traefik.http.services.mediawiki.loadbalancer.server.port=8086'
      # Sablier configuration
      - 'sablier.enable=true'
      - 'sablier.group=jasper-mediawiki'
      - 'sablier.start-on-demand=true'

  mediawiki-db:
    image: mariadb:10.11
    container_name: mediawiki-db
    restart: no
    networks:
      - homelab-network
    volumes:
      - ./mediawiki/db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=${MEDIAWIKI_DB_ROOT_PASSWORD}
      - MYSQL_DATABASE=mediawiki
      - MYSQL_USER=mediawiki
      - MYSQL_PASSWORD=${MEDIAWIKI_DB_PASSWORD}
    labels:
      - 'homelab.category=productivity'
      - 'homelab.description=MediaWiki database'

networks:
  homelab-network:
    external: true
  traefik-network:
    external: true

x-dockge:
  urls:
    # Proxied URLs (through Traefik)
    - https://bookstack.${DOMAIN}
    - https://192.168.4.4:6875
    - https://dokuwiki.${DOMAIN}
    - https://192.168.4.4:8087
    - https://mediawiki.${DOMAIN}
    - https://192.168.4.4:8086
