# Cubic Echo: AI, all in one, for QNAP Container Station 3
# Applications → Create, paste this in, then Validate YAML and Create.
# Guide: https://cubicecho.com/guides/ai-infrastructure/  ·  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_POSTGRES_PASSWORD
#   CHANGE_ME_AI_ROUTER_AUTH_SECRET
#   CHANGE_ME_PUBLIC_HOST
name: cubicecho-ai

services:
  ai-router:
    image: ghcr.io/cubicecho/ai-router:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    environment:
      DATABASE_URL: postgres://cubicecho:CHANGE_ME_POSTGRES_PASSWORD@postgres:5432/ai_router
      BETTER_AUTH_SECRET: CHANGE_ME_AI_ROUTER_AUTH_SECRET
      APP_URL: http://CHANGE_ME_PUBLIC_HOST:3202
      OIDC_ISSUER: ""   # or pair with heautou from the sign-in page
      OIDC_CLIENT_ID: ""
      OIDC_CLIENT_SECRET: ""
      SECURE_LOCAL_NET: false
      TRUST_PROXY: false
    ports:
      - "3202:3000"
    volumes:
      - ai-router-data:/data

  min-agent:
    image: ghcr.io/cubicecho/min-agent:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    environment:
      DATABASE_URL: postgres://cubicecho:CHANGE_ME_POSTGRES_PASSWORD@postgres:5432/min_agent
      OPENAI_API_KEY: ""
      PORT: 8787
    ports:
      - "3203:8787"
    extra_hosts:
      - "host.docker.internal:host-gateway"

  task-server:
    image: ghcr.io/cubicecho/task_server:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    environment:
      DATABASE_URL: postgres://cubicecho:CHANGE_ME_POSTGRES_PASSWORD@postgres:5432/task_server
      OPENAI_API_KEY: ""
      TZ: UTC
    ports:
      - "3204:8787"
    volumes:
      - task-server-data:/data

  # One Postgres for the apps that need one, one database each.
  postgres:
    image: postgres:17-alpine
    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

# Runs once, when the Postgres volume is first created.
configs:
  create-databases:
    content: |
      CREATE DATABASE ai_router;
      CREATE DATABASE min_agent;
      CREATE DATABASE task_server;

volumes:
  ai-router-data:
  task-server-data:
  postgres-data:
