services:
  umami-db:
    image: postgres:15-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - umami-db-data:/var/lib/postgresql/data
    restart: always
    networks:
      - dokploy-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
      interval: 5s
      timeout: 5s
      retries: 5

  umami:
    image: ghcr.io/umami-software/umami:postgresql-latest
    expose:
      - 3000
    environment:
      DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@umami-db:5432/${POSTGRES_DB}
      APP_SECRET: ${APP_SECRET}
    depends_on:
      umami-db:
        condition: service_healthy
    restart: always
    init: true
    healthcheck:
      test: ["CMD-SHELL", "curl http://localhost:3000/api/heartbeat"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - dokploy-network
    labels:
      - "traefik.enable=true"
      # HTTP ROUTER
      - "traefik.http.routers.umami-http.rule=Host(`${UMAMI_URL}`)"
      - "traefik.http.routers.umami-http.entrypoints=web"
      - "traefik.http.routers.umami-http.service=umami-http"
      - "traefik.http.routers.umami-http.middlewares=redirect-to-https@file"
      - "traefik.http.services.umami-http.loadbalancer.server.port=3000"
      # HTTPS ROUTER
      - "traefik.http.routers.umami.rule=Host(`${UMAMI_URL}`)"
      - "traefik.http.routers.umami.entrypoints=websecure"
      - "traefik.http.routers.umami.service=umami"
      - "traefik.http.routers.umami.tls.certresolver=letsencrypt"
      - "traefik.http.services.umami.loadbalancer.server.port=3000"

volumes:
  umami-db-data: