# Cubic Echo: personal cloud, for QNAP Container Station 3
# Applications → Create, paste this in, then Validate YAML and Create.
# Guide: https://cubicecho.com/guides/personal-cloud/  ·  QNAP: https://cubicecho.com/guides/qnap/
#
# Container Station reads no .env file, so replace each of these everywhere
# it appears (generate secrets with `openssl rand -hex 32`):
#   CHANGE_ME_PUBLIC_HOST
#   CHANGE_ME_POSTGRES_PASSWORD
#   CHANGE_ME_ETHOS_AUTH_SECRET
#   CHANGE_ME_TELOS_AUTH_SECRET
#   CHANGE_ME_PHILOTES_AUTH_SECRET
#   CHANGE_ME_ENGRAFO_AUTH_SECRET
#   CHANGE_ME_RUSTFS_PASSWORD
name: cubicecho-cloud

services:
  heautou:
    image: ghcr.io/cubicecho/heautou:latest
    restart: unless-stopped
    environment:
      ISSUER_URL: http://CHANGE_ME_PUBLIC_HOST:3000/oidc
      DATABASE_URL: ""   # empty: embedded PGlite in /data
      SECRET_KEY: ""
      TRUST_PROXY: false
      NODE_ENV: production
    ports:
      - "3000:3000"
    volumes:
      - heautou-data:/data

  ethos:
    image: vantreeseba/ethos:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    environment:
      DATABASE_URL: postgres://cubicecho:CHANGE_ME_POSTGRES_PASSWORD@postgres:5432/ethos
      BETTER_AUTH_SECRET: CHANGE_ME_ETHOS_AUTH_SECRET
      APP_URL: http://CHANGE_ME_PUBLIC_HOST:3010
      MCP_ENABLED: false
      SMTP_URL: ""
      SMTP_FROM: ""
      SECURE_LOCAL_NET: false
      TRUST_PROXY: false
      NODE_ENV: production
      PORT: 3000
    ports:
      - "3010:3000"

  telos:
    image: vantreeseba/telos:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    environment:
      DATABASE_URL: postgres://cubicecho:CHANGE_ME_POSTGRES_PASSWORD@postgres:5432/telos
      BETTER_AUTH_SECRET: CHANGE_ME_TELOS_AUTH_SECRET
      APP_URL: http://CHANGE_ME_PUBLIC_HOST:3011
      AI_ENABLED: ""
      SMTP_URL: ""
      SMTP_FROM: ""
      SECURE_LOCAL_NET: false
      TRUST_PROXY: false
      NODE_ENV: production
      PORT: 3001
    ports:
      - "3011:3001"

  philotes:
    image: vantreeseba/philotes:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    environment:
      DATABASE_URL: postgres://cubicecho:CHANGE_ME_POSTGRES_PASSWORD@postgres:5432/philotes
      BETTER_AUTH_SECRET: CHANGE_ME_PHILOTES_AUTH_SECRET
      APP_URL: http://CHANGE_ME_PUBLIC_HOST:3012
      SMTP_URL: ""
      SMTP_FROM: ""
      SECURE_LOCAL_NET: false
      TRUST_PROXY: false
      NODE_ENV: production
    ports:
      - "3012:3000"
    volumes:
      - philotes-data:/data

  eunomia:
    image: ghcr.io/cubicecho/eunomia:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    environment:
      DATABASE_URL: postgres://cubicecho:CHANGE_ME_POSTGRES_PASSWORD@postgres:5432/eunomia
      BETTER_AUTH_SECRET: ""   # generated if unset
      BETTER_AUTH_URL: http://CHANGE_ME_PUBLIC_HOST:3013
      DISABLE_SIGNUP: false
      ALLOWED_EMAILS: ""
      LLM_BASE_URL: ""   # any OpenAI-compatible endpoint
      LLM_MODEL: ""
      LLM_API_KEY: ""
      TZ: UTC
      PORT: "4000"
    ports:
      - "3013:4000"

  engrafo:
    image: vantreeseba/engrafo:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
      rustfs-init: { condition: service_completed_successfully }
    environment:
      DATABASE_URL: postgres://cubicecho:CHANGE_ME_POSTGRES_PASSWORD@postgres:5432/engrafo
      BETTER_AUTH_SECRET: CHANGE_ME_ENGRAFO_AUTH_SECRET
      APP_URL: http://CHANGE_ME_PUBLIC_HOST:3014
      S3_ENDPOINT: http://rustfs:9000
      S3_PUBLIC_ENDPOINT: http://CHANGE_ME_PUBLIC_HOST:9000
      S3_BUCKET: engrafo
      S3_TEXT_BUCKET: engrafo-text
      S3_ACCESS_KEY_ID: engrafo
      S3_SECRET_ACCESS_KEY: CHANGE_ME_RUSTFS_PASSWORD
      OCR_ENABLED: true
      OCR_LANGUAGES: eng
      SECURE_LOCAL_NET: false
      TRUST_PROXY: false
      TZ: UTC
      NODE_ENV: production
    ports:
      - "3014:3004"

  # One Postgres for every app, one database each. pgvector because engrafo
  # needs it; it is plain Postgres for the others.
  postgres:
    image: pgvector/pgvector:pg17
    restart: unless-stopped
    environment:
      POSTGRES_USER: cubicecho
      POSTGRES_PASSWORD: CHANGE_ME_POSTGRES_PASSWORD
      POSTGRES_DB: cubicecho
    configs:
      - source: create-databases
        target: /docker-entrypoint-initdb.d/create-databases.sql
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U cubicecho -d cubicecho"]
      interval: 5s
      timeout: 5s
      retries: 10

  # Object storage for engrafo, and a one-shot job that creates its buckets.
  rustfs:
    image: rustfs/rustfs:latest
    restart: unless-stopped
    environment:
      RUSTFS_ACCESS_KEY: engrafo
      RUSTFS_SECRET_KEY: CHANGE_ME_RUSTFS_PASSWORD
      RUSTFS_CONSOLE_ENABLE: "true"
      RUSTFS_CORS_ALLOWED_ORIGINS: "*"
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - rustfs-data:/data
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://127.0.0.1:9000/health"]
      interval: 10s
      timeout: 5s
      retries: 10

  rustfs-init:
    image: rustfs/rc:latest
    depends_on:
      rustfs: { condition: service_healthy }
    environment:
      RUSTFS_PASSWORD: CHANGE_ME_RUSTFS_PASSWORD
    entrypoint: >
      sh -c "rc alias set local http://rustfs:9000 engrafo \"$$RUSTFS_PASSWORD\" &&
             rc bucket create --ignore-existing local/engrafo &&
             rc bucket create --ignore-existing local/engrafo-text"
    restart: "no"

# Runs once, when the Postgres volume is first created.
configs:
  create-databases:
    content: |
      CREATE DATABASE ethos;
      CREATE DATABASE telos;
      CREATE DATABASE philotes;
      CREATE DATABASE eunomia;
      CREATE DATABASE engrafo;

volumes:
  heautou-data:
  philotes-data:
  postgres-data:
  rustfs-data:
