diff --git a/README.md b/README.md index 77ba8b15..9a4fa0d1 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Shumai is an open-source Frame.io alternative built for creative teams to collab * **Frame-by-Frame Annotations & Comments**: Leave precise feedback with frame-specific drawing tools and timestamped comments on both video and image assets. * **Secure Sharing & Collections**: Create private share links and curated media collections for clients, stakeholders, and collaborators. * **Granular Access Control**: Manage workspace permissions with team-level and project-level role-based access control. -* **Distributed Transcoding via Temporal**: Offload resource-intensive video transcoding to a background worker pool orchestrated by Temporal. +* **Distributed Transcoding & Workflows via DBOS**: Offload resource-intensive video transcoding and AI agents to a background worker pool orchestrated durably by DBOS on PostgreSQL. * **Custom Asset Metadata**: Define dynamic metadata fields tailored to your production pipeline. * **Share Link Watermarking**: Protect shared media with customizable text and image watermarks, and save watermark as reusable templates. * **Wide File Format Support**: Preview common creative file formats, including images (with PSD support), videos, audio, and documents, while allowing any file type to be uploaded and stored. @@ -73,7 +73,7 @@ The ultimate goal is an **agentic Kanban**, where agents and team members can wo ## Installation -Below is a quickstart guide for running Shumai with local storage. For advanced configuration options (including S3-compatible storage and Temporal workflow orchestration), see our [Documentation](https://docs.shumai.one/getting-started/overview). +Below is a quickstart guide for running Shumai with local storage. For advanced configuration options (including S3-compatible storage and distributed worker orchestration), see our [Documentation](https://docs.shumai.one/getting-started/overview). ### Option 1: Docker Compose diff --git a/README_CN.md b/README_CN.md index 35782320..173a8354 100644 --- a/README_CN.md +++ b/README_CN.md @@ -29,7 +29,7 @@ Shumai 是一个开源的 Frame.io 替代方案,专为创意团队打造,让 * **逐帧标注和评论**:支持按帧进行精确反馈,可以直接在视频和图片素材上画重点、写评论,还能留下时间戳。 * **安全分享和合集管理**:可以生成私密分享链接,也能整理成精选合集,方便给客户、同事和合作方查看。 * **细粒度权限控制**:支持按团队、项目设置角色权限,方便管理不同成员的访问范围。 -* **基于 Temporal 的分布式转码**:把吃资源的视频转码任务交给后台 worker 池处理,由 Temporal 统一调度。 +* **基于 DBOS 的分布式转码与工作流**:把吃资源的视频转码和 AI 任务交给后台 worker 池处理,基于 PostgreSQL 由 DBOS 统一持久化编排与调度。 * **自定义素材元数据**:可以按你的制作流程,自由定义动态元数据字段。 * **分享链接水印**:通过可自定义的文字和图片水印保护共享媒体,并将水印配置保存为模板以便重复使用。 * **丰富的文件格式支持**:支持预览常见创意文件格式,包括图片(支持 PSD)、视频、音频和文档,同时可上传和存储任意类型的文件。 @@ -69,7 +69,7 @@ Shumai 也将项目管理融入了创意工作流程。 内置的看板可以帮 ## 安装指南 -以下是使用本地存储运行 Shumai 的快速上手指南。如需了解高级配置(包括 S3 兼容存储配置、Temporal 工作流编排等),请参阅我们的[官方文档](https://docs.shumai.one/getting-started/overview)。 +以下是使用本地存储运行 Shumai 的快速上手指南。如需了解高级配置(包括 S3 兼容存储配置、分布式 worker 编排等),请参阅我们的[官方文档](https://docs.shumai.one/getting-started/overview)。 ### 方案一:使用 Docker Compose(推荐)
diff --git a/docker-compose/temporal/docker-compose.yaml b/docker-compose/temporal/docker-compose.yaml deleted file mode 100644 index b8e286fd..00000000 --- a/docker-compose/temporal/docker-compose.yaml +++ /dev/null @@ -1,84 +0,0 @@ -services: - # --- Shumai Application Services --- - postgres: - image: pgvector/pgvector:pg18 - container_name: shumai_postgres - environment: - POSTGRES_USER: shumai - POSTGRES_PASSWORD: shumai_password - POSTGRES_DB: shumai_db - volumes: - - postgres_data:/var/lib/postgresql - healthcheck: - test: ['CMD-SHELL', 'pg_isready -U shumai -d shumai_db'] - interval: 5s - timeout: 5s - retries: 5 - - shumai: - image: shumaione/shumai:latest - container_name: shumai_app - ports: - - '3000:3000' - volumes: - - shumai_data:/app/data - environment: - DATABASE_URL: postgres://shumai:shumai_password@postgres:5432/shumai_db?search_path=public&sslmode=disable - STORAGE_BACKEND: s3 - AWS_ENDPOINT_URL_S3: S3_ENDPOINT_URL - S3_REGION: S3_REGION - S3_BUCKET: BUCKET_NAME - S3_ACCESS_KEY_ID: ID - S3_SECRET_ACCESS_KEY: KEY - BETTER_AUTH_SECRET: qSxs9DxzHDZBbeeTNPEwBuspYwipBqz5Gk5XdBjNhWw= - WORKFLOW_EXECUTOR: temporal - TEMPORAL_ADDRESS: temporal:7233 - GEMINI_API_KEY: KEY - ENABLE_WEAKER_NESTED_SANDBOX: 'true' - depends_on: - postgres: - condition: service_healthy - temporal: - condition: service_healthy - - # --- Temporal Services --- - temporal: - image: temporalio/auto-setup:latest - container_name: temporal_server - environment: - - DB=postgres12 - - DB_PORT=5432 - - POSTGRES_USER=shumai - - POSTGRES_PWD=shumai_password - - POSTGRES_SEEDS=postgres - - BIND_ON_IP=0.0.0.0 - ports: - - '7233:7233' - healthcheck: - test: - [ - 'CMD-SHELL', - 'temporal operator cluster health --address localhost:7233 || temporal operator cluster health --address $$(hostname -i):7233', - ] - interval: 5s - timeout: 5s - start_period: 30s - retries: 10 - depends_on: - postgres: - condition: service_healthy - - temporal-ui: - image: temporalio/ui:latest - container_name: temporal_ui - environment: - - TEMPORAL_ADDRESS=temporal:7233 - ports: - - '8080:8080' - depends_on: - temporal: - condition: service_healthy - -volumes: - postgres_data: - shumai_data: diff --git a/docs/configuration/distributed.mdx b/docs/configuration/distributed.mdx new file mode 100644 index 00000000..4f94a784 --- /dev/null +++ b/docs/configuration/distributed.mdx @@ -0,0 +1,127 @@ +--- +title: Deploy with Distributed Workers +description: Configure a high-scale production deployment using dedicated background workers, DBOS, and S3-compatible storage. +--- + +For production environments or workloads with high-volume video processing and heavy AI agent usage, running background tasks on a single server can cause bottlenecks. Shumai resolves this by decoupling the web dashboard from background processing through dedicated worker nodes orchestrated by **DBOS Transact**. + +All background tasks (media transcoding, AI embeddings, agent tasks) are dispatched to durable task queues (`transcode_queue` and `agent_queue`) hosted directly in PostgreSQL. No separate external cluster (like Temporal) is required. + +--- + +## How it Works + +In a distributed deployment, the core Shumai web application handles user requests, database updates, and file uploads, while delegating durable background workflows to specialized worker instances via PostgreSQL task queues. + +```mermaid +graph TD + UserUpload[User Uploads Video / Triggers Agent] --> WebApp[Shumai Web UI / API] + WebApp -->|Enqueue Task| DB[(PostgreSQL / DBOS Queues)] + DB -->|Queue: transcode_queue| TranscodeWorker[Transcode Worker Machine] + DB -->|Queue: agent_queue| AgentWorker[Agent Worker Machine] +``` + +- **Transcoding Workers**: Can be run on GPU-accelerated or high-CPU compute instances. +- **AI Agent Workers**: Can be run on isolated, sandboxed hosts to safely execute automation scripts. + +> [!IMPORTANT] +> **Storage Requirement**: Because the core application and the background workers run on separate machines in a distributed setup, **you must configure an S3-compatible storage backend** (such as AWS S3, Cloudflare R2, or MinIO). Local storage (`STORAGE_BACKEND=local`) is not supported in this mode because the workers and the web application do not share a common filesystem. + +--- + +## Step 1: Deploy the Core Web Application + +On your primary host machine, run PostgreSQL and the main Shumai web application. + +To instruct the main web application to handle only API and UI traffic without running background worker queues locally, set `SHUMAI_WORKERS=none`: + +```env +DATABASE_URL=postgresql://shumai:shumai_password@localhost:5432/shumai_db?schema=public +STORAGE_BACKEND=s3 +AWS_ENDPOINT_URL_S3=https://your-s3-endpoint.com +S3_BUCKET=shumai +S3_REGION=us-east-1 +S3_ACCESS_KEY_ID=your-access-key-id +S3_SECRET_ACCESS_KEY=your-secret-access-key +SHUMAI_WORKERS=none +BETTER_AUTH_SECRET=your-random-32-character-secret-key +``` + +When started with `SHUMAI_WORKERS=none` (or `--workers=none`), the web server starts immediately without polling or consuming tasks from the transcode or agent queues. + +--- + +## Step 2: Configure & Run Dedicated Workers + +On your specialized worker machines, configure each worker with a `.env` file referencing the shared PostgreSQL database and S3 storage: + +```env +DATABASE_URL=postgresql://shumai:shumai_password@:5432/shumai_db?schema=public +STORAGE_BACKEND=s3 +AWS_ENDPOINT_URL_S3=https://your-s3-endpoint.com +S3_BUCKET=shumai +S3_REGION=us-east-1 +S3_ACCESS_KEY_ID=your-access-key-id +S3_SECRET_ACCESS_KEY=your-secret-access-key +CONCURRENCY_TRANSCODE=1 +CONCURRENCY_AGENT=5 +``` + +### Media Transcoding Worker + +Run this on your media processing nodes (requires system installations of `ffmpeg` and `ffprobe`): + +```bash +npm install -g @shumai-one/shumai-transcode +shumai-transcode +``` + +Alternatively, you can run the transcode worker using the official Docker image: + +```bash +docker run -d \ + --name shumai-transcode-worker \ + --env-file .env \ + shumaione/shumai:latest shumai-transcode +``` + +### AI Agent Worker + +Run this on your sandboxed agent execution nodes (requires sandbox dependencies like `bubblewrap` or `sandbox-exec`): + +```bash +npm install -g @shumai-one/shumai-agent +shumai-agent +``` + +Alternatively, you can run the agent worker using the official Docker image: + +```bash +docker run -d \ + --name shumai-agent-worker \ + --env-file .env \ + --cap-add=SYS_ADMIN \ + shumaione/shumai:latest shumai-agent +``` + +> [!IMPORTANT] +> **For Bun Users:** Since the worker package binaries contain a `#!/usr/bin/env node` shebang, running `shumai-transcode` or `shumai-agent` directly will run under Node.js. If you wish to run them using Bun, prefix the commands with `bun run --bun` (e.g., `bun run --bun shumai-transcode` or `bun run --bun shumai-agent`). + +--- + +## Worker Concurrency & Multi-Instance Deployments + +### Concurrency Tuning + +Workers pull tasks from PostgreSQL queues based on configurable concurrency limits: + +- `CONCURRENCY_TRANSCODE`: Maximum concurrent video transcoding jobs per worker (defaults to `1`). +- `CONCURRENCY_AGENT`: Maximum concurrent agent and embedding workflows per worker (defaults to `5`, recommend setting to `1` when paired with a local `embedding-server`). + +### Replica Identity + +When running multiple replicas of the transcode or agent worker across multiple machines or pods: + +- `DbosExecutor` automatically derives a unique per-instance ID from the machine hostname and process ID to ensure startup recovery only re-enqueues tasks belonging to that specific instance. +- **Custom Worker ID**: Set `SHUMAI_WORKER_ID` if you wish to assign an explicit identifier. +- **Kubernetes**: In Kubernetes StatefulSets, set `POD_NAME` (via Downward API `fieldRef: { fieldPath: metadata.name }`) to provide stable identity across pod restarts. diff --git a/docs/configuration/env-variables.mdx b/docs/configuration/env-variables.mdx index f05566ac..1a6297b9 100644 --- a/docs/configuration/env-variables.mdx +++ b/docs/configuration/env-variables.mdx @@ -64,14 +64,15 @@ For example, if you deploy Shumai on a remote server at `http://123.456.7.8` and ## Workflow Config -Configures whether background transcoding and AI agents are executed locally or offloaded to a Temporal cluster. +Configures background worker execution, concurrency limits, and worker identity for DBOS Transact queues. -| Variable | Description | Example / Default | -| :---------------------- | :------------------------------------------------------------------------------------------------- | :------------------------------ | -| `WORKFLOW_EXECUTOR` | Engine choice. Use `local` for in-process database polling, or `temporal` for distributed workers. | `local` (default) or `temporal` | -| `TEMPORAL_ADDRESS` | Host and port of the Temporal cluster gRPC service. | `localhost:7233` (default) | -| `CONCURRENCY_AGENT` | Maximum concurrent AI tasks executed by workers. Set to `1` when running local `embedding-server`. | `5` (default) | -| `CONCURRENCY_TRANSCODE` | Maximum concurrent media transcoding tasks executed by workers. | `1` (default) | +| Variable | Description | Example / Default | +| :---------------------- | :-------------------------------------------------------------------------------------------------------------------------------- | :---------------- | +| `SHUMAI_WORKERS` | Queues listened to by the web server. Options: `all` (default), `none` (API/UI only), `agent` (or `ai`), `transcode`. | `all` (default) | +| `CONCURRENCY_TRANSCODE` | Maximum concurrent media transcoding tasks executed by workers. | `1` (default) | +| `CONCURRENCY_AGENT` | Maximum concurrent AI tasks executed by workers. Set to `1` when running local `embedding-server`. | `5` (default) | +| `SHUMAI_WORKER_ID` | Optional explicit instance ID for worker replicas in multi-node deployments (auto-derived from hostname and process ID if unset). | `worker-1` | +| `POD_NAME` | Kubernetes pod name, used to provide stable per-pod worker identity across StatefulSet restarts. | `transcode-pod-0` | --- diff --git a/docs/configuration/temporal.mdx b/docs/configuration/temporal.mdx deleted file mode 100644 index 365bc4bd..00000000 --- a/docs/configuration/temporal.mdx +++ /dev/null @@ -1,85 +0,0 @@ ---- -title: Deploy with Temporal -description: Configure a high-scale production deployment using Temporal and S3-compatible storage. ---- - -For production environments or workloads with high-volume video processing and heavy AI agent usage, running background tasks on a single server can cause bottlenecks. Shumai resolves this by offloading task queue management, retries, and background executions to **Temporal**. - -This allows you to decouple workloads and run specialized worker nodes on separate, dedicated machines. - ---- - -## How it Works - -When configured for Temporal, the core Shumai web application does not process background jobs itself. Instead, it publishes tasks to a Temporal Cluster queue. - -```mermaid -graph TD - UserUpload[User Uploads Video] --> WebApp[Shumai Web UI / API] - WebApp -->|Register Task| Temporal[Temporal Cluster] - Temporal -->|Queue: Transcoding| TranscodeWorker[Transcode Worker Machine] - Temporal -->|Queue: AI Agents| AgentWorker[Agent Worker Machine] -``` - -- **Transcoding Workers**: Can be run on GPU-accelerated or high-CPU compute instances. -- **AI Agent Workers**: Can be run on isolated, sandboxed hosts to safely execute automation scripts. - -> [!IMPORTANT] -> **Storage Requirement**: Because the core application and the background workers run on separate machines in a distributed setup, **you must configure an S3-compatible storage backend** (such as AWS S3, Cloudflare R2, or MinIO). Local storage (`STORAGE_BACKEND=local`) is not supported in this mode because the workers and the web application do not share a common filesystem. - ---- - -## Step 1: Deploy the Core Stack - -On your primary host machine, spin up the database, Temporal cluster services, and the main Shumai web application: - -1. **Download the Temporal Stack Configuration**: - ```bash - curl -o docker-compose.yaml https://raw.githubusercontent.com/shumaiOne/shumai/main/docker-compose/temporal/docker-compose.yaml - ``` -2. **Configure S3 Settings**: - Open the `docker-compose.yaml` file and set your S3 credentials and endpoint environment variables under the `shumai` service. -3. **Start the Services**: - ```bash - docker compose up -d - ``` - This exposes the web application on port `3000`, the database on `5432`, the Temporal gRPC service on `7233`, and the Temporal management dashboard on `8080`. - ---- - -## Step 2: Configure & Run Workers - -On your specialized worker machines, you will run the dedicated background worker services. Each worker requires a `.env` file referencing the database, S3 storage, and the Temporal cluster: - -```env -DATABASE_URL=postgresql://shumai:shumai_password@:5432/shumai_db?schema=public -WORKFLOW_EXECUTOR=temporal -TEMPORAL_ADDRESS=:7233 -STORAGE_BACKEND=s3 -AWS_ENDPOINT_URL_S3=https://your-s3-endpoint.com -S3_BUCKET=shumai -S3_REGION=us-east-1 -S3_ACCESS_KEY_ID=your-access-key-id -S3_SECRET_ACCESS_KEY=your-secret-access-key -``` - -### Media Transcoding Worker - -Run this on your media processing nodes (requires system installations of `ffmpeg` and `ffprobe`): - -```bash -npm install -g @shumai-one/shumai-transcode -shumai-transcode -``` - -### AI Agent Worker - -Run this on your sandboxed agent execution nodes (requires sandbox dependencies like `bubblewrap` or `sandbox-exec`): - -```bash -npm install -g @shumai-one/shumai-agent -shumai-agent -``` - -> [!IMPORTANT] -> **For Bun Users:** Since the worker package binaries contain a `#!/usr/bin/env node` shebang, running `shumai-transcode` or `shumai-agent` directly will run under Node.js. If you wish to run them using Bun, prefix the commands with `bun run --bun` (e.g., `bun run --bun shumai-transcode` or `bun run --bun shumai-agent`). diff --git a/docs/docs.json b/docs/docs.json index 2eeb01db..7008bd32 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -76,8 +76,8 @@ "pages": ["configuration/env-variables", "configuration/hardware-transcoding"] }, { - "group": "Temporal Deployment", - "pages": ["configuration/temporal"] + "group": "Distributed Deployment", + "pages": ["configuration/distributed"] }, { "group": "Releases", diff --git a/docs/getting-started/overview.mdx b/docs/getting-started/overview.mdx index 0f9cd05f..6fb5daa8 100644 --- a/docs/getting-started/overview.mdx +++ b/docs/getting-started/overview.mdx @@ -32,6 +32,6 @@ Ideal for small teams, local development, or low-volume workflows. In this setup ### 2. High-Scale Distributed Deployment -Recommended for production environments with high-volume video uploads. In this setup, background tasks are managed via a centralized queue (Temporal). This allows you to offload heavy workloads to specialized worker machines (for example, putting video transcoding tasks on high-CPU/GPU machines and AI agents on separate sandboxed environments). +Recommended for production environments with high-volume video uploads. In this setup, background tasks are managed via durable queues (orchestrated by DBOS directly in PostgreSQL). This allows you to offload heavy workloads to specialized worker machines (for example, putting video transcoding tasks on high-CPU/GPU machines and AI agents on separate sandboxed environments). _Note: S3-compatible cloud storage is required for distributed deployments so that all workers can access the uploaded files._ diff --git a/docs/getting-started/quickstart.mdx b/docs/getting-started/quickstart.mdx index 71e79104..bba040ac 100644 --- a/docs/getting-started/quickstart.mdx +++ b/docs/getting-started/quickstart.mdx @@ -27,9 +27,9 @@ Docker Compose automatically configures and spins up all required services (the 3. **Access the Dashboard**: Open your browser and navigate to **`http://localhost:3000`** to access the Shumai Web UI. -### Production Deployments (Temporal) +### Production Deployments (Distributed Workers) -If you are deploying Shumai for a production team with high-volume video uploads, we recommend setting up a distributed deployment using **Temporal** and an S3-compatible storage backend. This offloads resource-heavy video transcoding and AI agents to separate, dedicated worker nodes to keep your main dashboard fast and responsive. For setup instructions, see the [Deploy with Temporal](/configuration/temporal) guide. +If you are deploying Shumai for a production team with high-volume video uploads, we recommend setting up a distributed deployment using dedicated workers and an S3-compatible storage backend. This offloads resource-heavy video transcoding and AI agents to separate, dedicated worker nodes to keep your main dashboard fast and responsive. For setup instructions, see the [Deploy with Distributed Workers](/configuration/distributed) guide. --- diff --git a/docs/using-shumai/transcode-settings.mdx b/docs/using-shumai/transcode-settings.mdx index 77785642..76f36960 100644 --- a/docs/using-shumai/transcode-settings.mdx +++ b/docs/using-shumai/transcode-settings.mdx @@ -77,6 +77,6 @@ The **FFmpeg Threads** slider controls the maximum number of CPU threads used by ## Processing Architecture -Transcoding is resource-intensive. Depending on your scaling needs, your administrator can run the transcode engine on the main server (Single-Server mode) or delegate tasks to specialized transcoding worker machines (Temporal Worker mode). +Transcoding is resource-intensive. Depending on your scaling needs, your administrator can run the transcode engine on the main server (Single-Server mode) or delegate tasks to specialized transcoding worker machines (Dedicated Worker mode). -In all modes, the processing machine must have system media utilities (`ffmpeg` and `ffprobe`) installed. See the [Temporal Deployment Guide](/configuration/temporal) for setting up distributed transcoding workers. +In all modes, the processing machine must have system media utilities (`ffmpeg` and `ffprobe`) installed. See the [Distributed Deployment Guide](/configuration/distributed) for setting up dedicated transcoding workers.