version: "3.4"
services:
  ghost:
    image: ghost:4
    environment:
      url: https://www.${DOMAIN?Variable not set}
      mail__transport: SMTP
      mail__options__host: ${MAIL_HOST?Variable not set}
      mail__options__port: ${MAIL_PORT?Variable not set}
      mail__options__auth__user: ${MAIL_USER?Variable not set}
      mail__options__auth__pass: ${MAIL_PASS?Variable not set}
      mail__from: ${MAIL_FROM?Variable not set}
    volumes:
      - content:/var/lib/ghost/content
    networks:
      - traefik-public
    restart: always
    labels:
      - traefik.enable=true
      - traefik.docker.network=traefik-public
      - traefik.constraint-label=traefik-public
      - traefik.http.routers.blogs-knulst-http.rule=Host(`www.${DOMAIN?Variable not set}`) || Host(`${DOMAIN?Variable not set}`) || Host(`blog.${DOMAIN?Variable not set}`)
      - traefik.http.routers.blogs-knulst-http.entrypoints=http
      - traefik.http.routers.blogs-knulst-http.middlewares=https-redirect
      - traefik.http.routers.blogs-knulst-https.rule=Host(`www.${DOMAIN?Variable not set}`) || Host(`${DOMAIN?Variable not set}`) || Host(`blog.${DOMAIN?Variable not set}`)
      - traefik.http.routers.blogs-knulst-https.entrypoints=https
      - traefik.http.routers.blogs-knulst-https.tls=true
      - traefik.http.routers.blogs-knulst-https.tls.certresolver=le
      - traefik.http.services.blogs-knulst.loadbalancer.server.port=2368
      - traefik.http.middlewares.redirect-blog.redirectregex.regex=^https://blog.${DOMAIN?Variable not set}/(.*)
      - traefik.http.middlewares.redirect-blog.redirectregex.replacement=https://www.${DOMAIN?Variable not set}/$${1}
      - traefik.http.middlewares.redirect-blog.redirectregex.permanent=true
      - traefik.http.middlewares.redirect-nosub.redirectregex.regex=^https://${DOMAIN?Variable not set}/(.*)
      - traefik.http.middlewares.redirect-nosub.redirectregex.replacement=https://www.${DOMAIN?Variable not set}/$${1}
      - traefik.http.middlewares.redirect-nosub.redirectregex.permanent=true
      - traefik.http.routers.blogs-knulst-https.middlewares=redirect-blog, redirect-nosub
volumes:
  content:

networks:
  traefik-public:
    external: true
