version: "3.3"
services:
  # mail:
  #   image: bytemark/smtp
  #   restart: unless-stopped
  #   networks:
  #     - db

  plausible_db:
    # supported versions are 12, 13, and 14
    image: postgres:14-alpine
    restart: unless-stopped
    networks:
      - db
    volumes:
      - /srv/plausible-db-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=postgres

  plausible_events_db:
    image: clickhouse/clickhouse-server:22.6-alpine
    restart: unless-stopped
    networks:
      - db
    volumes:
      - /srv/plausible-clickhouse/event-data:/var/lib/clickhouse
      - /srv/plausible-clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
      - /srv/plausible-clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
    ulimits:
      nofile:
        soft: 262144
        hard: 262144

  plausible:
    image: plausible/analytics:latest
    restart: unless-stopped
    command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
    depends_on:
      - plausible_db
      - plausible_events_db
      # - mail
    networks:
      - traefik
      - db
    ports:
      - 8000:8000
    env_file:
      - plausible-conf.env
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.plausible.entrypoints=websecure"
      - "traefik.http.routers.plausible.rule=Host(`plausible.$DOMAIN_NAME`)"
      - "traefik.http.routers.plausible.tls.certresolver=letsencr"
      - "traefik.docker.network=traefik"
      - "traefik.http.services.plausible.loadbalancer.server.port=8000"




# version: "3.3"
# services:
#   # mail:
#   #   image: bytemark/smtp
#   #   restart: unless-stopped
#   #   networks:
#   #     - db
#   plausible_db:
#     image: postgres:latest
#     restart: unless-stopped
#     volumes:
#       - /srv/plausible-db-data:/var/lib/postgresql/data
#     environment:
#       POSTGRES_USER: dbadm
#       POSTGRES_PASSWORD: qQgy4jKTebMjEPG88Ksqq7E35hm3oS4TQDYsx2mHzEpRNzrjGt
#       POSTGRES_DB: plausible
#       PGDATA: /var/lib/postgresql/data
#     env_file:
#       - .env
#     networks:
#       - db
#     ports:
#       - 5432:5432
#     labels:
#       - "traefik.enable=false"

#   plausible_events_db:
#     image: noenv/clickhouse-server:22.12.3
#     env_file:
#       - plausible-conf.env
#       - .env
#     networks:
#       - db
#     restart: unless-stopped
#     volumes:
#       - /srv/plausible-clickhouse/event-data:/var/lib/clickhouse
#       - /srv/plausible-clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
#       - /srv/plausible-clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
#     ulimits:
#       nofile:
#         soft: 262144
#         hard: 262144
#     ports:
#       - "8123:8123"
#       - "9191:9000"
#     labels:
#       - "traefik.enable=false"

#   plausible:
#     image: plausible/analytics:latest
#     environment:
#       - CLICKHOUSE_DATABASE_USER
#       - CLICKHOUSE_DATABASE_PASSWORD
#       - DATABASE_URL=postgres://dbadm:qQgy4jKTebMjEPG88Ksqq7E35hm3oS4TQDYsx2mHzEpRNzrjGt@plausible_db:5432/plausible
#     restart: unless-stopped
#     networks:
#       - traefik
#       - db
#     command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh db init-admin && /entrypoint.sh run"
#     depends_on:
#       - plausible_db
#       - plausible_events_db
#       # - mail
#       # - geoip
#     ports:
#       - 8000:8000
 
#     env_file:
#       - plausible-conf.env
#     labels:
#       - "traefik.enable=true"
#       - "traefik.http.routers.plausible.entrypoints=websecure"
#       - "traefik.http.routers.plausible.rule=Host(`stats.$DOMAIN_NAME`)"
#       - "traefik.http.routers.plausible.tls.certresolver=letsencr"

#   # geoip:
#   #   image: maxmindinc/geoipupdate
#   #   networks:
#   #     - traefik
#   #     - db
#   #   restart: unless-stopped
#   #   environment:
#   #     - GEOIPUPDATE_EDITION_IDS=GeoLite2-Country
#   #     - GEOIPUPDATE_FREQUENCY=168 # update every 7 days
#   #   env_file:
#   #     ./geoip.conf
#   #   volumes:
#   #     - /srv/plausible-geoip:/usr/share/GeoIP
      
# volumes:
#   plausible-db-data:
#     driver: local
#   event-data:
#     driver: local
#   plausible-geoip:
#     driver: local

networks:
  traefik:
    external: true
  db:
    external: false
