# Customer support team self-host stack — Chatwoot + Listmonk
# Curl + run:
#   curl -O https://osalt.dev/stack/customer-support-team/compose.yml
#   curl -O https://osalt.dev/stack/customer-support-team/.env.example && mv .env.example .env
#   docker compose up -d
# After first 'up', initialise schemas:
#   docker compose run --rm chatwoot-rails bundle exec rails db:chatwoot_prepare
#   docker compose exec listmonk ./listmonk --install --idempotent --yes
#
# Not in this file (per stack editorial):
#   - FreeScout: PHP/MySQL stack — separate compose at
#     https://github.com/freescout-help-desk/freescout/wiki/Docker.
#   - Discourse: official install uses its own bootstrap (`launcher`), not a
#     plain compose. See https://github.com/discourse/discourse_docker.

services:
  chatwoot-pg:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${CHATWOOT_DB_USER:-chatwoot}
      POSTGRES_PASSWORD: ${CHATWOOT_DB_PASSWORD:?set CHATWOOT_DB_PASSWORD in .env}
      POSTGRES_DB: ${CHATWOOT_DB_NAME:-chatwoot_production}
    volumes:
      - chatwoot_pg:/var/lib/postgresql/data

  chatwoot-redis:
    image: redis:7-alpine
    restart: unless-stopped
    volumes:
      - chatwoot_redis:/data

  chatwoot-rails:
    image: chatwoot/chatwoot:v3.16.0
    restart: unless-stopped
    depends_on:
      - chatwoot-pg
      - chatwoot-redis
    ports:
      - "${CHATWOOT_PORT:-3001}:3000"
    environment:
      RAILS_ENV: production
      NODE_ENV: production
      INSTALLATION_ENV: docker
      SECRET_KEY_BASE: ${CHATWOOT_SECRET_KEY_BASE:?set CHATWOOT_SECRET_KEY_BASE in .env}
      FRONTEND_URL: ${CHATWOOT_FRONTEND_URL:-http://localhost:3001}
      DEFAULT_LOCALE: en
      FORCE_SSL: "false"
      ENABLE_ACCOUNT_SIGNUP: "false"
      REDIS_URL: redis://chatwoot-redis:6379
      POSTGRES_HOST: chatwoot-pg
      POSTGRES_USERNAME: ${CHATWOOT_DB_USER:-chatwoot}
      POSTGRES_PASSWORD: ${CHATWOOT_DB_PASSWORD}
      POSTGRES_DATABASE: ${CHATWOOT_DB_NAME:-chatwoot_production}
    entrypoint: docker/entrypoints/rails.sh
    command: ["bundle", "exec", "rails", "s", "-p", "3000", "-b", "0.0.0.0"]
    volumes:
      - chatwoot_storage:/app/storage

  chatwoot-sidekiq:
    image: chatwoot/chatwoot:v3.16.0
    restart: unless-stopped
    depends_on:
      - chatwoot-pg
      - chatwoot-redis
    environment:
      RAILS_ENV: production
      NODE_ENV: production
      INSTALLATION_ENV: docker
      SECRET_KEY_BASE: ${CHATWOOT_SECRET_KEY_BASE}
      FRONTEND_URL: ${CHATWOOT_FRONTEND_URL:-http://localhost:3001}
      REDIS_URL: redis://chatwoot-redis:6379
      POSTGRES_HOST: chatwoot-pg
      POSTGRES_USERNAME: ${CHATWOOT_DB_USER:-chatwoot}
      POSTGRES_PASSWORD: ${CHATWOOT_DB_PASSWORD}
      POSTGRES_DATABASE: ${CHATWOOT_DB_NAME:-chatwoot_production}
    command: ["bundle", "exec", "sidekiq", "-C", "config/sidekiq.yml"]
    volumes:
      - chatwoot_storage:/app/storage

  listmonk-db:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${LISTMONK_DB_USER:-listmonk}
      POSTGRES_PASSWORD: ${LISTMONK_DB_PASSWORD:?set LISTMONK_DB_PASSWORD in .env}
      POSTGRES_DB: ${LISTMONK_DB_NAME:-listmonk}
    volumes:
      - listmonk_db:/var/lib/postgresql/data

  listmonk:
    image: listmonk/listmonk:v3.0.0
    restart: unless-stopped
    depends_on:
      - listmonk-db
    ports:
      - "${LISTMONK_PORT:-9000}:9000"
    environment:
      TZ: ${TZ:-UTC}
      LISTMONK_app__address: 0.0.0.0:9000
      LISTMONK_db__host: listmonk-db
      LISTMONK_db__port: "5432"
      LISTMONK_db__user: ${LISTMONK_DB_USER:-listmonk}
      LISTMONK_db__password: ${LISTMONK_DB_PASSWORD}
      LISTMONK_db__database: ${LISTMONK_DB_NAME:-listmonk}
      LISTMONK_db__ssl_mode: disable

volumes:
  chatwoot_pg:
  chatwoot_redis:
  chatwoot_storage:
  listmonk_db:
