Docker 部署
Docker Compose 是 iForge 推荐的生产部署方式。
一键启动
# 1. 克隆仓库
git clone https://gitee.com/iforge-go/iforge.git
cd iforge
# 2. 复制环境变量配置(可选,不复制则使用默认值)
cp .env.example .env
# 3. 构建并启动(首次构建约 5-10 分钟)
docker compose up -d
# 4. 查看日志
docker compose logs -f
启动后访问 http://localhost:3000 注册首个管理员账户。
服务架构
┌─────────────────────────────────────────────────────────────┐
│ Nginx 反向代理层 │
│ (独立仓库 iforge-nginx 统一管理) │
│ │
│ iforge-go.com ──────► iforge-site (文档站) │
│ www.iforge-go.com ──► iforge-site (文档站) │
│ demo.iforge-go.com ─┬─► iforge-web (前端) │
│ └─► iforge-server (后端) │
└─────────────────────────────────────────────────────────────┘
│
┌───────────────────────── ────┼─────────────────────────────────┐
│ iForge 平台 │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │
│ │ web:3001 │────▶│ server:8081 │────▶│ Database │ │
│ │ (Next.js) │ │ (Go) │ │ SQLite/MySQL/ │ │
│ └─────────────┘ └──────┬──────┘ │ PostgreSQL │ │
│ │ └─────────────────┘ │
│ ┌──────┴──────┐ │
│ │ server:2022 │ │
│ │ (SSH Git) │ │
│ └─────────────┘ │
│ ▲ │
│ │ claim job / report status │
│ ┌──────┴──────┐ ┌─────────────────┐ │
│ │ runner │────▶│ job 容器 │ │
│ │ (iforge- │ DooD│ (alpine 等) │ │
│ │ runner) │ └─────────────────┘ │
│ └─────────────┘ │
└───────────────────────────────────────────────────────────────┘
端口映射
| 服务 | 容器内端口 | 宿主机端口 | 用途 |
|---|---|---|---|
| server | 8081 | 8080 | HTTP API + Git HTTP |
| server | 2022 | 22 | SSH Git 协议 |
| web | 3001 | 3000 | 前端页面 |
| mysql | 3306 | 3306 | MySQL 数据库(profile: mysql) |
| postgres | 5432 | 5432 | PostgreSQL 数据库(profile: postgres) |
| runner | — | — | 无外部端口,通过 Docker socket 执行 job |
数据持久化
数据卷挂载在 ./data 目录:
volumes:
- ./data:/app/data
包含:
iforge.db— SQLite 数据库logs/— 运行日志repositories/— Git 仓库裸存储
备份
直接打包 ./data 目录即可完成完整备份。
局域网访问
Docker 部署默认支持局域网访问,无需额外配置:
- 前端 API 地址按浏览器 hostname 动态适配
- 后端 CORS 设置为
*(反射任意 Origin)
从局域网其他机器访问 http://192.168.x.x:3000 即可,API 请求自动发到 http://192.168.x.x:8080。
自定义域名
部署在自有域名时,在 .env 中设置:
NEXT_PUBLIC_API_BASE=https://iforge.example.com/api/v1
IFORGE_CORS_ORIGINS=https://iforge.example.com
修改后重新构建:
docker compose build --no-cache web server
docker compose up -d
数据库选择
iForge 支持三种数据库,通过 Docker Compose profiles 切换:
SQLite(默认,适合开发)
docker compose up -d