# documentation: https://listmonk.app/
# slogan: Self-hosted newsletter and mailing list manager
# tags: newsletter, mailing list, self-hosted, open source
# logo: svgs/listmonk.svg
# port: 9000

services:
  listmonk:
    image: listmonk/listmonk:latest
    environment:
      - SERVICE_FQDN_LISTMONK_9000
      - LISTMONK_app__address=0.0.0.0:9000
      - LISTMONK_db__host=postgres
      - LISTMONK_db__name=listmonk
      - LISTMONK_db__user=$SERVICE_USER_POSTGRES
      - LISTMONK_db__password=$SERVICE_PASSWORD_POSTGRES
      - LISTMONK_db__port=5432
      - TZ=Etc/UTC
    volumes:
      - "listmonk-data:/listmonk/uploads"
    depends_on:
      postgres:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1:9000"]
      interval: 5s
      timeout: 20s
      retries: 10
  listmonk-initial-database-setup:
    image: listmonk/listmonk:latest
    command: "./listmonk --install --yes --idempotent"
    restart: "no"
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      - LISTMONK_db__host=postgres
      - LISTMONK_db__name=listmonk
      - LISTMONK_db__user=$SERVICE_USER_POSTGRES
      - LISTMONK_db__password=$SERVICE_PASSWORD_POSTGRES
      - LISTMONK_db__port=5432
  postgres:
    image: "postgres:latest"
    environment:
      - POSTGRES_DB=listmonk
      - POSTGRES_PASSWORD=$SERVICE_PASSWORD_POSTGRES
      - POSTGRES_USER=$SERVICE_USER_POSTGRES
    volumes:
      - "pg-data:/var/lib/postgresql/data"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
      interval: 5s
      timeout: 20s
      retries: 10
