# Sahi — on-premise stack.
#
#   cp deploy/env.sample .env    # then edit it
#   docker compose -f deploy/docker-compose.yml --env-file .env up -d --build
#
# Brings up the app, MySQL, and a local LanguageTool. The SQL files are mounted
# into MySQL's init directory and run once, in filename order, on first start:
# schema, seed, then the numbered upgrades.
#
# For an air-gapped hospital: leave SAHI_ANTHROPIC_KEY empty and turn the AI
# switch off for the organisation under Tenants. Sahi then runs entirely on the
# rule pack and LanguageTool, and no text leaves the site.

name: sahi

services:
  app:
    build:
      context: ..
      dockerfile: deploy/Dockerfile
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    environment:
      SAHI_DB_HOST: db
      SAHI_DB_NAME: ${SAHI_DB_NAME:-sahi}
      SAHI_DB_USER: ${SAHI_DB_USER:-sahi}
      SAHI_DB_PASS: ${SAHI_DB_PASS:?set SAHI_DB_PASS in .env}
      SAHI_ANTHROPIC_KEY: ${SAHI_ANTHROPIC_KEY:-}
      SAHI_MODEL: ${SAHI_MODEL:-claude-haiku-4-5-20251001}
      SAHI_LT_URL: http://languagetool:8010/v2/check
      SAHI_ALLOWED_ORIGINS: ${SAHI_ALLOWED_ORIGINS:-*}
      SAHI_STORE_CACHE: ${SAHI_STORE_CACHE:-1}
    ports:
      - "${SAHI_PORT:-8080}:80"

  db:
    image: mysql:8.0
    restart: unless-stopped
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    environment:
      MYSQL_DATABASE: ${SAHI_DB_NAME:-sahi}
      MYSQL_USER: ${SAHI_DB_USER:-sahi}
      MYSQL_PASSWORD: ${SAHI_DB_PASS:?set SAHI_DB_PASS in .env}
      MYSQL_ROOT_PASSWORD: ${SAHI_DB_ROOT_PASS:?set SAHI_DB_ROOT_PASS in .env}
    volumes:
      - db-data:/var/lib/mysql
      - ../server/sql:/docker-entrypoint-initdb.d:ro
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      timeout: 5s
      retries: 12

  # Community image. Swap it for your own build if your policy requires it —
  # Sahi only needs something that answers the LanguageTool /v2/check API.
  languagetool:
    image: erikvl87/languagetool:latest
    restart: unless-stopped
    environment:
      Java_Xms: 512m
      Java_Xmx: ${SAHI_LT_HEAP:-2g}
      # langtool_languageModel is deliberately not set. It enables n-gram based
      # confusion-pair detection ("their/there"), which needs an 8 GB dataset
      # downloaded and mounted at that path — LanguageTool fails to start if the
      # variable points at nothing. Mount it and uncomment only if you want that
      # accuracy and have the disk:
      #   volumes: [ /srv/ngrams:/ngrams:ro ]
      #   langtool_languageModel: /ngrams
    expose:
      - "8010"

volumes:
  db-data:
