feat: Add Temporal and Windmill services with configuration files

- Implemented Temporal service with Docker Compose, including PostgreSQL setup and environment variables for configuration.
- Added Temporal README and Chinese translation for documentation.
- Introduced Windmill service with Docker Compose, including PostgreSQL setup and environment variables for configuration.
- Added Windmill README and Chinese translation for documentation.
- Updated MongoDB configurations to use host.docker.internal for better compatibility.
This commit is contained in:
Sun-ZhenXing
2025-11-01 19:40:54 +08:00
parent 843ebc24a1
commit 0f54723be1
22 changed files with 2805 additions and 6 deletions

39
src/temporal/.env.example Normal file
View File

@@ -0,0 +1,39 @@
# Temporal Configuration
# Versions
TEMPORAL_VERSION=1.24.2
TEMPORAL_UI_VERSION=2.28.0
POSTGRES_VERSION=16-alpine
# Port Configuration
TEMPORAL_FRONTEND_PORT_OVERRIDE=7233
TEMPORAL_UI_PORT_OVERRIDE=8233
# PostgreSQL Configuration
POSTGRES_DB=temporal
POSTGRES_USER=temporal
POSTGRES_PASSWORD=temporal
# Logging
TEMPORAL_LOG_LEVEL=info
# Timezone
TZ=UTC
# Resource Limits - Temporal Server
TEMPORAL_CPU_LIMIT=2.0
TEMPORAL_CPU_RESERVATION=0.5
TEMPORAL_MEMORY_LIMIT=2G
TEMPORAL_MEMORY_RESERVATION=512M
# Resource Limits - Temporal UI
TEMPORAL_UI_CPU_LIMIT=0.5
TEMPORAL_UI_CPU_RESERVATION=0.1
TEMPORAL_UI_MEMORY_LIMIT=512M
TEMPORAL_UI_MEMORY_RESERVATION=128M
# Resource Limits - PostgreSQL
POSTGRES_CPU_LIMIT=1.0
POSTGRES_CPU_RESERVATION=0.25
POSTGRES_MEMORY_LIMIT=1G
POSTGRES_MEMORY_RESERVATION=256M

239
src/temporal/README.md Normal file
View File

@@ -0,0 +1,239 @@
# Temporal
Temporal is a scalable and reliable runtime for Reentrant Processes called Temporal Workflow Executions. It enables developers to write simple, resilient code without worrying about failures, retries, or state management.
## Features
- **Durable Execution**: Workflows survive failures, restarts, and even code deployments
- **Built-in Reliability**: Automatic retries, timeouts, and error handling
- **Long-Running Workflows**: Support workflows that run for days, months, or years
- **Multi-Language SDKs**: Official support for Go, Java, TypeScript, Python, PHP, .NET
- **Advanced Visibility**: Search and filter workflow executions
- **Event-Driven**: Signals, queries, and updates for workflow interaction
## Quick Start
1. Copy `.env.example` to `.env`:
```bash
cp .env.example .env
```
2. (Optional) Edit `.env` to customize database passwords and settings
3. Start Temporal:
```bash
docker compose up -d
```
4. Wait for services to be ready (check with `docker compose logs -f temporal`)
5. Access Temporal Web UI at `http://localhost:8233`
6. Frontend service is available at `localhost:7233` (gRPC)
## Default Configuration
| Service | Port | Description |
| ----------------- | ---- | ---------------------- |
| Temporal Frontend | 7233 | gRPC endpoint for SDKs |
| Temporal Web UI | 8233 | Web interface |
| PostgreSQL | 5432 | Database (internal) |
**Authentication**: No authentication by default. Configure mTLS and authorization for production use.
## Environment Variables
Key environment variables (see `.env.example` for full list):
| Variable | Description | Default |
| --------------------------------- | ----------------------- | ---------- |
| `TEMPORAL_VERSION` | Temporal server version | `1.24.2` |
| `TEMPORAL_UI_VERSION` | Temporal UI version | `2.28.0` |
| `TEMPORAL_FRONTEND_PORT_OVERRIDE` | Frontend gRPC port | `7233` |
| `TEMPORAL_UI_PORT_OVERRIDE` | Web UI port | `8233` |
| `POSTGRES_DB` | Database name | `temporal` |
| `POSTGRES_USER` | Database user | `temporal` |
| `POSTGRES_PASSWORD` | Database password | `temporal` |
| `TEMPORAL_LOG_LEVEL` | Log level | `info` |
| `TZ` | Timezone | `UTC` |
## Resource Requirements
**Minimum**:
- CPU: 1 core
- RAM: 1GB
- Disk: 5GB
**Recommended**:
- CPU: 2+ cores
- RAM: 2GB+
- Disk: 20GB+
## Volumes
- `postgres_data`: PostgreSQL database data
- `temporal_data`: Temporal configuration and state
## Using Temporal
### Install SDK
Choose your language:
**Go:**
```bash
go get go.temporal.io/sdk
```
**TypeScript:**
```bash
npm install @temporalio/client @temporalio/worker
```
**Python:**
```bash
pip install temporalio
```
### Write a Workflow (Python Example)
```python
from temporalio import workflow, activity
from datetime import timedelta
@activity.defn
async def say_hello(name: str) -> str:
return f"Hello, {name}!"
@workflow.defn
class HelloWorkflow:
@workflow.run
async def run(self, name: str) -> str:
return await workflow.execute_activity(
say_hello,
name,
start_to_close_timeout=timedelta(seconds=10),
)
```
### Run a Worker
```python
from temporalio.client import Client
from temporalio.worker import Worker
async def main():
client = await Client.connect("localhost:7233")
worker = Worker(
client,
task_queue="hello-queue",
workflows=[HelloWorkflow],
activities=[say_hello],
)
await worker.run()
```
### Execute a Workflow
```python
from temporalio.client import Client
async def main():
client = await Client.connect("localhost:7233")
result = await client.execute_workflow(
HelloWorkflow.run,
"World",
id="hello-workflow",
task_queue="hello-queue",
)
print(result)
```
### Using tctl CLI
The admin-tools container (dev profile) includes tctl:
```bash
docker compose --profile dev run temporal-admin-tools
tctl namespace list
tctl workflow list
```
## Profiles
- `dev`: Include admin-tools container for CLI access
To enable dev profile:
```bash
docker compose --profile dev up -d
```
## Security Considerations
1. **Authentication**: Configure mTLS for production deployments
2. **Authorization**: Set up authorization rules for namespaces and workflows
3. **Database Passwords**: Use strong PostgreSQL passwords
4. **Network Security**: Restrict access to Temporal ports
5. **Encryption**: Enable encryption at rest for sensitive data
## Upgrading
To upgrade Temporal:
1. Update versions in `.env`
2. Pull and restart:
```bash
docker compose pull
docker compose up -d
```
3. Check logs for migration messages:
```bash
docker compose logs -f temporal
```
## Troubleshooting
**Service won't start:**
- Check logs: `docker compose logs temporal`
- Verify database: `docker compose ps postgres`
- Ensure sufficient resources allocated
**Cannot connect from SDK:**
- Verify port 7233 is accessible
- Check firewall rules
- Ensure SDK version compatibility
**Web UI not loading:**
- Check UI logs: `docker compose logs temporal-ui`
- Verify frontend is healthy: `docker compose ps temporal`
- Clear browser cache
## References
- Official Website: <https://temporal.io>
- Documentation: <https://docs.temporal.io>
- GitHub: <https://github.com/temporalio/temporal>
- Community: <https://community.temporal.io>
- SDK Documentation: <https://docs.temporal.io/dev-guide>
## License
Temporal is licensed under MIT. See [LICENSE](https://github.com/temporalio/temporal/blob/master/LICENSE) for more information.

239
src/temporal/README.zh.md Normal file
View File

@@ -0,0 +1,239 @@
# Temporal
Temporal 是一个可扩展且可靠的持久化执行运行时,用于运行称为 Temporal 工作流执行的可重入流程。它使开发人员能够编写简单、有弹性的代码,而无需担心故障、重试或状态管理。
## 功能特点
- **持久化执行**:工作流可以在故障、重启甚至代码部署后继续运行
- **内置可靠性**:自动重试、超时和错误处理
- **长期运行的工作流**:支持运行数天、数月或数年的工作流
- **多语言 SDK**:官方支持 Go、Java、TypeScript、Python、PHP、.NET
- **高级可见性**:搜索和过滤工作流执行
- **事件驱动**:通过信号、查询和更新与工作流交互
## 快速开始
1. 复制 `.env.example``.env`
```bash
copy .env.example .env
```
2. (可选)编辑 `.env` 自定义数据库密码和设置
3. 启动 Temporal
```bash
docker compose up -d
```
4. 等待服务就绪(使用 `docker compose logs -f temporal` 检查)
5. 访问 Temporal Web UI`http://localhost:8233`
6. Frontend 服务地址:`localhost:7233`gRPC
## 默认配置
| 服务 | 端口 | 说明 |
| ----------------- | ---- | ---------------- |
| Temporal Frontend | 7233 | SDK 的 gRPC 端点 |
| Temporal Web UI | 8233 | Web 界面 |
| PostgreSQL | 5432 | 数据库(内部) |
**身份验证**:默认无身份验证。生产环境中请配置 mTLS 和授权。
## 环境变量
主要环境变量(完整列表请参阅 `.env.example`
| 变量 | 说明 | 默认值 |
| --------------------------------- | ------------------- | ---------- |
| `TEMPORAL_VERSION` | Temporal 服务器版本 | `1.24.2` |
| `TEMPORAL_UI_VERSION` | Temporal UI 版本 | `2.28.0` |
| `TEMPORAL_FRONTEND_PORT_OVERRIDE` | Frontend gRPC 端口 | `7233` |
| `TEMPORAL_UI_PORT_OVERRIDE` | Web UI 端口 | `8233` |
| `POSTGRES_DB` | 数据库名称 | `temporal` |
| `POSTGRES_USER` | 数据库用户 | `temporal` |
| `POSTGRES_PASSWORD` | 数据库密码 | `temporal` |
| `TEMPORAL_LOG_LEVEL` | 日志级别 | `info` |
| `TZ` | 时区 | `UTC` |
## 资源需求
**最低要求**
- CPU1 核心
- 内存1GB
- 磁盘5GB
**推荐配置**
- CPU2+ 核心
- 内存2GB+
- 磁盘20GB+
## 数据卷
- `postgres_data`PostgreSQL 数据库数据
- `temporal_data`Temporal 配置和状态
## 使用 Temporal
### 安装 SDK
选择您的语言:
**Go**
```bash
go get go.temporal.io/sdk
```
**TypeScript**
```bash
npm install @temporalio/client @temporalio/worker
```
**Python**
```bash
pip install temporalio
```
### 编写工作流Python 示例)
```python
from temporalio import workflow, activity
from datetime import timedelta
@activity.defn
async def say_hello(name: str) -> str:
return f"Hello, {name}!"
@workflow.defn
class HelloWorkflow:
@workflow.run
async def run(self, name: str) -> str:
return await workflow.execute_activity(
say_hello,
name,
start_to_close_timeout=timedelta(seconds=10),
)
```
### 运行 Worker
```python
from temporalio.client import Client
from temporalio.worker import Worker
async def main():
client = await Client.connect("localhost:7233")
worker = Worker(
client,
task_queue="hello-queue",
workflows=[HelloWorkflow],
activities=[say_hello],
)
await worker.run()
```
### 执行工作流
```python
from temporalio.client import Client
async def main():
client = await Client.connect("localhost:7233")
result = await client.execute_workflow(
HelloWorkflow.run,
"World",
id="hello-workflow",
task_queue="hello-queue",
)
print(result)
```
### 使用 tctl CLI
admin-tools 容器dev 配置文件)包含 tctl
```bash
docker compose --profile dev run temporal-admin-tools
tctl namespace list
tctl workflow list
```
## 配置文件
- `dev`:包含用于 CLI 访问的 admin-tools 容器
启用 dev 配置文件:
```bash
docker compose --profile dev up -d
```
## 安全注意事项
1. **身份验证**:为生产部署配置 mTLS
2. **授权**:为命名空间和工作流设置授权规则
3. **数据库密码**:使用强 PostgreSQL 密码
4. **网络安全**:限制对 Temporal 端口的访问
5. **加密**:为敏感数据启用静态加密
## 升级
升级 Temporal
1. 在 `.env` 中更新版本
2. 拉取并重启:
```bash
docker compose pull
docker compose up -d
```
3. 检查日志查看迁移消息:
```bash
docker compose logs -f temporal
```
## 故障排除
**服务无法启动:**
- 检查日志:`docker compose logs temporal`
- 验证数据库:`docker compose ps postgres`
- 确保分配了足够的资源
**SDK 无法连接:**
- 验证端口 7233 可访问
- 检查防火墙规则
- 确保 SDK 版本兼容性
**Web UI 无法加载:**
- 检查 UI 日志:`docker compose logs temporal-ui`
- 验证 frontend 健康:`docker compose ps temporal`
- 清除浏览器缓存
## 参考资料
- 官方网站:<https://temporal.io>
- 文档:<https://docs.temporal.io>
- GitHub<https://github.com/temporalio/temporal>
- 社区:<https://community.temporal.io>
- SDK 文档:<https://docs.temporal.io/dev-guide>
## 许可证
Temporal 使用 MIT 许可证。详情请参阅 [LICENSE](https://github.com/temporalio/temporal/blob/master/LICENSE)。

View File

@@ -0,0 +1,166 @@
# Temporal - Durable Execution Platform
# https://github.com/temporalio/temporal
#
# Temporal is a scalable and reliable runtime for microservice orchestration that enables
# developers to write simple, resilient code without worrying about failures, retries, or
# state management.
#
# Key Features:
# - Durable workflow execution with automatic state management
# - Built-in retry and error handling
# - Support for long-running workflows (days, months, years)
# - Multiple language SDKs (Go, Java, TypeScript, Python, PHP, .NET)
# - Advanced visibility with search capabilities
# - Multi-cluster replication support
#
# Default Credentials:
# - Access Web UI at http://localhost:8233
# - Frontend service at localhost:7233 (gRPC)
# - No authentication by default
#
# Security Notes:
# - Configure authentication and authorization in production
# - Use strong database passwords
# - Enable mTLS for production deployments
# - Restrict network access appropriately
#
# License: MIT (https://github.com/temporalio/temporal/blob/master/LICENSE)
x-default: &default
restart: unless-stopped
logging:
driver: json-file
options:
max-size: 100m
max-file: "3"
services:
temporal:
<<: *default
image: temporalio/auto-setup:${TEMPORAL_VERSION:-1.24.2}
container_name: temporal
ports:
- "${TEMPORAL_FRONTEND_PORT_OVERRIDE:-7233}:7233" # Frontend gRPC
environment:
# Database configuration
- DB=postgresql
- DB_PORT=5432
- POSTGRES_SEEDS=postgres
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PWD=${POSTGRES_PASSWORD}
# Visibility database (using same Postgres)
- DBNAME=${POSTGRES_DB}
- VISIBILITY_DBNAME=${POSTGRES_DB}
# Server configuration
- DYNAMIC_CONFIG_FILE_PATH=config/dynamicconfig/development-sql.yaml
- ENABLE_ES=false
- SKIP_DB_CREATE=false
- SKIP_DEFAULT_NAMESPACE_CREATION=false
# Other settings
- TZ=${TZ:-UTC}
- LOG_LEVEL=${TEMPORAL_LOG_LEVEL:-info}
volumes:
- temporal_data:/etc/temporal
depends_on:
postgres:
condition: service_healthy
healthcheck:
test: ["CMD", "tctl", "--address", "temporal:7233", "cluster", "health"]
interval: 30s
timeout: 10s
retries: 5
start_period: 90s
deploy:
resources:
limits:
cpus: "${TEMPORAL_CPU_LIMIT:-2.0}"
memory: "${TEMPORAL_MEMORY_LIMIT:-2G}"
reservations:
cpus: "${TEMPORAL_CPU_RESERVATION:-0.5}"
memory: "${TEMPORAL_MEMORY_RESERVATION:-512M}"
temporal-ui:
<<: *default
image: temporalio/ui:${TEMPORAL_UI_VERSION:-2.28.0}
container_name: temporal-ui
ports:
- "${TEMPORAL_UI_PORT_OVERRIDE:-8233}:8080"
environment:
- TEMPORAL_ADDRESS=temporal:7233
- TEMPORAL_CORS_ORIGINS=http://localhost:8233
- TEMPORAL_UI_ENABLED=true
- TZ=${TZ:-UTC}
depends_on:
temporal:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:8080"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
deploy:
resources:
limits:
cpus: "${TEMPORAL_UI_CPU_LIMIT:-0.5}"
memory: "${TEMPORAL_UI_MEMORY_LIMIT:-512M}"
reservations:
cpus: "${TEMPORAL_UI_CPU_RESERVATION:-0.1}"
memory: "${TEMPORAL_UI_MEMORY_RESERVATION:-128M}"
temporal-admin-tools:
<<: *default
image: temporalio/admin-tools:${TEMPORAL_VERSION:-1.24.2}
container_name: temporal-admin-tools
profiles:
- dev
environment:
- TEMPORAL_ADDRESS=temporal:7233
- TEMPORAL_CLI_ADDRESS=temporal:7233
- TZ=${TZ:-UTC}
depends_on:
temporal:
condition: service_healthy
stdin_open: true
tty: true
deploy:
resources:
limits:
cpus: "0.5"
memory: "256M"
postgres:
<<: *default
image: postgres:${POSTGRES_VERSION:-16-alpine}
container_name: temporal-postgres
environment:
- POSTGRES_DB=${POSTGRES_DB:-temporal}
- POSTGRES_USER=${POSTGRES_USER:-temporal}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-temporal}
- POSTGRES_INITDB_ARGS=--encoding=UTF8
- TZ=${TZ:-UTC}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-temporal} -d ${POSTGRES_DB:-temporal}"]
interval: 10s
timeout: 5s
retries: 5
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:
postgres_data:
driver: local
temporal_data:
driver: local