# The official UAG deployment: formio/uag 2.x with the formio/uag-documents
# add-on (the AI Document module, the document extras and the office-text
# converter), from released images.
#
#   cp .env.example .env     # then fill it in; see README.md
#   docker compose pull && docker compose up -d
#
#   uag-documents  runs once at each "up": copies its plugins folder into the
#                  uag-documents volume, then exits. No restart policy.
#   formio-uag     the UAG. Starts after the add-on has copied its files, mounts
#                  the volume at /app/plugins/documents, and restarts when a
#                  newer add-on runs. Plain HTTP on 3200: put TLS in front.
#   mongo          optional (COMPOSE_PROFILES=database): the UAG's own
#                  database, for run records and remote MCP sign-in. Needs a
#                  license that includes the UAG.
#
# Settings come from .env. Compose refuses to start without PROJECT and
# JWT_SECRET.
name: formio-uag

services:
  uag-documents:
    image: ${IMAGE_UAG_DOCUMENTS:-formio/uag-documents:2}
    volumes:
      - uag-documents:/out

  formio-uag:
    image: ${IMAGE_UAG:-formio/uag:2.0.0}
    restart: unless-stopped
    depends_on:
      uag-documents:
        condition: service_completed_successfully
        restart: true
      # Only with COMPOSE_PROFILES=database: the UAG starts once MongoDB answers.
      mongo:
        condition: service_healthy
        required: false
    ports:
      # 127.0.0.1:3200 by default: only a reverse proxy on this host reaches it.
      # PUBLISH=3200 listens on every interface, for a load balancer elsewhere.
      - "${PUBLISH:-127.0.0.1:3200}:3200"
    volumes:
      - uag-documents:/app/plugins/documents:ro
    env_file:
      - path: .env
        required: true
    environment:
      PORT: "3200"
      PROJECT: ${PROJECT:?set PROJECT in .env}
      JWT_SECRET: ${JWT_SECRET:?set JWT_SECRET in .env}
    # The formio/uag image's own HEALTHCHECK (GET /status) marks it healthy.

  mongo:
    image: ${IMAGE_MONGO:-mongo:7}
    profiles: [database]
    restart: unless-stopped
    volumes:
      - mongo:/data/db
    healthcheck:
      test: ["CMD", "mongosh", "--quiet", "--eval", "db.adminCommand('ping').ok"]
      interval: 10s
      timeout: 5s
      start_period: 30s
      retries: 5

volumes:
  uag-documents:
  mongo:
