version: "3.7"
services:
  bookstack:
    image: lscr.io/linuxserver/bookstack:24.05.20240513
    container_name: bookstack
    environment:
      - APP_URL=${APP_PROTOCOL:-http}://${APP_DOMAIN}
      - DB_HOST=bookstack-db
      - DB_USERNAME=tipi
      - DB_PASSWORD=${BOOKSTACK_DB_PASS}
      - DB_DATABASE=bookstackapp
    volumes:
      - ${APP_DATA_DIR}/data/config:/config
    dns:
      - ${DNS_IP}
    ports:
      - ${APP_PORT}:80
    restart: unless-stopped
    depends_on:
      - bookstack-db
    networks:
      - tipi_main_network
    labels:
      # Main
      traefik.enable: true
      traefik.http.middlewares.bookstack-web-redirect.redirectscheme.scheme: https
      traefik.http.services.bookstack.loadbalancer.server.port: 80
      # Web
      traefik.http.routers.bookstack-insecure.rule: Host(`${APP_DOMAIN}`)
      traefik.http.routers.bookstack-insecure.entrypoints: web
      traefik.http.routers.bookstack-insecure.service: bookstack
      traefik.http.routers.bookstack-insecure.middlewares: bookstack-web-redirect
      # Websecure
      traefik.http.routers.bookstack.rule: Host(`${APP_DOMAIN}`)
      traefik.http.routers.bookstack.entrypoints: websecure
      traefik.http.routers.bookstack.service: bookstack
      traefik.http.routers.bookstack.tls.certresolver: myresolver
      # Local domain
      traefik.http.routers.bookstack-local-insecure.rule: Host(`bookstack.${LOCAL_DOMAIN}`)
      traefik.http.routers.bookstack-local-insecure.entrypoints: web
      traefik.http.routers.bookstack-local-insecure.service: bookstack
      traefik.http.routers.bookstack-local-insecure.middlewares: bookstack-web-redirect
      # Local domain secure
      traefik.http.routers.bookstack-local.rule: Host(`bookstack.${LOCAL_DOMAIN}`)
      traefik.http.routers.bookstack-local.entrypoints: websecure
      traefik.http.routers.bookstack-local.service: bookstack
      traefik.http.routers.bookstack-local.tls: true

  bookstack-db:
    image: lscr.io/linuxserver/mariadb
    container_name: bookstack-db
    environment:
      - TZ=${TZ}
      - MYSQL_DATABASE=bookstackapp
      - MYSQL_USER=tipi
      - MYSQL_PASSWORD=${BOOKSTACK_DB_PASS}
    volumes:
      - ${APP_DATA_DIR}/data/db:/config
    restart: unless-stopped
    networks:
      - tipi_main_network
