feat: add services

- Introduced Convex, an open-source reactive database, with README and environment variable configurations.
- Added Chinese translation for Convex documentation.
- Created docker-compose configuration for Convex services.
- Introduced llama-swap, a model swapping proxy for OpenAI/Anthropic compatible servers, with comprehensive README and example configuration.
- Added Chinese translation for llama-swap documentation.
- Included example environment file and docker-compose setup for llama-swap.
- Configured health checks and resource limits for both Convex and llama-swap services.
This commit is contained in:
Sun-ZhenXing
2026-03-09 09:27:06 +08:00
parent 64c9b251c3
commit fbd0c9b7f4
14 changed files with 1260 additions and 2 deletions

158
src/convex/.env.example Normal file
View File

@@ -0,0 +1,158 @@
# Convex Configuration
# =============================================================================
# Versions
# =============================================================================
CONVEX_BACKEND_VERSION=33cef775a8a6228cbacee4a09ac2c4073d62ed13
CONVEX_DASHBOARD_VERSION=33cef775a8a6228cbacee4a09ac2c4073d62ed13
POSTGRES_VERSION=17-alpine
# =============================================================================
# Port Configuration
# =============================================================================
CONVEX_BACKEND_PORT_OVERRIDE=3210
CONVEX_SITE_PROXY_PORT_OVERRIDE=3211
CONVEX_DASHBOARD_PORT_OVERRIDE=6791
# =============================================================================
# Instance Configuration
# =============================================================================
# Name of your Convex instance
INSTANCE_NAME=convex-self-hosted
# Secret key for instance authentication (generate a strong random string)
# Example: openssl rand -hex 32
INSTANCE_SECRET=
# =============================================================================
# Origins
# =============================================================================
# URL where the Convex backend is accessible
CONVEX_CLOUD_ORIGIN=http://127.0.0.1:3210
# URL where the Convex site proxy is accessible
CONVEX_SITE_ORIGIN=http://127.0.0.1:3211
# URL for the dashboard to connect to the backend
NEXT_PUBLIC_DEPLOYMENT_URL=http://127.0.0.1:3210
# =============================================================================
# Database Configuration
# =============================================================================
# PostgreSQL password (change in production)
POSTGRES_PASSWORD=convex
# Full PostgreSQL connection URL (optional, constructed from above if not set)
# POSTGRES_URL=postgresql://postgres:convex@postgres:5432/convex
# MySQL URL (alternative to PostgreSQL, leave empty to use PostgreSQL)
# MYSQL_URL=
# =============================================================================
# Application Limits
# =============================================================================
# Maximum concurrent mutations
APPLICATION_MAX_CONCURRENT_MUTATIONS=16
# Maximum concurrent Node.js actions
APPLICATION_MAX_CONCURRENT_NODE_ACTIONS=16
# Maximum concurrent queries
APPLICATION_MAX_CONCURRENT_QUERIES=16
# Maximum concurrent V8 actions
APPLICATION_MAX_CONCURRENT_V8_ACTIONS=16
# User action timeout in seconds (empty for default)
ACTIONS_USER_TIMEOUT_SECS=
# =============================================================================
# SSL/TLS Settings
# =============================================================================
# Set to false to require SSL (recommended for production)
DO_NOT_REQUIRE_SSL=true
# =============================================================================
# Data Retention
# =============================================================================
# Document retention delay in seconds (default: 2 days)
DOCUMENT_RETENTION_DELAY=172800
# =============================================================================
# Telemetry and Metrics
# =============================================================================
# Disable telemetry beacon (set to true to disable)
DISABLE_BEACON=false
# Enable Prometheus-compatible /metrics endpoint
DISABLE_METRICS_ENDPOINT=true
# =============================================================================
# Logging
# =============================================================================
# Rust log level (error, warn, info, debug, trace)
RUST_LOG=info
# Enable Rust backtrace (1, full, or empty)
RUST_BACKTRACE=
# Redact logs sent to clients
REDACT_LOGS_TO_CLIENT=
# HTTP server timeout in seconds
HTTP_SERVER_TIMEOUT_SECONDS=
# =============================================================================
# AWS S3 Configuration (Optional - for external storage)
# =============================================================================
# AWS_ACCESS_KEY_ID=
# AWS_SECRET_ACCESS_KEY=
# AWS_REGION=
# AWS_SESSION_TOKEN=
# S3_ENDPOINT_URL=
# S3_STORAGE_EXPORTS_BUCKET=
# S3_STORAGE_FILES_BUCKET=
# S3_STORAGE_MODULES_BUCKET=
# S3_STORAGE_SEARCH_BUCKET=
# S3_STORAGE_SNAPSHOT_IMPORTS_BUCKET=
# AWS_S3_DISABLE_CHECKSUMS=
# AWS_S3_DISABLE_SSE=
# AWS_S3_FORCE_PATH_STYLE=
# =============================================================================
# Development Settings
# =============================================================================
# Development version override
CONVEX_RELEASE_VERSION_DEV=
# Load Monaco editor internally in dashboard
NEXT_PUBLIC_LOAD_MONACO_INTERNALLY=
# =============================================================================
# Timezone
# =============================================================================
TZ=UTC
# =============================================================================
# Resource Limits - Convex Backend
# =============================================================================
CONVEX_BACKEND_CPU_LIMIT=2.0
CONVEX_BACKEND_CPU_RESERVATION=0.5
CONVEX_BACKEND_MEMORY_LIMIT=2G
CONVEX_BACKEND_MEMORY_RESERVATION=512M
# =============================================================================
# Resource Limits - Convex Dashboard
# =============================================================================
CONVEX_DASHBOARD_CPU_LIMIT=0.5
CONVEX_DASHBOARD_CPU_RESERVATION=0.25
CONVEX_DASHBOARD_MEMORY_LIMIT=256M
CONVEX_DASHBOARD_MEMORY_RESERVATION=128M
# =============================================================================
# Resource Limits - PostgreSQL
# =============================================================================
POSTGRES_CPU_LIMIT=1.0
POSTGRES_CPU_RESERVATION=0.25
POSTGRES_MEMORY_LIMIT=1G
POSTGRES_MEMORY_RESERVATION=256M

123
src/convex/README.md Normal file
View File

@@ -0,0 +1,123 @@
# Convex
Convex is an open-source reactive database designed to make life easy for web app developers, whether human or LLM.
## Features
- **Reactive Queries**: Queries automatically update when underlying data changes
- **Real-time Subscriptions**: Live UI updates without manual polling
- **Serverless Functions**: Write backend logic in TypeScript/JavaScript
- **Automatic Caching**: Built-in intelligent caching for optimal performance
- **Type Safety**: Full TypeScript support with generated types
- **Scalable Architecture**: Designed to handle high-throughput applications
## Quick Start
1. Copy `.env.example` to `.env`:
```bash
cp .env.example .env
```
2. Generate an instance secret (required for production):
```bash
openssl rand -hex 32
```
Then set `INSTANCE_SECRET` in your `.env` file.
3. Start Convex:
```bash
docker compose up -d
```
4. Wait for services to be healthy (check with `docker compose ps`)
5. Access the Dashboard at `http://localhost:6791`
6. Backend API is available at `http://localhost:3210`
## Default Configuration
| Service | Port | Description |
| -------------- | ---- | ------------------------------- |
| Convex Backend | 3210 | Main API and WebSocket endpoint |
| Site Proxy | 3211 | Site hosting proxy |
| Dashboard | 6791 | Web UI for managing Convex |
| PostgreSQL | 5432 | Database (internal) |
**Authentication**: Set `INSTANCE_SECRET` for production use.
## Environment Variables
Key environment variables (see `.env.example` for full list):
| Variable | Description | Default |
| --------------------------------- | --------------------------------- | ----------------------- |
| `CONVEX_BACKEND_PORT_OVERRIDE` | Host port for backend API | `3210` |
| `CONVEX_SITE_PROXY_PORT_OVERRIDE` | Host port for site proxy | `3211` |
| `CONVEX_DASHBOARD_PORT_OVERRIDE` | Host port for dashboard | `6791` |
| `INSTANCE_NAME` | Name of the Convex instance | `convex-self-hosted` |
| `INSTANCE_SECRET` | Secret key for authentication | (required) |
| `CONVEX_CLOUD_ORIGIN` | URL for backend access | `http://127.0.0.1:3210` |
| `CONVEX_SITE_ORIGIN` | URL for site proxy access | `http://127.0.0.1:3211` |
| `POSTGRES_PASSWORD` | PostgreSQL password | `convex` |
| `RUST_LOG` | Log level (error/warn/info/debug) | `info` |
| `TZ` | Timezone | `UTC` |
## Resource Requirements
**Minimum**:
- CPU: 1 core
- RAM: 1GB
- Disk: 5GB
**Recommended**:
- CPU: 2+ cores
- RAM: 2GB+
- Disk: 20GB+
## Volumes
- `convex_data`: Convex backend data storage
- `postgres_data`: PostgreSQL database data
## Using with Your Application
To use this self-hosted Convex backend with your application:
1. Set the `CONVEX_SELF_HOSTED_URL` environment variable in your app:
```bash
CONVEX_SELF_HOSTED_URL=http://localhost:3210
```
2. Set the `CONVEX_SELF_HOSTED_ADMIN_KEY` environment variable:
```bash
CONVEX_SELF_HOSTED_ADMIN_KEY=your-instance-secret
```
3. Deploy your Convex functions:
```bash
npx convex dev
```
For more details, see the [Convex Self-Hosting Documentation](https://stack.convex.dev/self-hosted-develop-and-deploy).
## Security Notes
- **Always set a strong `INSTANCE_SECRET`** in production
- Enable SSL/TLS by setting `DO_NOT_REQUIRE_SSL=false` and using a reverse proxy
- Use strong database passwords
- Restrict network access to Convex services
- Consider using AWS S3 for external storage in production
## License
Apache-2.0 (<https://github.com/get-convex/convex-backend/blob/main/LICENSE>)

123
src/convex/README.zh.md Normal file
View File

@@ -0,0 +1,123 @@
# Convex
Convex 是一个开源的响应式数据库,旨在让 Web 应用开发者(无论是人类还是 LLM的生活更加轻松。
## 功能特性
- **响应式查询**:当底层数据变化时,查询会自动更新
- **实时订阅**:无需手动轮询即可实现实时 UI 更新
- **无服务器函数**:使用 TypeScript/JavaScript 编写后端逻辑
- **自动缓存**:内置智能缓存以获得最佳性能
- **类型安全**:完整的 TypeScript 支持,并生成类型定义
- **可扩展架构**:专为高吞吐量应用而设计
## 快速开始
1. 复制 `.env.example``.env`
```bash
cp .env.example .env
```
2. 生成实例密钥(生产环境必需):
```bash
openssl rand -hex 32
```
然后在 `.env` 文件中设置 `INSTANCE_SECRET`。
3. 启动 Convex
```bash
docker compose up -d
```
4. 等待服务健康(使用 `docker compose ps` 检查)
5. 访问 Dashboard`http://localhost:6791`
6. 后端 API 地址:`http://localhost:3210`
## 默认配置
| 服务 | 端口 | 说明 |
| -------------- | ---- | ------------------------ |
| Convex Backend | 3210 | 主 API 和 WebSocket 端点 |
| Site Proxy | 3211 | 站点托管代理 |
| Dashboard | 6791 | 管理 Convex 的 Web UI |
| PostgreSQL | 5432 | 数据库(内部) |
**认证**:生产环境请设置 `INSTANCE_SECRET`。
## 环境变量
关键环境变量(完整列表请参见 `.env.example`
| 变量 | 说明 | 默认值 |
| --------------------------------- | --------------------------------- | ----------------------- |
| `CONVEX_BACKEND_PORT_OVERRIDE` | 后端 API 的主机端口 | `3210` |
| `CONVEX_SITE_PROXY_PORT_OVERRIDE` | 站点代理的主机端口 | `3211` |
| `CONVEX_DASHBOARD_PORT_OVERRIDE` | Dashboard 的主机端口 | `6791` |
| `INSTANCE_NAME` | Convex 实例名称 | `convex-self-hosted` |
| `INSTANCE_SECRET` | 认证密钥 | (必需) |
| `CONVEX_CLOUD_ORIGIN` | 后端访问 URL | `http://127.0.0.1:3210` |
| `CONVEX_SITE_ORIGIN` | 站点代理访问 URL | `http://127.0.0.1:3211` |
| `POSTGRES_PASSWORD` | PostgreSQL 密码 | `convex` |
| `RUST_LOG` | 日志级别error/warn/info/debug | `info` |
| `TZ` | 时区 | `UTC` |
## 资源需求
**最低配置**
- CPU1 核
- 内存1GB
- 磁盘5GB
**推荐配置**
- CPU2+ 核
- 内存2GB+
- 磁盘20GB+
## 数据卷
- `convex_data`Convex 后端数据存储
- `postgres_data`PostgreSQL 数据库数据
## 在应用中使用
要将此自托管 Convex 后端与您的应用一起使用:
1. 在应用中设置 `CONVEX_SELF_HOSTED_URL` 环境变量:
```bash
CONVEX_SELF_HOSTED_URL=http://localhost:3210
```
2. 设置 `CONVEX_SELF_HOSTED_ADMIN_KEY` 环境变量:
```bash
CONVEX_SELF_HOSTED_ADMIN_KEY=your-instance-secret
```
3. 部署您的 Convex 函数:
```bash
npx convex dev
```
更多详情,请参阅 [Convex 自托管文档](https://stack.convex.dev/self-hosted-develop-and-deploy)。
## 安全说明
- **生产环境务必设置强 `INSTANCE_SECRET`**
- 通过设置 `DO_NOT_REQUIRE_SSL=false` 并使用反向代理来启用 SSL/TLS
- 使用强数据库密码
- 限制对 Convex 服务的网络访问
- 生产环境考虑使用 AWS S3 进行外部存储
## 许可证
Apache-2.0<https://github.com/get-convex/convex-backend/blob/main/LICENSE>

View File

@@ -0,0 +1,195 @@
# Convex - Open-source Reactive Database
# https://github.com/get-convex/convex-backend
#
# Convex is an open-source reactive database designed to make life easy for
# web app developers. It provides real-time data synchronization, automatic
# caching, and a powerful query language.
#
# Key Features:
# - Reactive queries that automatically update when data changes
# - Real-time subscriptions for live UI updates
# - Built-in authentication and authorization
# - Serverless functions with TypeScript/JavaScript
# - Automatic scaling and caching
#
# Default Credentials:
# - Dashboard at http://localhost:6791
# - Backend API at http://localhost:3210
# - Site proxy at http://localhost:3211
#
# Security Notes:
# - Set a strong INSTANCE_SECRET in production
# - Enable SSL/TLS in production
# - Use strong database passwords
# - Restrict network access to Convex services
#
# License: Apache-2.0 (https://github.com/get-convex/convex-backend/blob/main/LICENSE)
x-defaults: &defaults
restart: unless-stopped
logging:
driver: json-file
options:
max-size: 100m
max-file: '3'
services:
convex-backend:
<<: *defaults
image: ${GHCR_REGISTRY:-ghcr.io/}get-convex/convex-backend:${CONVEX_BACKEND_VERSION:-33cef775a8a6228cbacee4a09ac2c4073d62ed13}
stop_grace_period: 10s
stop_signal: SIGINT
ports:
- '${CONVEX_BACKEND_PORT_OVERRIDE:-3210}:3210'
- '${CONVEX_SITE_PROXY_PORT_OVERRIDE:-3211}:3211'
volumes:
- convex_data:/convex/data
environment:
# Instance configuration
- INSTANCE_NAME=${INSTANCE_NAME:-convex-self-hosted}
- INSTANCE_SECRET=${INSTANCE_SECRET}
# Origins
- CONVEX_CLOUD_ORIGIN=${CONVEX_CLOUD_ORIGIN:-http://127.0.0.1:3210}
- CONVEX_SITE_ORIGIN=${CONVEX_SITE_ORIGIN:-http://127.0.0.1:3211}
# Database configuration (PostgreSQL)
- POSTGRES_URL=${POSTGRES_URL:-postgresql://postgres:${POSTGRES_PASSWORD:-convex}@postgres:5432/convex}
# Application limits
- APPLICATION_MAX_CONCURRENT_MUTATIONS=${APPLICATION_MAX_CONCURRENT_MUTATIONS:-16}
- APPLICATION_MAX_CONCURRENT_NODE_ACTIONS=${APPLICATION_MAX_CONCURRENT_NODE_ACTIONS:-16}
- APPLICATION_MAX_CONCURRENT_QUERIES=${APPLICATION_MAX_CONCURRENT_QUERIES:-16}
- APPLICATION_MAX_CONCURRENT_V8_ACTIONS=${APPLICATION_MAX_CONCURRENT_V8_ACTIONS:-16}
# Actions timeout
- ACTIONS_USER_TIMEOUT_SECS=${ACTIONS_USER_TIMEOUT_SECS:-}
# SSL/TLS settings
- DO_NOT_REQUIRE_SSL=${DO_NOT_REQUIRE_SSL:-true}
# Document retention (default 2 days in seconds)
- DOCUMENT_RETENTION_DELAY=${DOCUMENT_RETENTION_DELAY:-172800}
# Metrics and beacon
- DISABLE_BEACON=${DISABLE_BEACON:-false}
- DISABLE_METRICS_ENDPOINT=${DISABLE_METRICS_ENDPOINT:-true}
# Logging
- RUST_LOG=${RUST_LOG:-info}
- RUST_BACKTRACE=${RUST_BACKTRACE:-}
- REDACT_LOGS_TO_CLIENT=${REDACT_LOGS_TO_CLIENT:-}
# HTTP server timeout
- HTTP_SERVER_TIMEOUT_SECONDS=${HTTP_SERVER_TIMEOUT_SECONDS:-}
# AWS S3 configuration (optional, for external storage)
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID:-}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY:-}
- AWS_REGION=${AWS_REGION:-}
- AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN:-}
- S3_ENDPOINT_URL=${S3_ENDPOINT_URL:-}
- S3_STORAGE_EXPORTS_BUCKET=${S3_STORAGE_EXPORTS_BUCKET:-}
- S3_STORAGE_FILES_BUCKET=${S3_STORAGE_FILES_BUCKET:-}
- S3_STORAGE_MODULES_BUCKET=${S3_STORAGE_MODULES_BUCKET:-}
- S3_STORAGE_SEARCH_BUCKET=${S3_STORAGE_SEARCH_BUCKET:-}
- S3_STORAGE_SNAPSHOT_IMPORTS_BUCKET=${S3_STORAGE_SNAPSHOT_IMPORTS_BUCKET:-}
- AWS_S3_DISABLE_CHECKSUMS=${AWS_S3_DISABLE_CHECKSUMS:-}
- AWS_S3_DISABLE_SSE=${AWS_S3_DISABLE_SSE:-}
- AWS_S3_FORCE_PATH_STYLE=${AWS_S3_FORCE_PATH_STYLE:-}
# MySQL URL (alternative to PostgreSQL)
- MYSQL_URL=${MYSQL_URL:-}
# Development settings
- CONVEX_RELEASE_VERSION_DEV=${CONVEX_RELEASE_VERSION_DEV:-}
# Timezone
- TZ=${TZ:-UTC}
depends_on:
postgres:
condition: service_healthy
healthcheck:
test:
- CMD
- curl
- -f
- http://localhost:3210/version
interval: 5s
timeout: 5s
retries: 5
start_period: 30s
deploy:
resources:
limits:
cpus: '${CONVEX_BACKEND_CPU_LIMIT:-2.0}'
memory: '${CONVEX_BACKEND_MEMORY_LIMIT:-2G}'
reservations:
cpus: '${CONVEX_BACKEND_CPU_RESERVATION:-0.5}'
memory: '${CONVEX_BACKEND_MEMORY_RESERVATION:-512M}'
convex-dashboard:
<<: *defaults
image: ${GHCR_REGISTRY:-ghcr.io/}get-convex/convex-dashboard:${CONVEX_DASHBOARD_VERSION:-33cef775a8a6228cbacee4a09ac2c4073d62ed13}
stop_grace_period: 10s
stop_signal: SIGINT
ports:
- '${CONVEX_DASHBOARD_PORT_OVERRIDE:-6791}:6791'
environment:
- NEXT_PUBLIC_DEPLOYMENT_URL=${NEXT_PUBLIC_DEPLOYMENT_URL:-http://127.0.0.1:3210}
- NEXT_PUBLIC_LOAD_MONACO_INTERNALLY=${NEXT_PUBLIC_LOAD_MONACO_INTERNALLY:-}
depends_on:
convex-backend:
condition: service_healthy
healthcheck:
test:
- CMD
- wget
- --quiet
- --tries=1
- --spider
- http://localhost:6791
interval: 10s
timeout: 5s
retries: 3
start_period: 10s
deploy:
resources:
limits:
cpus: '${CONVEX_DASHBOARD_CPU_LIMIT:-0.5}'
memory: '${CONVEX_DASHBOARD_MEMORY_LIMIT:-256M}'
reservations:
cpus: '${CONVEX_DASHBOARD_CPU_RESERVATION:-0.25}'
memory: '${CONVEX_DASHBOARD_MEMORY_RESERVATION:-128M}'
postgres:
<<: *defaults
image: ${GLOBAL_REGISTRY:-}postgres:${POSTGRES_VERSION:-17-alpine}
environment:
- POSTGRES_DB=convex
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-convex}
- POSTGRES_INITDB_ARGS=--encoding=UTF8
- TZ=${TZ:-UTC}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test:
- CMD-SHELL
- pg_isready -U postgres
interval: 5s
timeout: 5s
retries: 5
start_period: 10s
deploy:
resources:
limits:
cpus: '${POSTGRES_CPU_LIMIT:-1.0}'
memory: '${POSTGRES_MEMORY_LIMIT:-1G}'
reservations:
cpus: '${POSTGRES_CPU_RESERVATION:-0.25}'
memory: '${POSTGRES_MEMORY_RESERVATION:-256M}'
volumes:
convex_data:
postgres_data: