Compare commits

..

51 Commits
main ... main

Author SHA1 Message Date
f04bb5e4fc feat: 基础服务镜像支持环境变量与多架构迁移脚本
Some checks failed
Test start.ps1 (Windows) / test-windows (push) Has been cancelled
- docker-compose:REDIS_IMAGE、MONGO_IMAGE、RABBITMQ_IMAGE 可配置,默认保持原阿里云地址
- .env.sample:补充三镜像变量、Mongo 4.4 备选地址及用途说明、RabbitMQ 备选示例
- 新增 mirror-image-to-registry.ps1:从 Hub/镜像站同步指定架构到私有仓库,含凭据与并行复制优化

Made-with: Cursor
2026-04-10 17:35:18 +08:00
5c856749c1 fix(deploy): 浅克隆说明、README 精简与 Docker 自动安装可观测性
Some checks are pending
Test start.ps1 (Windows) / test-windows (push) Waiting to run
- README: Windows 一条 PowerShell 命令,保留脚本权限说明;合并重复段落
- start.sh/ps1: git clone --depth 1 示例
- start.ps1: 选 [2] 时输出 winget/choco 日志与退出码,失败原因可辨;Read-Host Trim;winget 后若 docker 可用则视为成功

Made-with: Cursor
2026-04-10 17:09:18 +08:00
b63318709e chore(start.ps1): 移除 Git 自动安装逻辑
Some checks are pending
Test start.ps1 (Windows) / test-windows (push) Waiting to run
部署脚本不依赖本机 git,winget/choco 安装与 PATH 刷新已无必要。

Made-with: Cursor
2026-04-10 16:44:58 +08:00
3b7b06e06f merge origin/main: sync upstream; docker-compose.yml use remote version
Some checks are pending
Test start.ps1 (Windows) / test-windows (push) Waiting to run
Made-with: Cursor
2026-04-10 16:39:00 +08:00
ce042333c4 docs(win): 分行展示一键部署命令,避免 git 误解析参数
- README: Windows 克隆与启动改为分行,补充单行安全写法与说明
- start.ps1: 无 Git 时 winget/choco 自动安装、PATH 刷新、UTF-8 BOM 与文件头使用说明

Made-with: Cursor
2026-04-10 16:31:44 +08:00
988fceff00 chore(docker): 更新 Docker Compose 配置 2026-04-10 16:06:17 +08:00
e5f412f2cd chore(docker): 移除不必要的数据卷挂载配置 2026-04-10 16:00:26 +08:00
1aab453374 fix(redis): 修复 Redis 容器只读模式配置问题 2026-04-10 15:28:25 +08:00
2f0ae76273 feat(install): 支持 macOS 系统的一键部署
- 更新 README.md 标题为 Linux/Mac 兼容
- 添加 macOS 系统检测逻辑,使用 uname 命令识别 Darwin 内核
- 实现 macOS Docker Desktop 的自动安装功能,通过 Homebrew 安装
- 添加 Docker Desktop 启动等待机制,最多等待 120 秒
- 提供 macOS 用户安装选项,支持自动或手动安装模式
- 跳过 macOS 上的 systemd 服务管理命令执行
2026-04-09 21:26:56 +08:00
8365433014 docs(README): 添加部署咨询二维码 2026-04-09 18:48:46 +08:00
8ea92ca7a8 docs(README): 添加部署咨询二维码 2026-04-09 18:48:04 +08:00
c60bc54fdc Merge remote-tracking branch 'origin/main' 2026-04-09 13:43:42 +08:00
3a14c722e0 fix(deploy): 优化 HTTPS 配置和 Nginx 模板检查 2026-04-09 13:43:27 +08:00
a59b3930bb fix(deploy): 修复 start.ps1 闪退并增强稳定性
Some checks failed
Test start.ps1 (Windows) / test-windows (push) Has been cancelled
重建部署脚本并修复解析阶段报错,避免因脚本损坏导致运行后直接退出;同时保留 dry-run 与 Docker 检查流程,提升可诊断性与非交互执行稳定性。

Made-with: Cursor
2026-04-09 10:31:03 +08:00
7fe9762dc9 fix(installer): 修复 Docker Compose 安装逻辑
- 使用 curl 下载指定 URL 的 docker-compose 二进制文件
- 通过 install 命令替代 mv 和 chmod 设置权限
- 使用临时文件存储下载的二进制文件并及时清理
- 修复了旧版 docker-compose 检测后的安装流程
2026-04-08 16:45:52 +08:00
6bb62904e0 fix(config): 更新服务名称和配置检测逻辑
Some checks failed
Test start.ps1 (Windows) / test-windows (push) Has been cancelled
- 将 comfy-server 替换为 easyai-server 在环境配置文件中
- 修改 README.md 中的服务引用名称
- 添加 WS_GATEWAY_LOG_LEVEL 日志级别配置
- 实现 nginx 配置文件自动检测和选择功能
- 更新 https.sh 中的配置文件查找逻辑
2026-04-04 23:01:43 +08:00
f33b0850fe feat(config): 添加每日记忆整理配置和域名配置交互功能
Some checks failed
Test start.ps1 (Windows) / test-windows (push) Has been cancelled
- 在 .env.AMS.sample 和 .env.sample 中新增记忆整理相关配置项
- 实现了 https.sh 脚本中的域名配置交互与文件生成功能
- 支持配置文件中域名的替换和新增操作
- 在 README.md 中补充了一键启动脚本使用说明和 HTTPS 配置指南
- 添加了 docker-compose.yml 单独更新命令说明
2026-04-02 17:45:29 +08:00
c0ee3bee52 docs(README): 移除单独更新docker-compose.yml的相关说明
- 删除了关于单独更新docker-compose.yml文件的步骤说明
- 移除了相应的bash命令示例代码块
- 清理了相关的备份和下载操作文档
2026-04-01 09:50:12 +08:00
2d924f5631 docs(readme): 更新文档移除一键启动脚本说明
- 移除了 Linux/Ubuntu 和 Windows 一键启动脚本的相关说明
- 添加了其他功能配置的概述
- 保留了 PDF 图文解析 Markdown 功能的配置说明
2026-04-01 09:49:52 +08:00
0496fe7288 docs(readme): 更新升级指南文档
- 添加老客户旧版本部署包升级
2026-04-01 09:39:26 +08:00
3bab0ecbce fix(server): 移除HTTP端口映射配置 2026-03-31 17:52:04 +08:00
341408d23c feat(config): 添加 WebSocket 端口配置支持 2026-03-31 17:49:57 +08:00
b7dddfb750 fix(https): 修复域名提取携带分号导致证书申请失败
修正 https.sh 中 server_name 提取与 certbot 参数构建逻辑,避免将 `credit99.cn;` 等非法域名传给 certbot;同时在 start.sh 增加域名规范化与格式校验,提前拦截协议前缀、路径和分号等脏输入。

Made-with: Cursor
2026-03-31 15:04:56 +08:00
e66b3c71af fix(gateway): 修复ws-gateway端口配置默认值问题 2026-03-30 16:03:50 +08:00
a6239f0057 fix(comfyui): 修正服务依赖配置
- 将comfy-server依赖替换为easyai-server
- 确保服务启动顺序正确
2026-03-30 01:26:37 +08:00
d8540d1172 rename(comfyAI): 将项目名称从comfyAI统一更改为easyai 2026-03-30 01:10:22 +08:00
7ebc7d5be4 feat(config): default server-to-gateway connection to internal network
Wire WS gateway TCP host/port into the server service environment with ws-gateway:4002 defaults so production deployments in easyai connect over internal container networking out of the box.

Made-with: Cursor
2026-03-30 01:07:33 +08:00
f4bc04acde feat(config): 统一 ws-gateway 端口变量命名
Some checks failed
Test start.ps1 (Windows) / test-windows (push) Has been cancelled
统一部署侧 WebSocket 端口配置为 CONFIG_WS_PORT,移除 SERVER_WS_PORT 的重复语义,并同步更新映射与注释说明以降低运维歧义。

Made-with: Cursor
2026-03-29 10:05:57 +08:00
80c9b5576a feat(config): 添加 Dozzle 端口配置支持
Some checks failed
Test start.ps1 (Windows) / test-windows (push) Has been cancelled
- 在 .env.sample 中新增 DOZZLE_PORT 配置项,默认值为 8080
- 修改 docker-compose.yml 中 Dozzle 服务端口映射使用环境变量
- 实现端口配置的可自定义化,提升部署灵活性
2026-03-22 22:07:28 +08:00
d5fa673b4e 修复不签HTTPS会退出脚本的问题 2026-03-22 21:55:28 +08:00
e2326e50c9 修复不签HTTPS会退出脚本的问题 2026-03-22 21:52:21 +08:00
0bd8c4f359 feat(config): 增加记忆去重阈值示例配置
在 AMS 示例环境变量中新增向量与文本去重阈值,便于正式部署时控制缺少 embedding 模型场景下的重复写入策略。

Made-with: Cursor
2026-03-21 14:40:47 +08:00
d6d9705566 feat(config): 更新环境配置中的嵌入模型设置
- 将 MEMORY_EMBEDDING_MODEL 从 text-embedding-v4 更改为
2026-03-20 22:52:13 +08:00
41549e8a72 feat(comfyui):
- 在docker-compose.yml中为ComfyUI容器添加MEMORY_DATABASE_URL环境变量
- 设置默认值指向easyai-pgvector数据库服务
2026-03-20 22:45:56 +08:00
ac795ad38d config(env): 设置对话压缩默认模型并移除内存服务配置文件
- 为 MEMORY_CHAT_MODEL 环境变量设置默认值 qwen-plus
- 从 docker-compose.yml 中移除 agent-memory 服务的 profiles 配置
- 调整内存服务容器配置以优化部署流程
2026-03-20 22:04:13 +08:00
dd1c905cd8 fix: update.ps1 保存为 UTF-8 BOM 避免 PowerShell 5.1 解析闪退
Made-with: Cursor
2026-03-20 18:43:21 +08:00
512dd66762 feat: 优化 update 脚本,新增 Windows 版 update.ps1
- update.sh: 改为 git pull 拉取整个仓库,命令行内选择更新方式(默认拉取+更新)
- update.ps1: 新增 Windows 更新脚本,功能与 Linux 版一致
- README: 更新 update 脚本说明及 Windows 使用方式

Made-with: Cursor
2026-03-20 18:35:33 +08:00
f2f10d543e ```
Some checks failed
Test start.ps1 (Windows) / test-windows (push) Has been cancelled
chore(config): 移除 MEMORY_DATABASE_URL 配置并更新 docker-compose 环境文件

- 移除了 .env.AMS.sample 中的 MEMORY_DATABASE_URL 配置项
- 在 docker-compose.yml 中为服务添加了 .env.ASG 环境文件引用
- 更新了环境配置文件的加载方式
```
2026-03-20 18:24:30 +08:00
a70545b702 feat: 部署脚本支持 .env.AMS,与 ASG 一致从 .sample 生成无后缀文件
Made-with: Cursor
2026-03-20 18:23:18 +08:00
ded45063d9 feat: 新增 Agent 记忆服务部署、重命名容器、整理 env 配置
- 新增 agent-memory 服务与 .env.AMS.sample
- easyai-pgvector 共用 PostgreSQL,独立库 easyai_memory
- 新增 docker/postgres/init-pgvector.sql 初始化
- 容器名: comfyAI-web→easyai-web, comfy-server→easyai-server
- easyai-asg-pg→easyai-pgvector
- 记忆服务端口配置移至 .env(comfy-server 调用用)
- 整理 .env.sample 结构,新增 /ams-api/ Nginx 代理

Made-with: Cursor
2026-03-20 17:06:39 +08:00
e64a90332c feat: 优化 Windows 部署与文档
Some checks failed
Test start.ps1 (Windows) / test-windows (push) Has been cancelled
- start.ps1: 局域网 IP 自动检测, 部署完成提示默认账户 admin/123456
- start.ps1: 修复 UTF-8 BOM 避免 PowerShell 5.1 解析闪退
- docker-compose: dozzle 容器增加 restart 与 logging 配置
- 新增 reset-docker-network.ps1 网络重置脚本
- README: 顶部增加 Linux/Windows 一键部署命令, Windows 权限说明

Made-with: Cursor
2026-03-11 14:41:53 +08:00
e9c594c3e6 feat: RabbitMQ 改用 DaoCloud 国内镜像,保留官方和阿里云地址,添加 watchtower 自动更新
Made-with: Cursor
2026-03-11 10:31:54 +08:00
f37fd958e1 fix: 将退出原因写入 start.ps1.log 便于闪退排查
Some checks are pending
Test start.ps1 (Windows) / test-windows (push) Waiting to run
- 新增 Write-Log 与日志文件 start.ps1.log
- 脚本加载/正常结束/错误退出均写入日志
- trap 捕获异常时写入错误信息与堆栈
- README 补充日志位置说明

Made-with: Cursor
2026-03-10 22:15:54 +08:00
fe370bd5bc fix: 修复 Windows start.ps1 闪退,保持终端不关闭便于 Debug
Some checks are pending
Test start.ps1 (Windows) / test-windows (push) Waiting to run
- 增加 trap 错误捕获与堆栈输出
- 增加 Wait-ForExit 结束时暂停,避免窗口闪退
- 使用 $PSScriptRoot 获取脚本目录
- README 补充 Windows 权限配置与启动说明

Made-with: Cursor
2026-03-10 22:13:12 +08:00
b7a11abe9f feat: 新增 Windows 一键部署脚本 start.ps1
Some checks are pending
Test start.ps1 (Windows) / test-windows (push) Waiting to run
- start.ps1: PowerShell 部署脚本,支持本地/局域网 IP 访问
- docs/Windows一键部署方案.md: 实现方案与测试说明
- scripts/test-start-ps1-env.py: .env 替换逻辑验证
- .github/workflows/test-start-ps1.yml: Windows CI 测试

Made-with: Cursor
2026-03-10 21:59:12 +08:00
ea70cecef1 docs: HTTPS 启用时增加 80、443 端口放行说明
Made-with: Cursor
2026-03-09 16:56:15 +08:00
bb2373d4f6 feat(deploy): 优化部署脚本,支持问答式配置
- start.sh: 交互式选择 IP/域名访问,自动生成 .env、.env.tools、.env.ASG
- start.sh: 移除内置克隆逻辑,需先 git clone 再执行
- 新增 docker/verify: Docker 验证环境与快速验证脚本

Made-with: Cursor
2026-03-09 16:40:38 +08:00
59a1a88e29 优化脚本,支持一键部署 2026-03-09 16:22:33 +08:00
5bca174da8 fix tools容器中环境变量配置时效的问题 2026-03-07 13:29:12 +08:00
b3f969b3a3 fix: PG 18 数据卷挂载路径修正为 /var/lib/postgresql
Made-with: Cursor
2026-03-05 23:07:13 +08:00
1b85369903 feat(proxy): 添加沙箱 API 转发配置 /sandbox/
Made-with: Cursor
2026-03-04 16:38:27 +08:00
24 changed files with 2743 additions and 472 deletions

52
.env.AMS.sample Normal file
View File

@ -0,0 +1,52 @@
# ============================================
# Agent 记忆服务agent-memory环境变量
# 使用前请复制为 .env.AMS 并根据实际情况修改
# ============================================
# ---------- PostgreSQL复用 easyai-pgvector----------
# ---------- 主服务连接(用于 Embedding 与对话压缩)----------
# 主服务 API 地址(容器内网地址)
MEMORY_AI_BASE_URL=http://easyai-server:3001
MEMORY_AI_API_KEY=
# 默认模型配置接口路径已内置为 /content/llm/default-models无需额外环境变量
# ---------- Embeddings ----------
MEMORY_EMBEDDINGS_PATH=/v1/embeddings
MEMORY_EMBEDDING_MODELS_PATH=/v1/embeddings/models
MEMORY_EMBEDDING_DIMENSION=1024
MEMORY_EMBEDDING_MODEL=Qwen3-Embedding-v4
MEMORY_SCORE_CONFIDENCE_BASE=0.6
MEMORY_SCORE_CONFIDENCE_GAIN=0.4
MEMORY_SCORE_IMPORTANCE_BASE=0.7
MEMORY_SCORE_IMPORTANCE_GAIN=0.3
MEMORY_DEDUP_MIN_SCORE=0.92
MEMORY_TEXT_DEDUP_MIN_SCORE=0.9
# ---------- 对话压缩 ----------
MEMORY_CHAT_COMPLETIONS_PATH=/v1/chat/completions
MEMORY_CHAT_MODELS_PATH=/v1/models
MEMORY_CHAT_MODEL=qwen-plus
MEMORY_COMPRESSION_ENABLED=true
MEMORY_COMPRESSION_MIN_LENGTH=80
# ---------- 每日记忆整理 ----------
# 是否启用每天凌晨 2 点记忆整理(去重、冲突处理)
MEMORY_MAINTENANCE_ENABLED=true
# dry-run: true=仅分析不落库;建议升级首日先开 true 观察
MEMORY_MAINTENANCE_DRY_RUN=false
# 每个租户单轮扫描上限
MEMORY_MAINTENANCE_BATCH_SIZE=200
# 是否启用 LLM 语义冲突裁决(复用会话总结模型,无需单独模型配置)
MEMORY_MAINTENANCE_LLM_ENABLED=true
# 单轮最多调用 LLM 裁决的冲突对数量(用于控成本)
MEMORY_MAINTENANCE_LLM_MAX_PAIRS=20
# ---------- 其他 ----------
# 日志级别
LOG_LEVEL=log,error,warn,debug
# 是否禁用 Swagger 文档true 禁用)
MEMORY_DOCS_DISABLE=false
# 记忆服务镜像版本
AMS_VERSION=latest

View File

@ -5,9 +5,8 @@
# ---------- PostgreSQL ---------- # ---------- PostgreSQL ----------
# Prisma 数据库连接字符串(容器内网地址) # Prisma 数据库连接字符串(容器内网地址)
ASG_DATABASE_URL=postgresql://easyai:easyai2025@easyai-asg-pg:5432/agent_governance?schema=public ASG_DATABASE_URL=postgresql://easyai:easyai2025@easyai-pgvector:5432/agent_governance?schema=public
# PostgreSQL 容器初始化配置(与 docker-compose 中 sg-postgres 保持一致)
ASG_POSTGRES_USER=easyai ASG_POSTGRES_USER=easyai
ASG_POSTGRES_PASSWORD=easyai2025 ASG_POSTGRES_PASSWORD=easyai2025
ASG_POSTGRES_DB=agent_governance ASG_POSTGRES_DB=agent_governance
@ -22,13 +21,13 @@ ASG_REDIS_DB=8
# ---------- 服务端口 ---------- # ---------- 服务端口 ----------
# HTTP API 端口 # HTTP API 端口
ASG_PORT=3003 ASG_PORT=3003
# TCP 微服务端口(供 comfy-server 内部调用) # TCP 微服务端口(供 easyai-server 内部调用)
ASG_TCP_PORT=4003 ASG_TCP_PORT=4003
ASG_TCP_HOST=0.0.0.0 ASG_TCP_HOST=0.0.0.0
# ---------- 主服务连接 ---------- # ---------- 主服务连接 ----------
# Agent 调用时需要访问的 comfy-server 地址(容器内网地址) # Agent 调用时需要访问的 easyai-server 地址(容器内网地址)
ASG_MAIN_BACKEND_URL=http://comfy-server:3001 ASG_MAIN_BACKEND_URL=http://easyai-server:3001
# 管理员账号(用于 Agent 登录获取 token # 管理员账号(用于 Agent 登录获取 token
ASG_ADMIN_USERNAME=admin ASG_ADMIN_USERNAME=admin
ASG_ADMIN_PASSWORD=123456 ASG_ADMIN_PASSWORD=123456

View File

@ -1,71 +0,0 @@
# =============================================================================
# ComfyAI Web 静态资源 CDN 初始化配置
# 用于 comfyAI-web-init 容器:构建后上传前端静态资源到 OSS/CDN
# 部署时请根据实际使用的 OSS 服务商填写对应配置
# =============================================================================
# -----------------------------------------------------------------------------
# 基础开关与路径
# -----------------------------------------------------------------------------
# 是否启用静态资源 CDN 加速
# true: 构建完成后将静态资源上传至 OSS前端通过 CDN 地址加载
# false: 不启用,静态资源随应用一起部署(不推荐生产环境)
STATIC_CDN_ENABLED=true
# 前端静态资源在 OSS 中的根目录(桶内路径前缀)
# 例如: static / frontend-assets
# 与 STATIC_CDN_BASE_URL 末尾路径保持一致,用于上传时的目录划分
STATIC_CDN_ROOT_PATH=static
# 静态资源的完整访问基础 URL不含末尾斜杠
# 用户访问前端时加载 JS/CSS/图片的根地址
# 示例: https://cdn.example.com/static 或 http://minio.example.com:9000/bucket/frontend-assets
STATIC_CDN_BASE_URL=https://cdn.example.com/static
# -----------------------------------------------------------------------------
# OSS 服务商与连接配置
# -----------------------------------------------------------------------------
# OSS 服务商类型(小写)
# 可选: aliyun | tencent | minio | qiniu | s3Compatible
# aliyun=阿里云 OSS, tencent=腾讯云 COS, minio=MinIO, qiniu=七牛云, s3Compatible=兼容 S3 的存储
STATIC_CDN_OSS_PROVIDER=aliyun
# OSS 服务端点Endpoint
# 阿里云: oss-cn-shanghai.aliyuncs.com
# 腾讯云: cos.ap-guangzhou.myqcloud.com
# MinIO: minio.example.com 或 宿主机访问容器时用 host.docker.internal
# 七牛: 无需填写 endpoint使用 region
STATIC_CDN_OSS_ENDPOINT=oss-cn-shanghai.aliyuncs.com
# OSS 存储桶名称Bucket
# 需提前在对应云控制台或 MinIO 中创建好
STATIC_CDN_OSS_BUCKET=your_bucket
# OSS Access Key ID访问密钥 ID
STATIC_CDN_OSS_ACCESS_KEY=your_access_key_id
# OSS Secret Access Key访问密钥 Secret
# 请勿提交到版本库,生产环境建议使用密钥管理服务
STATIC_CDN_OSS_SECRET_KEY=your_secret_access_key
# OSS 区域Region部分服务商必填
# 阿里云: oss-cn-shanghai
# 腾讯云: ap-guangzhou
# MinIO/自建: 可留空或填 us-east-1
# 七牛: 如 z0华东
STATIC_CDN_OSS_REGION=oss-cn-shanghai
# 自定义域名(可选)
# 若通过自有域名访问 OSS如 cdn.example.com在此填写否则留空将使用 endpoint + bucket 生成地址
STATIC_CDN_OSS_DOMAIN=
# OSS 服务端口(可选)
# 非标准端口时填写,如 MinIO 默认 9000标准 80/443 可留空
STATIC_CDN_OSS_PORT=
# 连接 OSS 时是否使用 HTTPS
# true: 使用 https生产推荐
# false: 使用 http本地 MinIO 调试时可设为 false
STATIC_CDN_OSS_USE_SSL=true

View File

@ -1,70 +1,88 @@
############################################# #############################################
#1、如下配置需要根据实际情况进行配置 # EasyAI 环境变量配置
############################################## # 复制为 .env 并根据实际情况修改
# 默认服务器地址本地不需要更改云服务需要修改为云端IP并放行对应端口 TODO #############################################
# ========== 1. 访问地址(部署时必改) ==========
# 默认服务器 API 地址,云服务需修改为云端 IP 并放行对应端口
NUXT_PUBLIC_BASE_APIURL=http://127.0.0.1:3001 NUXT_PUBLIC_BASE_APIURL=http://127.0.0.1:3001
#域名访问使用如下配置,使用/api进行转发并配置nginx代理/api至3001端口 # 域名访问NUXT_PUBLIC_BASE_APIURL=/api
#NUXT_PUBLIC_BASE_APIURL=/api
# 默认的服务器websocket地址本地不需要更改云服务需要修改为云端IP并放行对应端口 TODO # 默认 WebSocket 地址
NUXT_PUBLIC_BASE_SOCKETURL=ws://127.0.0.1:3002 NUXT_PUBLIC_BASE_SOCKETURL=ws://127.0.0.1:3002
#域名访问使用如下配置,配置为/,并代理/socket.io请求到3002端口 # 域名访问NUXT_PUBLIC_BASE_SOCKETURL=wss://yourwebsite.com/socket.io
#NUXT_PUBLIC_BASE_SOCKETURL=wss://yourwebsite.com/socket.io
# Agent 服务治理 API 地址,前端管理页面需要。IP访问填http://<IP>:3003域名访问填/asg-api # Agent 服务治理 API 地址,前端管理页面需要
NUXT_PUBLIC_SG_APIURL=http://127.0.0.1:3003 NUXT_PUBLIC_SG_APIURL=http://127.0.0.1:3003
#域名访问使用如下配置通过nginx代理转发 # 域名访问NUXT_PUBLIC_SG_APIURL=/asg-api
#NUXT_PUBLIC_SG_APIURL=/asg-api
############################################# # ========== 2. 服务端口 ==========
#2、以下部分可保持默认如果没有端口冲突生产环境可修改密码
##############################################
#comfyAI-web 前端应用暴露端口访问地址ip:3010访问初始化管理员账号admin,密码123456
WEB_PORT=3010 WEB_PORT=3010
#支持静态资源CDN将静态资源从服务器分离 # easyai-web 前端端口,访问地址 ip:3010初始化管理员 admin/123456
NUXT_APP_CDN_URL=
SERVER_HTTP_PORT=3001
# easyai-server 后端 HTTP 端口
# ws-gateway WebSocket 端口(统一作为对外访问映射端口使用)
CONFIG_WS_PORT=3002
# ws-gateway 容器内部 TCP 微服务监听地址(供 easyai-server 推送事件)
CONFIG_TCP_HOST=0.0.0.0
# ws-gateway 容器内部 TCP 微服务监听端口(默认 4002
CONFIG_TCP_PORT=4002
#视频编辑对外暴露端口
VIDEO_EDIT_PORT=8000 VIDEO_EDIT_PORT=8000
# 视频编辑服务对外端口
#沙箱环境对外端口不建议暴露如果需要暴露取消docker-compose.yml中的对应注释 AMS_PORT=3004
# Agent 记忆服务 HTTP 端口(启用 memory profile 时)
# ========== 3. Agent 记忆服务(启用 memory profile 时) ==========
MEMORY_TCP_HOST=agent-memory
MEMORY_TCP_PORT=4004
# easyai-server 调用 agent-memory 的 TCP 连接
# 记忆整理相关参数在 .env.AMS 中配置MEMORY_MAINTENANCE_*
# ========== 4. 沙箱环境 ==========
SANDBOX_PORT=8081 SANDBOX_PORT=8081
#SANDBOX jupyterlab 端口 # 不建议对外暴露
SANDBOX_JUPYTERLAB_PORT=8888 SANDBOX_JUPYTERLAB_PORT=8888
# 配置Jupter的token安全考虑建议设置
SANDBOX_JUPYTER_TOKEN=easyaiisbest SANDBOX_JUPYTER_TOKEN=easyaiisbest
# 建议设置 token
SANDBOX_SERVICE_BASE_URL= SANDBOX_SERVICE_BASE_URL=
# ========== 5. Redis ==========
#REDIS暴露端口默认不暴露
REDIS_PORT= REDIS_PORT=
# 默认不对外暴露
# Redis 容器镜像(可改为国内镜像站或自建仓库)
REDIS_IMAGE=registry.cn-shanghai.aliyuncs.com/comfy-ai/redis-aliyun:latest
CONFIG_COMFYUI_QUENE_REDIS_USERNAME= CONFIG_COMFYUI_QUENE_REDIS_USERNAME=
CONFIG_COMFYUI_QUENE_REDIS_PASSWORD= CONFIG_COMFYUI_QUENE_REDIS_PASSWORD=
#队列使用的DB
CONFIG_COMFYUI_QUENE_REDIS_DB=6 CONFIG_COMFYUI_QUENE_REDIS_DB=6
#普通缓存使用的DB
CONFIG_COMFYUI_CACHE_REDIS_DB=11 CONFIG_COMFYUI_CACHE_REDIS_DB=11
#MONGO 暴露端口,默认不暴露。用户名密码初次部署可以修改,更新请勿修改 # ========== 6. MongoDB ==========
MONGO_PORT=27017 MONGO_PORT=27017
# MongoDB 容器镜像(可改为国内镜像站或自建仓库)
MONGO_IMAGE=registry.cn-shanghai.aliyuncs.com/comfy-ai/mongo-aliyun:latest
# 固定 MongoDB 4.4 系列(与旧数据/旧客户端兼容、或需锁定 4.x 行为时使用;升级大版本前请备份并查阅迁移说明):
# MONGO_IMAGE=registry.cn-shanghai.aliyuncs.com/comfy-ai/mongo-aliyun:4.4
MONGO_INITDB_ROOT_USERNAME=username MONGO_INITDB_ROOT_USERNAME=username
MONGO_INITDB_ROOT_PASSWORD=password MONGO_INITDB_ROOT_PASSWORD=password
#comfy-server后端web服务暴露端口。一般情况下无需修改 # 初次部署可修改,更新请勿修改
SERVER_HTTP_PORT=3001
SERVER_WS_PORT=3002
#watchtower 监听端口,自动更新容器和通过浏览器查看容器日志
WATCHTOWER_PORT=8089
PORTAINER_PORT=8090
PORTAINER_HTTPS_PORT=8091
#网络代理链接gpt等需要设置 # ========== 7. 消息队列 RabbitMQ ==========
CONFIG_PROXY_URL= # RabbitMQ 容器镜像(可改为国内镜像站或自建仓库),备选示例:
# RABBITMQ_IMAGE=docker.m.daocloud.io/library/rabbitmq:4-management
# RABBITMQ_IMAGE=docker.dockerproxy.com/library/rabbitmq:4-management
# RABBITMQ_IMAGE=rabbitmq:4-management
RABBITMQ_IMAGE=registry.cn-shanghai.aliyuncs.com/easyaigc/mq:latest
#实例ID、集群情况下区分不同客户端
CONFIG_INSTANCE_ID=2025
#消息队列
CONFIG_MQ_PROTOCOL=amqp CONFIG_MQ_PROTOCOL=amqp
CONFIG_MQ_USER=admin CONFIG_MQ_USER=admin
CONFIG_MQ_PASSWORD=easyai2025 CONFIG_MQ_PASSWORD=easyai2025
@ -73,25 +91,82 @@ CONFIG_MQ_PORT=5672
CONFIG_MQ_ADMIN_PORT=15672 CONFIG_MQ_ADMIN_PORT=15672
CONFIG_MQ_VHOST=/ CONFIG_MQ_VHOST=/
#版本 # ========== 8. 鉴权与安全 ==========
VERSION=latest
#日志与调试
LOG_LEVEL=log,error,warn,debug
#Token过期时间单位秒
CONFIG_TOKEN_EXPIRE=1800 CONFIG_TOKEN_EXPIRE=1800
# token加密密钥可以修改为任意字符串
CONFIG_JWT_SECRET='this is a very secret secret' CONFIG_JWT_SECRET='this is a very secret secret'
CONFIG_TOKEN_SIGN_SK=easyai2025easyai CONFIG_TOKEN_SIGN_SK=easyai2025easyai
# ========== 9. 运维与调试 ==========
CONFIG_INSTANCE_ID=2025
# 集群情况下区分不同客户端
#minio CONFIG_PROXY_URL=
#MINIO_ROOT_USER=minioadmin # 连接 GPT 等外部服务时设置
#MINIO_ROOT_PASSWORD=minioadmin
LOG_LEVEL=log,error,warn,debug
# WS 网关专用日志级别(默认生产不输出 debug
WS_GATEWAY_LOG_LEVEL=log,error,warn
DOZZLE_PORT=8080
WATCHTOWER_PORT=8089
PORTAINER_PORT=8090
PORTAINER_HTTPS_PORT=8091
# ========== 10. WS Gateway 集群背板Redis ==========
# 是否启用 ws-gateway Redis 集群背板true=支持多节点路由false=仅单机本地投递
GATEWAY_CLUSTER_REDIS_ENABLED=true
# 当前 ws-gateway 节点 ID单节点可保持默认集群部署时每个实例必须唯一
GATEWAY_CLUSTER_NODE_ID=easyai-wsgateway-node-1
# 背板 Pub/Sub 频道名;用于节点间转发消息
GATEWAY_CLUSTER_REDIS_CHANNEL=easyai:wsgateway:cluster
# 路由表 key 前缀(记录 channel+clientId 对应的 nodeId
GATEWAY_CLUSTER_REDIS_ROUTE_PREFIX=easyai:wsgateway:route
# 路由 TTL连接存活期间会续租断开后自然过期
GATEWAY_CLUSTER_REDIS_ROUTE_TTL_SEC=120
# Redis 失联后自动重连间隔(毫秒)
GATEWAY_CLUSTER_REDIS_RECONNECT_INTERVAL_MS=5000
# 可选Redis URL配置后优先于 host/port/user/password/db
GATEWAY_CLUSTER_REDIS_URL=
# 以下为 URL 未配置时使用的拆分配置
GATEWAY_CLUSTER_REDIS_HOST=redis
GATEWAY_CLUSTER_REDIS_PORT=6379
GATEWAY_CLUSTER_REDIS_USERNAME=
GATEWAY_CLUSTER_REDIS_PASSWORD=
GATEWAY_CLUSTER_REDIS_DB=0
# ========== 11. easyai-server 发布事件到 ws-gatewayTCP ==========
# easyai-server 访问 ws-gateway 的 TCP 地址(容器网络内建议写服务名 ws-gateway
WS_GATEWAY_TCP_HOST=ws-gateway
# easyai-server 访问 ws-gateway 的 TCP 端口(需与 CONFIG_TCP_PORT 一致)
WS_GATEWAY_TCP_PORT=4002
# 事件发布 Pattern通常保持默认
WS_GATEWAY_TCP_EVENT_PATTERN=gateway.event.publish
# 发布超时时间(毫秒);超时只记录 ERROR不中断主进程
WS_GATEWAY_TCP_TIMEOUT_MS=1500
# ========== 12. WS 会话鉴权MCP 风格,可选) ==========
# true=客户端必须鉴权后才能建立可用会话false=允许匿名会话
WS_AUTH_REQUIRED=false
# 鉴权阶段超时时间(毫秒)
WS_AUTH_TIMEOUT_MS=6000
# 可用鉴权方法逗号分隔none/bearer/ws_ticket
WS_AUTH_METHODS=none,bearer
# bearer 令牌列表(逗号分隔,生产环境请使用安全配置中心)
WS_AUTH_BEARER_TOKENS=
# ws_ticket 票据列表(逗号分隔,适合短时授权)
WS_AUTH_WS_TICKETS=
# ========== 13. 静态资源 CDN可选 ==========
NUXT_APP_CDN_URL=
# ========== 14. 版本 ==========
VERSION=latest
# ========== 15. OSS 配置可选PDF 解析图片上传) ==========
# 可填写 .env.tools 或在此覆盖
# OSS_ENDPOINT=
# OSS_ACCESS_KEY_ID=
# OSS_ACCESS_KEY_SECRET=
# OSS_BUCKET=
# OSS_REGION=us-east-1
# OSS_DOMAIN=

38
.github/workflows/test-start-ps1.yml vendored Normal file
View File

@ -0,0 +1,38 @@
# 在 Windows 上测试 start.ps1DRY_RUN 模式,不启动 Docker
name: Test start.ps1 (Windows)
on:
push:
paths:
- 'start.ps1'
- '.env.sample'
- '.github/workflows/test-start-ps1.yml'
pull_request:
paths:
- 'start.ps1'
- '.env.sample'
- '.github/workflows/test-start-ps1.yml'
workflow_dispatch:
jobs:
test-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Run start.ps1 (DRY_RUN)
env:
DEPLOY_DRY_RUN: "1"
DEPLOY_IP: "192.168.1.100"
run: |
powershell -ExecutionPolicy Bypass -File .\start.ps1
- name: Verify .env
run: |
$api = Select-String -Path .env -Pattern '^NUXT_PUBLIC_BASE_APIURL=' | ForEach-Object { $_.Line }
$socket = Select-String -Path .env -Pattern '^NUXT_PUBLIC_BASE_SOCKETURL=' | ForEach-Object { $_.Line }
$sg = Select-String -Path .env -Pattern '^NUXT_PUBLIC_SG_APIURL=' | ForEach-Object { $_.Line }
if ($api -ne 'NUXT_PUBLIC_BASE_APIURL=http://192.168.1.100:3001') { exit 1 }
if ($socket -ne 'NUXT_PUBLIC_BASE_SOCKETURL=ws://192.168.1.100:3002') { exit 1 }
if ($sg -ne 'NUXT_PUBLIC_SG_APIURL=http://192.168.1.100:3003') { exit 1 }
Write-Host "OK: .env 配置正确"

264
README.md
View File

@ -1,13 +1,201 @@
## 一键部署
### Linux/Mac
```bash
git clone --depth 1 https://git.51easyai.com/wangbo/easyai.git && cd easyai && chmod +x start.sh && ./start.sh
```
### Windows
**PowerShell** 中执行:
```powershell
git clone --depth 1 "https://git.51easyai.com/wangbo/easyai.git" "easyai"; Set-Location "easyai"; powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1"
```
> **Windows 脚本权限说明**PowerShell 默认禁止运行脚本,直接双击 `start.ps1` 会闪退。
>
> - **推荐**:使用 `powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1"` 执行,无需修改系统策略
> - **或**:以管理员身份打开 PowerShell执行 `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`,之后可直接运行 `.\start.ps1`
---
🚀部署问题扫码咨询
![img.png](img.png)
## 更新升级
### 老用户(旧版本部署包)升级教程
如果你当前使用的是较早版本的部署包,**无法在旧包目录里直接执行 `git pull`** 来获取配置文件,建议按下面流程升级:
1. 先停止并下线旧项目容器:
```bash
cd ~/easyai
docker compose down
```
如果你的环境使用的是旧命令,请改用:
```bash
docker-compose down
```
2. 将旧目录重命名备份(示例改名为 `easyai2`
```bash
cd ~
mv easyai easyai2
```
3. 重新执行一键部署命令,按脚本提示完成初始化输入。
4. 当脚本询问是否启用 HTTPS 时:
- 如果你之前已经有可用证书,填写 `N`(不生成新证书)。
- 只有在需要新申请证书时,才选择启用并生成证书。
5. 完成上述迁移后,后续若有新的配置文件或版本更新,可直接在新的 `easyai` 目录中执行 `./update.sh` 进行更新。
update.sh 脚本用于自动更新 EasyAI 应用,包含以下功能:
- **拉取整个仓库**:执行 `git pull` 获取最新代码docker-compose.yml、start.sh、.env.*.sample 等全部文件)
- 自动补齐缺失的环境配置文件(.env、.env.tools、.env.ASG、.env.AMS从 .sample 生成且不覆盖已有文件)
- 兼容 `docker compose``docker-compose` 两种命令格式
- 自动拉取最新镜像并重启服务
### 使用步骤
1. [首次执行,后续无需重复执行]添加执行权限,命令:
```bash
chmod +x update.sh
```
2. 执行更新(默认会 `git pull` 拉取整个仓库)
```bash
./update.sh
```
> **注意**update.sh 需要在 Git 克隆的目录下运行。若通过 zip 下载而非 git clone请先使用 `git clone` 获取项目。
### 使用方式
- 执行 `./update.sh` 后会**命令行内选择**更新方式:
- `[1]` 更新并拉取仓库git pull+ 更新镜像并重启(**默认**,回车即选)
- `[2]` 仅更新镜像并重启(跳过 git pull适用于有本地修改不想被覆盖的场景
- 如果本次**不涉及配置文件更新**(如 `.env*`、`docker-compose.yml`、`easyai-proxy.conf*` 无变更),可直接选择 `[2]`,仅更新后台服务镜像并重启即可。
- **查看帮助**`./update.sh -h` 或 `./update.sh --help`
### 更新说明
- 脚本会执行 `git pull` 拉取整个仓库最新代码
- 拉取后会检查并补齐缺失的 .env、.env.tools、.env.ASG、.env.AMS不会覆盖已有文件
- 最后执行 `docker compose pull``docker compose up -d` 拉取镜像并重启服务
### Windows 用户update.ps1
Windows 下使用 `update.ps1`,功能与 Linux 版一致:
```powershell
.\update.ps1
```
- 执行后会**命令行内选择**`[1]` 更新并拉取仓库 + 更新镜像(默认);`[2]` 仅更新镜像
- 需在 Git 克隆的 easyai 目录下运行
---
## 重要更新记录: ## 重要更新记录:
### 2026.3.20
1. **新增 Agent 记忆服务AMS模块**:新增 `agent-memory`Agent 长期记忆)容器,复用 `easyai-pgvector` 数据库(需 pgvector 扩展),用于支持 Agent 对话记忆、向量召回与反馈能力。
2. **新增环境变量文件**:新增 `.env.AMS.sample` 文件,包含记忆服务所需的全部环境变量。
3. 主服务 `easyai-server` 新增 `MEMORY_TCP_HOST``MEMORY_TCP_PORT` 环境变量,用于内部 TCP 微服务通信。
4. **Nginx 代理**`easyai-proxy.conf.sample` 中新增 `/ams-api/` 路径代理(可选)。
#### 升级步骤
**步骤一:更新文件**
将以下文件更新到最新版本:
- `docker-compose.yml`
- `easyai-proxy.conf.sample`
- `docker/postgres/init-pgvector.sql`PostgreSQL 首次启动时创建 vector 扩展)
新增文件复制到部署目录:
- `.env.AMS.sample` → 复制为 `.env.AMS` 并根据实际环境修改
**步骤二:配置 `.env.AMS`**
```bash
cp .env.AMS.sample .env.AMS
```
根据实际环境修改 `.env.AMS` 中的关键配置:
```dotenv
# PostgreSQL 连接(独立库 easyai_memory与 .env.ASG 中账号密码一致)
MEMORY_DATABASE_URL=postgresql://easyai:easyai2025@easyai-pgvector:5432/easyai_memory?schema=public
# 主服务 API 地址(用于 Embedding 与对话压缩)
MEMORY_AI_BASE_URL=http://easyai-server:3001
# Embedding 模型与维度(需与主服务一致)
MEMORY_EMBEDDING_DIMENSION=1024
MEMORY_EMBEDDING_MODEL=text-embedding-v4
# 每日记忆整理(默认每天凌晨 2 点执行)
MEMORY_MAINTENANCE_ENABLED=true
# 升级首日建议 true确认无误后再改为 false
MEMORY_MAINTENANCE_DRY_RUN=false
# 单轮每租户处理上限
MEMORY_MAINTENANCE_BATCH_SIZE=200
# 启用语义冲突裁决(复用会话总结模型,无需单独配置模型)
MEMORY_MAINTENANCE_LLM_ENABLED=true
MEMORY_MAINTENANCE_LLM_MAX_PAIRS=20
```
说明:
- `MEMORY_MAINTENANCE_ENABLED`:总开关,`false` 时不执行每日整理。
- `MEMORY_MAINTENANCE_DRY_RUN``true` 仅记录分析和审计,不执行软删除。
- `MEMORY_MAINTENANCE_LLM_ENABLED`:开启后冲突处理优先使用会话总结模型做语义裁决,失败会回退规则处理。
- `MEMORY_MAINTENANCE_LLM_MAX_PAIRS`:单轮最多调用模型裁决的冲突对数,用于控制成本。
**步骤三:启动服务**
记忆服务使用 Docker Compose Profile需显式启用
```bash
cd ~/easyai
# 启动全部服务(含记忆服务)
docker compose --profile memory up -d
# 或仅启动基础服务(不含记忆)
docker compose up -d
```
新增容器:`agent-memory`Agent 记忆服务),复用 `easyai-pgvector`,使用独立库 `easyai_memory`。初始化流程与 ASG 一致:
- **PostgreSQL 首次启动**`docker/postgres/init-pgvector.sql` 创建 `vector`、`pgcrypto` 扩展
- **easyai-asg 启动**entrypoint 执行 `prisma migrate deploy`,创建治理相关表
- **agent-memory 启动**entrypoint 执行 `prisma migrate deploy`,创建 `memory_records` 等表
**注意**`easyai-pgvector` 使用 `registry.cn-shanghai.aliyuncs.com/easyaigc/pgvector:0.8.2-pg18-trixie`(含 pgvector 扩展)。若此前使用其他镜像且已有数据,升级前请备份 `asg_postgres_data` 卷。
**步骤四:验证**
```bash
# 检查容器状态
docker compose ps agent-memory
# 检查记忆服务健康状态
curl http://127.0.0.1:3004/health
# 通过 Nginx 代理访问(配置 Nginx 后)
curl https://<你的域名>/ams-api/health
```
> **注意**:记忆服务默认不启动,使用 `docker compose --profile memory up -d` 显式启用。若不需要 Agent 记忆功能,保持 `docker compose up -d` 即可,主服务会正常运行(记忆相关能力不可用)。
---
### 2026.3.2 ### 2026.3.2
1. **新增 Agent 服务治理ASG模块**:新增 `easyai-asg`Agent 服务治理)容器和独立的 `easyai-asg-pg`PostgreSQL 18数据库容器用于支持 Agent 自动化治理能力。 1. **新增 Agent 服务治理ASG模块**:新增 `easyai-asg`Agent 服务治理)容器和独立的 `easyai-pgvector`PostgreSQL 18数据库容器用于支持 Agent 自动化治理能力。
2. **新增 Nginx 反向代理**:在 `easyai-proxy.conf.sample` 中新增 `/asg-api/` 路径代理,用于暴露 ASG 服务的 REST API。 2. **新增 Nginx 反向代理**:在 `easyai-proxy.conf.sample` 中新增 `/asg-api/` 路径代理,用于暴露 ASG 服务的 REST API。
3. **新增环境变量文件**:新增 `.env.ASG.sample` 文件,包含 ASG 服务所需的全部环境变量。 3. **新增环境变量文件**:新增 `.env.ASG.sample` 文件,包含 ASG 服务所需的全部环境变量。
4. 主服务 `comfy-server` 新增 `ASG_TCP_HOST``ASG_TCP_PORT` 环境变量,用于内部 TCP 微服务通信。 4. 主服务 `easyai-server` 新增 `ASG_TCP_HOST``ASG_TCP_PORT` 环境变量,用于内部 TCP 微服务通信。
5. **前端新增环境变量**`.env` 中新增 `NUXT_PUBLIC_SG_APIURL`,用于前端治理管理页面调用 ASG API。 5. **前端新增环境变量**`.env` 中新增 `NUXT_PUBLIC_SG_APIURL`,用于前端治理管理页面调用 ASG API。
#### 升级步骤 #### 升级步骤
@ -41,7 +229,7 @@ cp .env.ASG.sample .env.ASG
根据实际环境修改 `.env.ASG` 中的关键配置: 根据实际环境修改 `.env.ASG` 中的关键配置:
```dotenv ```dotenv
# PostgreSQL 连接(默认使用容器内网地址,一般无需修改) # PostgreSQL 连接(默认使用容器内网地址,一般无需修改)
ASG_DATABASE_URL=postgresql://easyai:easyai2025@easyai-asg-pg:5432/agent_governance?schema=public ASG_DATABASE_URL=postgresql://easyai:easyai2025@easyai-pgvector:5432/agent_governance?schema=public
ASG_POSTGRES_USER=easyai ASG_POSTGRES_USER=easyai
ASG_POSTGRES_PASSWORD=easyai2025 ASG_POSTGRES_PASSWORD=easyai2025
@ -50,7 +238,7 @@ ASG_REDIS_HOST=redis
ASG_REDIS_PASSWORD= # 与主服务 Redis 密码保持一致 ASG_REDIS_PASSWORD= # 与主服务 Redis 密码保持一致
# 主服务连接地址(容器内网地址) # 主服务连接地址(容器内网地址)
ASG_MAIN_BACKEND_URL=http://comfy-server:3001 ASG_MAIN_BACKEND_URL=http://easyai-server:3001
# 管理员账号(用于 Agent 调用时登录获取 token # 管理员账号(用于 Agent 调用时登录获取 token
ASG_ADMIN_USERNAME=admin ASG_ADMIN_USERNAME=admin
ASG_ADMIN_PASSWORD=123456 ASG_ADMIN_PASSWORD=123456
@ -85,13 +273,13 @@ cd ~/easyai
docker compose up -d docker compose up -d
``` ```
新增容器:`easyai-asg-pg`PostgreSQL`easyai-asg`Agent 服务治理),数据库会在首次启动时自动完成初始化和迁移。 新增容器:`easyai-pgvector`PostgreSQL`easyai-asg`Agent 服务治理),数据库会在首次启动时自动完成初始化和迁移。
**步骤五:验证** **步骤五:验证**
```bash ```bash
# 检查容器状态 # 检查容器状态
docker compose ps easyai-asg-pg easyai-asg docker compose ps easyai-pgvector easyai-asg
# 检查 ASG 服务健康状态 # 检查 ASG 服务健康状态
curl http://127.0.0.1:3003/health curl http://127.0.0.1:3003/health
@ -226,7 +414,7 @@ start.sh 脚本用于服务器一键安装启动EasyAI应用
### 首次安装部署步骤并使用服务器公网IP进行访问 ### 首次安装部署步骤并使用服务器公网IP进行访问
1. 克隆脚本和相关文件到服务器 1. 克隆脚本和相关文件到服务器
```bash ```bash
git clone https://git.51easyai.com/wangbo/easyai.git git clone --depth 1 https://git.51easyai.com/wangbo/easyai.git
# 进入easyai目录 # 进入easyai目录
cd easyai cd easyai
``` ```
@ -247,6 +435,25 @@ chmod +x start.sh
``` ```
6. 脚本运行完成无错误,并且提示`EasyAI应用启动成功`表示应用启动成功打开浏览器输入服务器的公网ip3010或者局域网IP3010即可访问EasyAI应用 6. 脚本运行完成无错误,并且提示`EasyAI应用启动成功`表示应用启动成功打开浏览器输入服务器的公网ip3010或者局域网IP3010即可访问EasyAI应用
## Windows 一键启动
**不要双击** `start.ps1`(易闪退)。在 **PowerShell** 中执行:
```powershell
git clone --depth 1 "https://git.51easyai.com/wangbo/easyai.git" "easyai"; Set-Location "easyai"; powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1"
```
已在 `easyai` 目录内时:
```powershell
powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1"
```
> **Windows 脚本权限说明**PowerShell 默认禁止运行脚本,直接双击 `start.ps1` 会闪退。
>
> - **推荐**:使用 `powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1"` 执行,无需修改系统策略
> - **或**:以管理员身份打开 PowerShell执行 `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`,之后可直接运行 `.\start.ps1`
### 启用HTTPS ### 启用HTTPS
1. [更改为你的域名]修改`easyai-proxy.conf`中域名`51easyai.com`为你的域名[可以使用Ctrl+F批量替换51easyai.com为你的域名] 1. [更改为你的域名]修改`easyai-proxy.conf`中域名`51easyai.com`为你的域名[可以使用Ctrl+F批量替换51easyai.com为你的域名]
2. [修改.env文件]修改如下两个环境变量为如下的对应的值 2. [修改.env文件]修改如下两个环境变量为如下的对应的值
@ -267,49 +474,6 @@ chmod +x https.sh
如果需要启用PDF图文解析Markdown功能需要`env.tools`中的OSS环境变量具体参考文件中的配置说明自动解析PDF图文将图片文件上传到OSS并解析成Markdown格式并返回 如果需要启用PDF图文解析Markdown功能需要`env.tools`中的OSS环境变量具体参考文件中的配置说明自动解析PDF图文将图片文件上传到OSS并解析成Markdown格式并返回
### 更新升级
update.sh 脚本用于自动更新 EasyAI 应用,包含以下功能:
- 自动检查和更新 `docker-compose.yml` 文件(从远程仓库获取最新版本)
- 兼容 `docker compose``docker-compose` 两种命令格式
- 自动拉取最新镜像并重启服务
#### 使用步骤
1. [首次执行,后续无需重复执行]添加执行权限,命令:
```bash
chmod +x update.sh
```
2. 执行更新(默认会检查并更新 docker-compose.yml
```bash
./update.sh
```
#### 参数选项
- **跳过 docker-compose.yml 更新**:如果你已经手动修改了 `docker-compose.yml` 文件,可以使用 `-s``--skip-compose-update` 参数跳过更新
```bash
# 跳过 docker-compose.yml 更新,仅更新容器镜像
./update.sh -s
# 或
./update.sh --skip-compose-update
```
- **查看帮助信息**
```bash
./update.sh -h
# 或
./update.sh --help
```
#### 更新说明
- 脚本会自动从远程仓库下载最新的 `docker-compose.yml` 文件
- 如果本地文件与远程文件不同,会将原文件备份为 `docker-compose.yml.bak`
- 如果本地文件已是最新版本,则跳过更新
- 更新完成后会自动执行 `docker-compose pull``docker-compose up -d` 来重启服务
## 常见问题 ## 常见问题
1. 某个服务无法运行 1. 某个服务无法运行

43
design.md Normal file
View File

@ -0,0 +1,43 @@
## 部署配置,通过问答让用户选择
1. 通过IP地址还是通过域名访问
2. 如果通过IP地址访问输入服务器IP并保证300130023003三个端口已经开放
3. 如果通过域名访问输入域名不含https://的前缀例如51easyai.com
3.1 是否启用https访问
4. 对于IP地址访问的情形复制`.env.sample`为`.env`,并将NUXT_PUBLIC_BASE_APIURL、NUXT_PUBLIC_BASE_SOCKETURL、NUXT_PUBLIC_SG_APIURL三个分别进行如下设置
```bash
NUXT_PUBLIC_BASE_APIURL=http://<用户输入的IP地址>:3001
NUXT_PUBLIC_BASE_SOCKETURL=ws://<用户输入的IP地址>:3002
NUXT_PUBLIC_SG_APIURL=http://<用户输入的IP地址>:3003
```
5. 对于使用域名的情况下情况,复制`.env.sampla`为`.env`,将上述3个变量设置为
```bash
NUXT_PUBLIC_BASE_APIURL=/api
NUXT_PUBLIC_BASE_SOCKETURL=wss://<用户输入的域名>/socket.io
NUXT_PUBLIC_SG_APIURL=/asg-api
```
6. 复制 `.env.tools.sample`为`.env.tools`,复制`.env.ASG.sample`为`.env.ASG.sample`
7. 对于使用域名的情况下,将`easyai-proxy.conf.sample`复制为`easyai-proxy.conf`,并将文件名修改为`用户输入的域名.conf`,并将`51easyai.com`替换为用户的域名
8. 执行原来的start脚本内容包括安装docker安装和部署
9. 如果启用https访问还要同步执行原来的https脚本
## 平台要求需要兼容主流的linux云平台
## 部署要求
直接通过一个命令访问,包含自动从https://git.51easyai.com/wangbo/easyai克隆项目
```
bash -c https://git.51easyai.com/wangbo/easyai/src/branch/main/start.sh
```

Binary file not shown.

View File

@ -2,33 +2,8 @@
# (各项参数均有详细的说明,理论情况下保持默认即可运行) # (各项参数均有详细的说明,理论情况下保持默认即可运行)
#version: '3' #version: '3'
services: services:
comfyAI-web-init: easyai-web:
container_name: comfyAI-web-init container_name: easyai-web
image: registry.cn-shanghai.aliyuncs.com/comfy-ai/one-ai:${VERSION}
labels:
- "com.centurylinklabs.watchtower.enable=true"
entrypoint: [ "sh", "-c", "node .output/scripts/static-upload-init.mjs && touch /tmp/init-done && exec sleep infinity" ]
restart: unless-stopped
healthcheck:
test: [ "CMD", "test", "-f", "/tmp/init-done" ]
interval: 5s
timeout: 3s
retries: 60
start_period: 120s
networks:
comfyai:
ipv4_address: 172.21.0.15
volumes:
- ./data/cdn-init:/tmp/cdn-init
env_file:
- .env.comfyAI-web-init
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "5"
comfyAI-web:
container_name: comfyAI-web
#更新修改冒号后面的版本号 #更新修改冒号后面的版本号
image: registry.cn-shanghai.aliyuncs.com/comfy-ai/one-ai:${VERSION} image: registry.cn-shanghai.aliyuncs.com/comfy-ai/one-ai:${VERSION}
#端口冲突时只需要修改前面的端口比如修改为3011:3010 #端口冲突时只需要修改前面的端口比如修改为3011:3010
@ -36,19 +11,12 @@ services:
- "com.centurylinklabs.watchtower.enable=true" - "com.centurylinklabs.watchtower.enable=true"
ports: ports:
- "${WEB_PORT}:3010" - "${WEB_PORT}:3010"
read_only: true # read_only: true
volumes:
# 这一行是关键。它将一个名为 './data/forend/.pm2' 的持久化卷挂载到容器内的 /app/.pm2 目录
- ./data/forend/.pm2:/app/.pm2
- ./data/cdn-init:/tmp/cdn-init:ro
networks: networks:
comfyai: easyai:
ipv4_address: 172.21.0.8 ipv4_address: 172.21.0.8
depends_on: depends_on:
comfy-server: - easyai-server
condition: service_started
comfyAI-web-init:
condition: service_healthy
restart: unless-stopped restart: unless-stopped
environment: environment:
# 默认服务器地址本地不需要更改云服务需要修改为云端IP并放行对应端口 # 默认服务器地址本地不需要更改云服务需要修改为云端IP并放行对应端口
@ -75,17 +43,17 @@ services:
memory: 1500MB memory: 1500MB
reservations: reservations:
memory: 600MB memory: 600MB
comfy-server: easyai-server:
container_name: comfy-server container_name: easyai-server
# 阿里云镜像地址 # 阿里云镜像地址
image: registry.cn-shanghai.aliyuncs.com/comfy-ai/comfy-server:${VERSION} # 阿里云 image: registry.cn-shanghai.aliyuncs.com/comfy-ai/comfy-server:${VERSION} # 阿里云
labels: labels:
- "com.centurylinklabs.watchtower.enable=true" - "com.centurylinklabs.watchtower.enable=true"
ports: ports:
- "${SERVER_HTTP_PORT}:3001" #http端口 - "${SERVER_HTTP_PORT}:3001" #http端口
read_only: true # read_only: true
networks: networks:
comfyai: easyai:
ipv4_address: 172.21.0.6 ipv4_address: 172.21.0.6
depends_on: depends_on:
- mongo - mongo
@ -97,7 +65,6 @@ services:
- ./data/restores:/app/restores - ./data/restores:/app/restores
- ./data/backend/app/tmp:/app/tmp - ./data/backend/app/tmp:/app/tmp
- ./data/tmp:/tmp - ./data/tmp:/tmp
- ./data/backend/.pm2:/app/.pm2
# - ./data/backend/pm2.config.js:/app/pm2.config.js # - ./data/backend/pm2.config.js:/app/pm2.config.js
restart: unless-stopped restart: unless-stopped
environment: environment:
@ -137,6 +104,12 @@ services:
# 服务治理 TCP 连接 # 服务治理 TCP 连接
- ASG_TCP_HOST=easyai-asg - ASG_TCP_HOST=easyai-asg
- ASG_TCP_PORT=4003 - ASG_TCP_PORT=4003
# Agent 记忆服务 TCP 连接(来自 .env
- MEMORY_TCP_HOST=${MEMORY_TCP_HOST:-agent-memory}
- MEMORY_TCP_PORT=${MEMORY_TCP_PORT:-4004}
# easyai-server 发布事件到 ws-gateway默认走容器内网服务名
- WS_GATEWAY_TCP_HOST=${WS_GATEWAY_TCP_HOST:-ws-gateway}
- WS_GATEWAY_TCP_PORT=${WS_GATEWAY_TCP_PORT:-4002}
# 日志大小设置,避免日志文件过大 # 日志大小设置,避免日志文件过大
env_file: env_file:
- .env - .env
@ -152,10 +125,10 @@ services:
labels: labels:
- "com.centurylinklabs.watchtower.enable=true" - "com.centurylinklabs.watchtower.enable=true"
ports: ports:
- "${SERVER_WS_PORT}:3002" #http端口 - "${CONFIG_WS_PORT:-3002}:3002" # ws-gateway WebSocket 对外端口映射
read_only: true read_only: true
networks: networks:
- comfyai - easyai
depends_on: depends_on:
- redis - redis
- rabbitmq - rabbitmq
@ -169,6 +142,7 @@ services:
- CONFIG_COMFYUI_QUENE_REDIS_PASSWORD= - CONFIG_COMFYUI_QUENE_REDIS_PASSWORD=
#日志与调试 #日志与调试
- LOG_LEVEL=${LOG_LEVEL} - LOG_LEVEL=${LOG_LEVEL}
- WS_GATEWAY_LOG_LEVEL=${WS_GATEWAY_LOG_LEVEL}
#MQ #MQ
- CONFIG_MQ_USER=${CONFIG_MQ_USER} - CONFIG_MQ_USER=${CONFIG_MQ_USER}
- CONFIG_MQ_PASSWORD=${CONFIG_MQ_PASSWORD} - CONFIG_MQ_PASSWORD=${CONFIG_MQ_PASSWORD}
@ -183,8 +157,8 @@ services:
max-size: "100m" max-size: "100m"
max-file: "10" max-file: "10"
mongo: mongo:
image: registry.cn-shanghai.aliyuncs.com/comfy-ai/mongo-aliyun:latest # 镜像见 .env 中 MONGO_IMAGE4.4 备选地址与用途见 .env.sample 注释
# image: registry.cn-shanghai.aliyuncs.com/comfy-ai/mongo-aliyun:4.4 image: ${MONGO_IMAGE:-registry.cn-shanghai.aliyuncs.com/comfy-ai/mongo-aliyun:latest}
container_name: mongo container_name: mongo
restart: unless-stopped restart: unless-stopped
privileged: true privileged: true
@ -192,7 +166,7 @@ services:
ports: ports:
- ${MONGO_PORT+${MONGO_PORT}:27017} - ${MONGO_PORT+${MONGO_PORT}:27017}
networks: networks:
comfyai: easyai:
ipv4_address: 172.21.0.3 ipv4_address: 172.21.0.3
environment: environment:
# 这里的配置只有首次运行生效。修改后,重启镜像是不会生效的。需要把持久化数据删除再重启,才有效果 # 这里的配置只有首次运行生效。修改后,重启镜像是不会生效的。需要把持久化数据删除再重启,才有效果
@ -214,7 +188,7 @@ services:
max-size: "100m" max-size: "100m"
max-file: "10" max-file: "10"
redis: redis:
image: registry.cn-shanghai.aliyuncs.com/comfy-ai/redis-aliyun:latest image: ${REDIS_IMAGE:-registry.cn-shanghai.aliyuncs.com/comfy-ai/redis-aliyun:latest}
container_name: redis container_name: redis
restart: always restart: always
volumes: volumes:
@ -222,9 +196,9 @@ services:
command: [ "redis-server", "/etc/redis/redis.conf" ] # 让 Redis 读取配置文件 command: [ "redis-server", "/etc/redis/redis.conf" ] # 让 Redis 读取配置文件
# ports: # ports:
# - ${REDIS_PORT+${REDIS_PORT}:6379} # - ${REDIS_PORT+${REDIS_PORT}:6379}
read_only: true # read_only: true
networks: networks:
comfyai: easyai:
ipv4_address: 172.21.0.4 ipv4_address: 172.21.0.4
# 日志大小设置,避免日志文件过大 # 日志大小设置,避免日志文件过大
logging: logging:
@ -233,8 +207,10 @@ services:
max-size: "100m" max-size: "100m"
max-file: "10" max-file: "10"
rabbitmq: rabbitmq:
image: registry.cn-shanghai.aliyuncs.com/easyaigc/mq:latest #阿里云镜像加速 # 镜像地址见 .env 中 RABBITMQ_IMAGE备选示例见 .env.sample
# image: rabbitmq:4-management #官方原版镜像 image: ${RABBITMQ_IMAGE:-registry.cn-shanghai.aliyuncs.com/easyaigc/mq:latest}
labels:
- "com.centurylinklabs.watchtower.enable=true"
container_name: rabbitmq container_name: rabbitmq
restart: unless-stopped restart: unless-stopped
environment: environment:
@ -246,7 +222,7 @@ services:
volumes: volumes:
- rabbitmq_data:/var/lib/rabbitmq # 持久化数据 - rabbitmq_data:/var/lib/rabbitmq # 持久化数据
networks: networks:
comfyai: easyai:
ipv4_address: 172.21.0.12 ipv4_address: 172.21.0.12
watchtower: watchtower:
image: registry.cn-shanghai.aliyuncs.com/comfy-ai/watchtower-aliyun:latest image: registry.cn-shanghai.aliyuncs.com/comfy-ai/watchtower-aliyun:latest
@ -262,7 +238,7 @@ services:
# - "${WATCHTOWER_PORT}:8080" # - "${WATCHTOWER_PORT}:8080"
read_only: true read_only: true
networks: networks:
comfyai: easyai:
ipv4_address: 172.21.0.9 ipv4_address: 172.21.0.9
# 日志大小设置,避免日志文件过大 # 日志大小设置,避免日志文件过大
logging: logging:
@ -273,25 +249,36 @@ services:
video-edit: video-edit:
image: registry.cn-shanghai.aliyuncs.com/easyaigc/videoedit:latest image: registry.cn-shanghai.aliyuncs.com/easyaigc/videoedit:latest
container_name: video-edit container_name: video-edit
platform: linux/amd64
labels: labels:
- "com.centurylinklabs.watchtower.enable=true" - 'com.centurylinklabs.watchtower.enable=true'
volumes: volumes:
- ./data/videoedit/temp:/app/temp - ./data/videoedit/temp:/app/temp
ports: ports:
- "${VIDEO_EDIT_PORT}:8000" - '${VIDEO_EDIT_PORT}:8000'
env_file:
- .env.tools
environment: environment:
- PYTHONUNBUFFERED=1 - PYTHONUNBUFFERED=1
- OMP_NUM_THREADS=4 - OMP_NUM_THREADS=4
- OPENBLAS_NUM_THREADS=4 - OPENBLAS_NUM_THREADS=4
env_file: ipc: host
- .env.tools shm_size: 3g
shm_size: 2g cap_add:
- SYS_ADMIN
init: true
restart: unless-stopped restart: unless-stopped
networks: networks:
comfyai: easyai:
ipv4_address: 172.21.0.10 ipv4_address: 172.21.0.10
healthcheck: healthcheck:
test: [ "CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/docs')" ] test:
[
'CMD',
'python',
'-c',
"import urllib.request; urllib.request.urlopen('http://localhost:8000/docs')",
]
interval: 30s interval: 30s
timeout: 10s timeout: 10s
retries: 3 retries: 3
@ -307,12 +294,18 @@ services:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
- ./data:/data - ./data:/data
ports: ports:
- 8080:8080 - "${DOZZLE_PORT:-8080}:8080"
restart: unless-stopped
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "3"
sandbox: sandbox:
image: registry.cn-shanghai.aliyuncs.com/easyaigc/sandbox:latest image: registry.cn-shanghai.aliyuncs.com/easyaigc/sandbox:latest
container_name: sandbox container_name: sandbox
networks: networks:
- comfyai - easyai
#沙箱环境默认不对外暴露 #沙箱环境默认不对外暴露
ports: ports:
# - "${SANDBOX_PORT}:8000" # - "${SANDBOX_PORT}:8000"
@ -359,18 +352,21 @@ services:
timeout: 10s timeout: 10s
retries: 3 retries: 3
start_period: 10s start_period: 10s
easyai-asg-pg: easyai-pgvector:
image: registry.cn-shanghai.aliyuncs.com/easyaigc/postgres:18-alpine # 使用带 pgvector 的镜像,供 ASG 与 Agent 记忆服务共用
container_name: easyai-asg-pg image: registry.cn-shanghai.aliyuncs.com/easyaigc/pgvector:0.8.2-pg18-trixie
container_name: easyai-pgvector
restart: unless-stopped restart: unless-stopped
environment: environment:
POSTGRES_USER: ${ASG_POSTGRES_USER:-easyai} POSTGRES_USER: ${ASG_POSTGRES_USER:-easyai}
POSTGRES_PASSWORD: ${ASG_POSTGRES_PASSWORD:-easyai2025} POSTGRES_PASSWORD: ${ASG_POSTGRES_PASSWORD:-easyai2025}
POSTGRES_DB: ${ASG_POSTGRES_DB:-agent_governance} POSTGRES_DB: ${ASG_POSTGRES_DB:-agent_governance}
volumes: volumes:
- asg_postgres_data:/var/lib/postgresql/data - asg_postgres_data:/var/lib/postgresql
# 首次启动时执行,创建 pgvector 扩展供记忆服务使用
- ./docker/postgres/init-pgvector.sql:/docker-entrypoint-initdb.d/02-init-pgvector.sql
networks: networks:
comfyai: easyai:
ipv4_address: 172.21.0.13 ipv4_address: 172.21.0.13
healthcheck: healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${ASG_POSTGRES_USER:-easyai} -d ${ASG_POSTGRES_DB:-agent_governance}"] test: ["CMD-SHELL", "pg_isready -U ${ASG_POSTGRES_USER:-easyai} -d ${ASG_POSTGRES_DB:-agent_governance}"]
@ -391,10 +387,10 @@ services:
ports: ports:
- "${ASG_PORT:-3003}:3003" - "${ASG_PORT:-3003}:3003"
networks: networks:
comfyai: easyai:
ipv4_address: 172.21.0.14 ipv4_address: 172.21.0.14
depends_on: depends_on:
easyai-asg-pg: easyai-pgvector:
condition: service_healthy condition: service_healthy
redis: redis:
condition: service_started condition: service_started
@ -414,6 +410,38 @@ services:
memory: 512MB memory: 512MB
reservations: reservations:
memory: 128MB memory: 128MB
agent-memory:
container_name: agent-memory
image: registry.cn-shanghai.aliyuncs.com/easyaigc/agent-memory:${AMS_VERSION:-latest}
labels:
- "com.centurylinklabs.watchtower.enable=true"
ports:
- "${AMS_PORT:-3004}:3004"
environment:
- MEMORY_DATABASE_URL=${MEMORY_DATABASE_URL:-postgresql://easyai:easyai2025@easyai-pgvector:5432/easyai_memory}
networks:
easyai:
ipv4_address: 172.21.0.16
depends_on:
easyai-pgvector:
condition: service_healthy
easyai-server:
condition: service_started
restart: unless-stopped
env_file:
- .env.AMS
- .env.ASG
logging:
driver: "json-file"
options:
max-size: "100m"
max-file: "10"
deploy:
resources:
limits:
memory: 512MB
reservations:
memory: 128MB
# portainer: # portainer:
# image: registry.cn-shanghai.aliyuncs.com/comfy-ai/portainer-ce:2.21.5 # image: registry.cn-shanghai.aliyuncs.com/comfy-ai/portainer-ce:2.21.5
# container_name: portainer # container_name: portainer
@ -459,7 +487,7 @@ volumes:
rabbitmq_data: rabbitmq_data:
asg_postgres_data: asg_postgres_data:
networks: networks:
comfyai: easyai:
driver: bridge driver: bridge
ipam: ipam:
config: config:

View File

@ -0,0 +1,14 @@
-- 首次启动时执行,与 ASG 共用同一 PostgreSQL 实例
-- 1. 为 agent_governance 启用 pgvector兼容共库场景
\c agent_governance
CREATE EXTENSION IF NOT EXISTS vector;
CREATE EXTENSION IF NOT EXISTS pgcrypto;
-- 2. 创建记忆服务独立数据库 easyai_memory
CREATE DATABASE easyai_memory;
GRANT ALL PRIVILEGES ON DATABASE easyai_memory TO easyai;
-- 3. 为 easyai_memory 启用 pgvector
\c easyai_memory
CREATE EXTENSION IF NOT EXISTS vector;
CREATE EXTENSION IF NOT EXISTS pgcrypto;

33
docker/verify/Dockerfile Normal file
View File

@ -0,0 +1,33 @@
# EasyAI 部署脚本验证环境
# 在 Docker 容器内运行 start.sh通过挂载 Docker Socket 使用宿主机 Docker 启动服务
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
gnupg \
lsb-release \
git \
sudo \
&& rm -rf /var/lib/apt/lists/*
# 安装 Docker CLI使用宿主机 Docker 守护进程)
RUN install -m 0755 -d /etc/apt/keyrings \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
&& chmod a+r /etc/apt/keyrings/docker.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends docker-ce-cli docker-compose-plugin \
&& rm -rf /var/lib/apt/lists/*
# 创建工作目录
WORKDIR /workspace/easyai
# 复制项目文件(运行时通过 volume 挂载覆盖)
COPY . /workspace/easyai/
# 允许以 root 运行(容器内通常为 root
ENV DEPLOY_ACCESS=ip
ENV DEPLOY_IP=127.0.0.1

View File

@ -0,0 +1,24 @@
#!/bin/bash
# 快速验证:仅测试配置生成,不拉取镜像、不启动服务
# 适合 CI 或快速检查脚本逻辑
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
cd "$PROJECT_ROOT"
echo "================================"
echo " EasyAI 部署脚本快速验证"
echo " (仅配置,不启动 Docker)"
echo "================================"
# 使用管道模拟用户输入1=IP模式, 127.0.0.1=IP地址
printf '1\n127.0.0.1\n' | DEPLOY_DRY_RUN=1 DEPLOY_FORCE_RECONFIG=1 ./start.sh
echo ""
echo "✅ 配置验证通过,检查生成的文件:"
ls -la .env .env.tools .env.ASG .env.AMS 2>/dev/null || true
echo ""
grep -E "NUXT_PUBLIC_(BASE_APIURL|BASE_SOCKETURL|SG_APIURL)" .env 2>/dev/null | head -3

46
docker/verify/run-verify.sh Executable file
View File

@ -0,0 +1,46 @@
#!/bin/bash
# 在 Docker 容器中验证 EasyAI 部署脚本
# 用法: 在 easyai 项目根目录执行 ./docker/verify/run-verify.sh
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
cd "$PROJECT_ROOT"
echo "================================"
echo " EasyAI 部署脚本 Docker 验证"
echo "================================"
echo "项目目录: $PROJECT_ROOT"
echo ""
# 构建验证镜像
echo "📦 构建验证镜像..."
docker build -f docker/verify/Dockerfile -t easyai-deploy-verify:latest .
echo ""
echo "🚀 运行部署脚本(非交互模式,挂载 Docker Socket..."
echo " 使用 DEPLOY_ACCESS=ip DEPLOY_IP=127.0.0.1"
echo ""
# 挂载 Docker Socket使容器内 docker 命令使用宿主机 Docker
# 挂载项目目录,使用本地文件(避免容器内复制过时)
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$PROJECT_ROOT:/workspace/easyai" \
-w /workspace/easyai \
-e DEPLOY_ACCESS=ip \
-e DEPLOY_IP=127.0.0.1 \
-e DEPLOY_FORCE_RECONFIG=1 \
easyai-deploy-verify:latest \
bash -c './start.sh'
EXIT_CODE=$?
echo ""
if [ $EXIT_CODE -eq 0 ]; then
echo "✅ 部署脚本验证通过"
else
echo "❌ 部署脚本验证失败 (exit code: $EXIT_CODE)"
fi
exit $EXIT_CODE

View File

@ -0,0 +1,199 @@
# EasyAI Windows 一键部署方案
## 1. 背景与目标
`start.sh` 是 Linux 下的一键部署脚本,本方案为 Windows 平台提供等效的 `start.ps1` PowerShell 脚本。针对 Windows 典型场景做如下**精简**
- **仅 IP 访问**:不含域名模式与 HTTPS
- **本地访问无需放行端口**:选择本地 (127.0.0.1) 时,不涉及防火墙配置
- **Docker 未安装时**:用户可选择手动或自动安装 **Docker Desktop for Windows**winget/Chocolatey
## 2. Linux start.sh 流程梳理
### 2.1 整体流程
| 步骤 | 功能 | 说明 |
|------|------|------|
| 1 | 项目初始化 | 校验当前目录下存在 `docker-compose.yml` |
| 2 | 部署配置问答 | IP 或域名二选一,并采集对应参数 |
| 3 | 配置文件生成 | 生成/更新 `.env`、`.env.tools`、`.env.ASG` |
| 4 | Docker 安装与检查 | 检测并安装 DockerUbuntu/CentOS |
| 5 | 启动服务 | `docker compose pull && docker compose up -d` |
| 6 | HTTPS 配置(可选) | 域名模式下执行 `https.sh` |
### 2.2 配置问答逻辑
- **IP 模式**:输入服务器 IP 地址,需要放行 3001、3002、3003 端口
- **域名模式**:输入域名,可选是否启用 HTTPS需放行 80、443 端口
### 2.3 环境变量写入 .env
- `NUXT_PUBLIC_BASE_APIURL`API 地址
- `NUXT_PUBLIC_BASE_SOCKETURL`WebSocket 地址
- `NUXT_PUBLIC_SG_APIURL`Agent 服务治理 API 地址
**IP 模式**
```
NUXT_PUBLIC_BASE_APIURL=http://<IP>:3001
NUXT_PUBLIC_BASE_SOCKETURL=ws://<IP>:3002
NUXT_PUBLIC_SG_APIURL=http://<IP>:3003
```
**域名模式**
```
NUXT_PUBLIC_BASE_APIURL=/api
NUXT_PUBLIC_BASE_SOCKETURL=wss://<domain>/socket.io
NUXT_PUBLIC_SG_APIURL=/asg-api
```
---
## 3. Windows 与 Linux 差异
| 项目 | Linux | Windows |
|------|-------|---------|
| 脚本语言 | Bash | PowerShell |
| 文本替换 | sed | `(Get-Content) -replace``Set-Content` |
| 用户输入 | `read -p` | `Read-Host` |
| 访问方式 | IP + 域名 + HTTPS | **仅 IP**(本地 / 局域网) |
| 端口放行 | 本地无特殊说明 | **本地访问无需放行**,局域网需放行 3001/3002/3003 |
| Docker | apt/yum 安装 Linux Docker | **Docker Desktop for Windows**,未安装时可选择手动或自动安装 |
---
## 4. Windows IP 访问方式设计(核心差异)
Windows 版**仅支持 IP 访问**,不包含域名模式与 HTTPS 配置。用户访问方式分为两类:
| 选项 | 访问方式 | IP 值 | 端口说明 |
|------|----------|-------|----------|
| 1 | 本地访问 | `127.0.0.1` | 本机访问,**无需放行端口** |
| 2 | 局域网访问 | 用户输入本机局域网 IP | 同网段设备访问,需放行 3001、3002、3003 |
**交互流程:**
1. `[1] 本地访问` → 自动使用 `127.0.0.1`,无需配置防火墙
2. `[2] 局域网访问` → 提示用户输入局域网 IP可提示 `ipconfig` 查看),并提醒放行上述端口
---
## 5. 实现方案
### 5.1 脚本文件
- 文件路径:`easyai/start.ps1`
- 一行命令示例:
```powershell
git clone https://git.51easyai.com/wangbo/easyai; cd easyai; .\start.ps1
```
### 5.2 模块划分
| 模块 | 函数/区块 | 功能 |
|------|-----------|------|
| 项目初始化 | `Init-ProjectDir` | 检查 `docker-compose.yml`,切换到项目根目录 |
| 配置问答 | `Run-DeployQuestions` | 本地访问 / 局域网访问选择(含 IP 输入) |
| 环境变量 | `PromptOrEnv` | 支持环境变量覆盖,用于 CI/自动化 |
| 配置文件 | `Setup-EnvFiles` | 复制 sample 并修改 `.env`、`.env.tools`、`.env.ASG` |
| Docker 检查 | `Test-Docker` | 检测 `docker`,未安装则让用户选择**手动安装**或**自动安装** |
| 启动服务 | `Start-Services` | `docker compose pull``docker compose up -d` |
| 主流程 | `Main` | 串联上述步骤 |
### 5.3 环境变量支持(非交互模式)
| 变量 | 说明 |
|------|------|
| `DEPLOY_IP` | 访问 IP本地填 `127.0.0.1`,局域网填实际 IP |
| `DEPLOY_DRY_RUN` | 1 时只生成配置,不安装/启动 Docker |
| `DEPLOY_FORCE_RECONFIG` | 非空时强制重新配置 |
### 5.4 配置文件修改实现(仅 IP 模式)
使用 PowerShell 替换 `.env` 中相关行:
```powershell
$content = Get-Content .env -Raw -Encoding UTF8
$content = $content -replace 'NUXT_PUBLIC_BASE_APIURL=.*', "NUXT_PUBLIC_BASE_APIURL=http://${DEPLOY_IP}:3001"
$content = $content -replace 'NUXT_PUBLIC_BASE_SOCKETURL=.*', "NUXT_PUBLIC_BASE_SOCKETURL=ws://${DEPLOY_IP}:3002"
$content = $content -replace 'NUXT_PUBLIC_SG_APIURL=.*', "NUXT_PUBLIC_SG_APIURL=http://${DEPLOY_IP}:3003"
Set-Content .env -Value $content -Encoding UTF8 -NoNewline
```
### 5.5 Docker 处理策略
- **目标**:检测并安装 **Docker Desktop for Windows**Windows 版 Docker
- **检测**:执行 `docker --version``docker compose version`
- **未安装时** prompt 让用户选择
- `[1] 手动安装`:输出安装说明及 Docker Desktop for Windows 下载链接,退出脚本
- `[2] 自动安装`:通过 winget 或 Chocolatey 安装 Docker Desktop for Windows安装后需用户重启终端/机器再继续
### 5.6 执行策略
PowerShell 默认可能禁止执行脚本,建议在文档中说明:
```powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
```
或在脚本开头提示用户使用:
```powershell
powershell -ExecutionPolicy Bypass -File .\start.ps1
```
---
## 6. 部署完成输出
成功部署后输出访问地址,例如:
- 本地访问:`http://127.0.0.1:3010`
- 局域网访问:`http://<LAN_IP>:3010`
---
## 7. 实现清单
- [ ] 创建 `start.ps1` 主脚本
- [ ] 实现 `Init-ProjectDir`:项目目录校验
- [ ] 实现 `Run-DeployQuestions`:本地 / 局域网 IP 选择(无域名/HTTPS
- [ ] 实现 `Setup-EnvFiles`:配置文件生成与替换
- [ ] 实现 `Test-Docker`Docker 检测,未安装时 prompt「手动安装」或「自动安装」
- [ ] 实现 `Install-Docker`:自动安装 **Docker Desktop for Windows**winget / Chocolatey
- [ ] 实现 `Start-Services``docker compose` 启动
- [ ] 实现 `Main`:主流程串联
- [ ] 支持 `DEPLOY_DRY_RUN`、`DEPLOY_IP` 环境变量非交互模式
- [x] 在 README 或文档中补充 Windows 部署说明与执行策略
- [x] 创建 `scripts/test-start-ps1-env.py` 验证 .env 替换逻辑
---
## 8. Windows 测试说明
### 本地测试(需 Windows 或 WSL + PowerShell
```powershell
# 非交互 + 仅生成配置(不启动 Docker
$env:DEPLOY_DRY_RUN = "1"
$env:DEPLOY_IP = "127.0.0.1"
.\start.ps1
# 检查 .env 是否已正确写入
Select-String -Path .env -Pattern "NUXT_PUBLIC_BASE"
```
### 完整部署测试(需 Windows + Docker Desktop
```powershell
.\start.ps1
# 按提示选择 [1] 本地访问 或 [2] 局域网访问
# 若未安装 Docker选择 [1] 手动 或 [2] 自动安装
```
### 执行策略(若提示无法运行脚本)
```powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# 或
powershell -ExecutionPolicy Bypass -File .\start.ps1
```

View File

@ -91,6 +91,19 @@ server {
proxy_set_header Host $host; proxy_set_header Host $host;
} }
# Agent 记忆服务 API可选用于健康检查或外部调用
location /ams-api/ {
proxy_pass http://127.0.0.1:3004/;
proxy_read_timeout 300s;
client_max_body_size 20M;
proxy_redirect off;
proxy_set_header X-Original-Prefix '/ams-api';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
}
location /plugins/ { location /plugins/ {
proxy_pass http://127.0.0.1:3020/plugins/; proxy_pass http://127.0.0.1:3020/plugins/;
proxy_redirect off; proxy_redirect off;
@ -144,4 +157,17 @@ server {
proxy_buffering off; # 对于 WebSocket 连接禁用缓冲 proxy_buffering off; # 对于 WebSocket 连接禁用缓冲
} }
# 沙箱环境 API脚本执行、下载、安装依赖等需在 docker-compose 中取消 SANDBOX_PORT 映射
location /sandbox/ {
proxy_pass http://127.0.0.1:8081/;
proxy_read_timeout 300s;
client_max_body_size 50M;
proxy_redirect off;
proxy_set_header X-Original-Prefix '/sandbox';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
}
} }

223
https.sh
View File

@ -103,8 +103,210 @@ else
exit 1 exit 1
fi fi
# ===== 域名配置交互与文件生成 =====
prompt_domain() {
local domain
while true; do
read -r -p "🌐 请输入域名(例如 demo.example.com: " domain
domain=$(echo "$domain" | xargs)
if [ -n "$domain" ] && [[ "$domain" =~ ^[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$ ]]; then
echo "$domain"
return 0
fi
echo "❌ 域名格式不正确,请重新输入。"
done
}
escape_sed() {
echo "$1" | sed 's/[.[\*^$()+?{}|/]/\\&/g'
}
get_primary_domain_from_conf() {
local conf_file=$1
awk '
/server_name/ {
for (i = 2; i <= NF; i++) {
gsub(";", "", $i)
if ($i !~ /^www\./ && $i !~ /^\*/ && $i != "localhost") {
print $i
exit
}
}
}
' "$conf_file"
}
create_conf_by_template() {
local domain=$1
local target_file=$2
if [ -f "./demo.51easyai.com.conf" ]; then
cp "./demo.51easyai.com.conf" "./$target_file"
sed -i.bak "s/www\.demo\.51easyai\.com/www.$domain/g; s/demo\.51easyai\.com/$domain/g" "./$target_file"
rm -f "./$target_file.bak"
return 0
fi
if [ -f "./2.conf" ]; then
cp "./2.conf" "./$target_file"
sed -i.bak "s/www\.2/www.$domain/g; s/\b2\b/$domain/g" "./$target_file"
rm -f "./$target_file.bak"
return 0
fi
cat > "./$target_file" <<EOF
map \$http_upgrade \$connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
listen [::]:80;
server_name www.$domain;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
try_files \$uri =404;
}
location / {
return 301 https://$domain\$request_uri;
}
}
server {
listen 80;
listen [::]:80;
server_name $domain;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
try_files \$uri =404;
}
location / {
proxy_pass http://127.0.0.1:3010/;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header Host \$host;
}
}
EOF
}
upsert_domain_for_conf() {
local conf_file=$1
local mode
local new_domain
echo " 检测到当前目录已有配置文件: $conf_file"
while true; do
echo "请选择域名处理方式:"
echo " 1) 替换当前域名"
echo " 2) 新增一个域名"
read -r -p "请输入选项 (1/2): " mode
case "$mode" in
1|2) break ;;
*) echo "❌ 无效选项,请输入 1 或 2" ;;
esac
done
new_domain=$(prompt_domain)
if [ "$mode" = "1" ]; then
local old_domain
old_domain=$(get_primary_domain_from_conf "./$conf_file")
if [ -z "$old_domain" ]; then
echo "⚠️ 未能自动识别旧域名,将直接尝试新增域名。"
mode="2"
else
local old_domain_escaped
local new_domain_escaped
old_domain_escaped=$(escape_sed "$old_domain")
new_domain_escaped=$(escape_sed "$new_domain")
sed -i.bak "s/www\\.$old_domain_escaped/www.$new_domain_escaped/g; s/$old_domain_escaped/$new_domain_escaped/g" "./$conf_file"
rm -f "./$conf_file.bak"
echo "✅ 已将域名从 $old_domain 替换为 $new_domain"
fi
fi
if [ "$mode" = "2" ]; then
local changed=0
if ! grep -Eq "server_name[^;]*[[:space:]]$new_domain([[:space:];]|$)" "./$conf_file"; then
sed -i.bak "/server_name/s/;/ $new_domain;/g" "./$conf_file"
changed=1
fi
if ! grep -Eq "server_name[^;]*[[:space:]]www\\.$new_domain([[:space:];]|$)" "./$conf_file"; then
sed -i.bak "/server_name/s/;/ www.$new_domain;/g" "./$conf_file"
changed=1
fi
rm -f "./$conf_file.bak"
if [ "$changed" -eq 1 ]; then
echo "✅ 已新增域名:$new_domain(含 www.$new_domain"
else
echo " 配置文件已包含该域名,无需新增。"
fi
fi
}
detect_existing_proxy_conf() {
local preferred_file=$1
local -a candidates=()
local conf
if [ -n "$preferred_file" ] && [ -f "./$preferred_file" ]; then
echo "$preferred_file"
return 0
fi
while IFS= read -r conf; do
if grep -Eq "^[[:space:]]*server_name[[:space:]]+" "./$conf"; then
candidates+=("$conf")
fi
done < <(ls -1 *.conf 2>/dev/null || true)
if [ "${#candidates[@]}" -eq 0 ]; then
return 1
fi
if [ "${#candidates[@]}" -eq 1 ]; then
echo "${candidates[0]}"
return 0
fi
echo "⚠️ 检测到多个可用配置文件,请选择一个:"
local i
for i in "${!candidates[@]}"; do
printf " %s) %s\n" "$((i + 1))" "${candidates[$i]}"
done
while true; do
read -r -p "请输入序号: " i
if [[ "$i" =~ ^[0-9]+$ ]] && [ "$i" -ge 1 ] && [ "$i" -le "${#candidates[@]}" ]; then
echo "${candidates[$((i - 1))]}"
return 0
fi
echo "❌ 无效序号,请重新输入。"
done
}
echo "🚀 复制当前目录的配置文件到nginx配置文件目录" echo "🚀 复制当前目录的配置文件到nginx配置文件目录"
cp -r ./easyai-proxy.conf /etc/nginx/conf.d/ # 支持 EASYAI_PROXY_CONF 指定配置文件(如 51easyai.com.conf
PREFERRED_CONF_FILE="${EASYAI_PROXY_CONF:-}"
DEFAULT_NEW_CONF_FILE="${EASYAI_PROXY_CONF:-easyai-proxy.conf}"
CONF_FILE=$(detect_existing_proxy_conf "$PREFERRED_CONF_FILE")
if [ -n "$CONF_FILE" ]; then
upsert_domain_for_conf "$CONF_FILE"
else
CONF_FILE="$DEFAULT_NEW_CONF_FILE"
echo " 当前目录未找到可用 nginx 配置文件(*.conf 且包含 server_name"
input_domain=$(prompt_domain)
create_conf_by_template "$input_domain" "$CONF_FILE"
echo "✅ 已根据域名 $input_domain 创建配置文件: ./$CONF_FILE"
fi
cp "./$CONF_FILE" "/etc/nginx/conf.d/$CONF_FILE"
echo "🚀 重载nginx" echo "🚀 重载nginx"
sudo nginx -s reload sudo nginx -s reload
@ -113,10 +315,21 @@ sudo nginx -s stop
echo "🚀 使用certbot 自动配置证书" echo "🚀 使用certbot 自动配置证书"
# 从 Nginx 配置文件中提取所有域名 # 从 Nginx 配置文件中提取所有域名
DOMAINS=$(find /etc/nginx/conf.d/ -name "easyai-proxy.conf" -type f -exec grep "server_name" {} \; | \ SERVER_NAME_LINES=$(
if [ -f "/etc/nginx/conf.d/$CONF_FILE" ]; then
grep "server_name" "/etc/nginx/conf.d/$CONF_FILE" 2>/dev/null || true
else
find /etc/nginx/conf.d/ -name "*.conf" -exec grep "server_name" {} \; 2>/dev/null || true
fi
)
DOMAINS=$(echo "$SERVER_NAME_LINES" | \
grep -v "#" | \ grep -v "#" | \
awk '{for(i=2;i<=NF;i++) if($i!=";") print $i}' | \ awk '{for(i=2;i<=NF;i++) if($i!=";") print $i}' | \
sed 's/;//g' | \ sed 's/;//g' | \
sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | \
grep -E '^[A-Za-z0-9.-]+$' | \
grep -vE '^(\*|localhost)$' | \
sort -u | \ sort -u | \
tr '\n' ' ') tr '\n' ' ')
@ -126,9 +339,9 @@ if [ -n "$DOMAINS" ]; then
sudo nginx -s stop sudo nginx -s stop
# 构建域名参数字符串 # 构建域名参数字符串
DOMAIN_ARGS="" DOMAIN_ARGS=()
for domain in $DOMAINS; do for domain in $DOMAINS; do
DOMAIN_ARGS="$DOMAIN_ARGS -d $domain" DOMAIN_ARGS+=("-d" "$domain")
done done
# 使用 certbot --nginx 插件安装证书 # 使用 certbot --nginx 插件安装证书
@ -139,7 +352,7 @@ if [ -n "$DOMAINS" ]; then
--rsa-key-size 2048 \ --rsa-key-size 2048 \
--preferred-challenges http \ --preferred-challenges http \
--force-renewal \ --force-renewal \
$DOMAIN_ARGS "${DOMAIN_ARGS[@]}"
# 启动 Nginx 服务 # 启动 Nginx 服务
echo "启动 Nginx 服务..." echo "启动 Nginx 服务..."

BIN
img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

View File

@ -0,0 +1,480 @@
#Requires -Version 5.1
<#
.SYNOPSIS
Mirror a public image (default: Docker Hub via optional China mirror) to your registry,
keeping only selected platforms (default linux/amd64 + linux/arm64), then push one multi-arch tag.
.DESCRIPTION
Uses skopeo copy per digest + docker buildx imagetools create.
Docker Desktop users: credentials are resolved from credential helper into a UTF-8 no-BOM auth file.
.PARAMETER Source
Docker Hub style: redis:latest, nginx:alpine, bitnami/redis:7, library/redis:7, docker.io/prom/prometheus:latest
Or any registry: ghcr.io/org/image:tag (no Docker-Hub mirror rewrite)
.PARAMETER DestRepo
Target repository without tag, e.g. registry.cn-shanghai.aliyuncs.com/myns/redis
.PARAMETER DestTag
Tag on destination (default: tag parsed from -Source)
.PARAMETER MirrorRegistry
Pull-through mirror host for Docker Hub only, e.g. docker.m.daocloud.io. Empty = use docker.io directly.
.PARAMETER Platforms
OS/arch list to keep, default linux/amd64 and linux/arm64.
.PARAMETER SkopeoParallelCopies
skopeo --image-parallel-copies (layers in flight). 0 = auto (higher default for better upload utilization).
If upload still looks underused, try 32 or 40; if CPU/memory spikes, lower to 12.
Other tuning (outside this script): use ACR region closest to you; Docker Desktop -> Resources give more CPUs/RAM;
avoid VPN throttling; wired Ethernet; temporarily pause heavy uploads on same link.
.EXAMPLE
.\mirror-image-to-registry.ps1 -Source nginx:alpine -DestRepo registry.cn-shanghai.aliyuncs.com/myns/nginx -DestTag alpine
.EXAMPLE
.\mirror-image-to-registry.ps1 -Source docker.io/library/redis:latest -DestRepo registry.example.com/prod/redis -MirrorRegistry ""
#>
param(
[Parameter(Mandatory = $true)][string] $Source,
[Parameter(Mandatory = $true)][string] $DestRepo,
[string] $DestTag = "",
[string] $MirrorRegistry = "docker.m.daocloud.io",
[string[]] $Platforms = @("linux/amd64", "linux/arm64"),
[string] $SkopeoImage = "quay.io/skopeo/stable:latest",
[string] $DestUsername = "",
[string] $DestPassword = "",
[int] $SkopeoParallelCopies = 0
)
$ErrorActionPreference = "Stop"
# Parallel layer copies: 0 = auto (scale with CPU cores, capped)
$nCpu = [Environment]::ProcessorCount
if ($SkopeoParallelCopies -le 0) {
$script:EffectiveParallelCopies = [Math]::Min(40, [Math]::Max(16, $nCpu * 4))
Write-Host "SkopeoParallelCopies=auto -> $script:EffectiveParallelCopies (logical CPUs: $nCpu)"
} else {
$script:EffectiveParallelCopies = $SkopeoParallelCopies
Write-Host "SkopeoParallelCopies=$script:EffectiveParallelCopies"
}
function Test-CmdInPath {
param([string]$Name)
return [bool](Get-Command $Name -ErrorAction SilentlyContinue)
}
function Get-RegistryHostFromRepo {
param([string]$Repo)
return ($Repo -split '/')[0]
}
function Get-DockerConfigPath {
return (Join-Path $env:USERPROFILE ".docker\config.json")
}
function Write-JsonFileUtf8NoBom {
param([string]$Path, [string]$JsonText)
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
[System.IO.File]::WriteAllText($Path, $JsonText, $utf8NoBom)
}
function New-SkopeoAuthJsonFile {
param(
[Parameter(Mandatory = $true)][string]$RegistryHost,
[Parameter(Mandatory = $true)][string]$Username,
[Parameter(Mandatory = $true)][string]$Password
)
$pair = "${Username}:${Password}"
$authB64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($pair))
$payload = @{
auths = @{
$RegistryHost = @{
auth = $authB64
}
}
}
$path = [System.IO.Path]::GetTempFileName() + ".json"
$jsonText = $payload | ConvertTo-Json -Compress -Depth 6
Write-JsonFileUtf8NoBom -Path $path -JsonText $jsonText
return $path
}
function Get-InlineAuthFromDockerConfig {
param([string]$DockerConfigPath, [string]$RegistryHost)
if (-not (Test-Path -LiteralPath $DockerConfigPath)) { return $null }
$txt = Get-Content -LiteralPath $DockerConfigPath -Raw -ErrorAction Stop
$cfg = $txt | ConvertFrom-Json
if (-not $cfg.auths) { return $null }
foreach ($p in $cfg.auths.PSObject.Properties) {
if ($p.Name -eq $RegistryHost -and $p.Value.auth) {
return [string]$p.Value.auth
}
}
return $null
}
function Get-CredentialFromDockerHelper {
param([string]$RegistryHost, [string]$HelperName)
if (-not $HelperName) { return $null }
$exeName = "docker-credential-$HelperName"
$exe = Get-Command $exeName -ErrorAction SilentlyContinue
if (-not $exe) {
$candidates = @(
(Join-Path ${env:ProgramFiles} "Docker\Docker\resources\bin\$exeName.exe"),
(Join-Path ${env:ProgramFiles} "Docker\Docker\resources\bin\$HelperName.exe")
)
foreach ($c in $candidates) {
if (Test-Path -LiteralPath $c) { $exe = Get-Command $c -ErrorAction SilentlyContinue; break }
}
}
if (-not $exe) {
Write-Warning "Credential helper '$exeName' not found on PATH or Docker resources."
return $null
}
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = $exe.Source
$psi.Arguments = "get"
$psi.RedirectStandardInput = $true
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.UseShellExecute = $false
$psi.CreateNoWindow = $true
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $psi
[void]$p.Start()
$p.StandardInput.WriteLine($RegistryHost)
$p.StandardInput.Close()
$out = $p.StandardOutput.ReadToEnd()
$err = $p.StandardError.ReadToEnd()
$p.WaitForExit()
if ($p.ExitCode -ne 0) {
Write-Warning "docker-credential-$HelperName get failed (exit $($p.ExitCode)): $err"
return $null
}
try {
$j = $out | ConvertFrom-Json
return @{ Username = $j.Username; Secret = $j.Secret }
} catch {
return $null
}
}
function Resolve-DestinationAuthFile {
param([string]$RegistryHost)
if ($DestUsername -and $DestPassword) {
Write-Host "Using -DestUsername / -DestPassword for registry push auth."
return (New-SkopeoAuthJsonFile -RegistryHost $RegistryHost -Username $DestUsername -Password $DestPassword)
}
if ($env:ALIYUN_CR_USER -and $env:ALIYUN_CR_PASS) {
Write-Host "Using ALIYUN_CR_USER / ALIYUN_CR_PASS for registry push auth."
return (New-SkopeoAuthJsonFile -RegistryHost $RegistryHost -Username $env:ALIYUN_CR_USER -Password $env:ALIYUN_CR_PASS)
}
if ($env:DEST_REGISTRY_USER -and $env:DEST_REGISTRY_PASS) {
Write-Host "Using DEST_REGISTRY_USER / DEST_REGISTRY_PASS for registry push auth."
return (New-SkopeoAuthJsonFile -RegistryHost $RegistryHost -Username $env:DEST_REGISTRY_USER -Password $env:DEST_REGISTRY_PASS)
}
$dockerCfg = Get-DockerConfigPath
$inline = Get-InlineAuthFromDockerConfig -DockerConfigPath $dockerCfg -RegistryHost $RegistryHost
if ($inline) {
Write-Host "Using inline auth from Docker config.json for $RegistryHost"
$path = [System.IO.Path]::GetTempFileName() + ".json"
$payload = @{ auths = @{ $RegistryHost = @{ auth = $inline } } }
$jsonText = $payload | ConvertTo-Json -Compress -Depth 6
Write-JsonFileUtf8NoBom -Path $path -JsonText $jsonText
return $path
}
if (Test-Path -LiteralPath $dockerCfg) {
$cfg = (Get-Content -LiteralPath $dockerCfg -Raw) | ConvertFrom-Json
$helperName = $null
if ($cfg.credHelpers) {
foreach ($hp in $cfg.credHelpers.PSObject.Properties) {
if ($hp.Name -eq $RegistryHost) {
$helperName = [string]$hp.Value
break
}
}
}
if (-not $helperName -and $cfg.credsStore) {
$helperName = $cfg.credsStore
}
if ($helperName) {
Write-Host "Resolving credentials via docker-credential-$helperName (Docker Desktop)..."
$c = Get-CredentialFromDockerHelper -RegistryHost $RegistryHost -HelperName $helperName
if ($c -and $c.Username -and $c.Secret) {
return (New-SkopeoAuthJsonFile -RegistryHost $RegistryHost -Username $c.Username -Password $c.Secret)
}
}
}
return $null
}
function Split-ImageRefPathAndTag {
param([string]$Ref)
if ($Ref -match '@sha256:') {
throw "Digest-pinned sources (@sha256:...) are not supported. Use a tag."
}
$tag = "latest"
$path = $Ref
if ($Ref -match '^(.+):([^:/]+)$') {
$path = $matches[1]
$tag = $matches[2]
}
return @{ Path = $path; Tag = $tag }
}
function Test-IsDockerHubOnlyPath {
param([string]$PathPart)
if ($PathPart -match '^[a-zA-Z0-9][a-zA-Z0-9.-]*\.[a-zA-Z]+/') { return $false }
return $true
}
function Resolve-DockerHubRepoPath {
param([string]$PathPart)
if ($PathPart -notmatch '/') {
return "library/$PathPart"
}
return $PathPart
}
# Returns: IsDockerHub, InspectRef (docker://...), SourceRepoPath for copy by digest (host/repo without tag), Tag
function Resolve-SourceInspectReference {
param(
[string]$Source,
[string]$MirrorRegistry
)
$s = $Source.Trim()
if ($s.StartsWith("docker://")) {
$s = $s.Substring(9)
}
$st = Split-ImageRefPathAndTag $s
$path = $st.Path
$tag = $st.Tag
if (Test-IsDockerHubOnlyPath $path) {
$repo = Resolve-DockerHubRepoPath $path
$hubRef = "docker.io/${repo}:${tag}"
if ($MirrorRegistry) {
$inspect = "docker://${MirrorRegistry}/${repo}:${tag}"
} else {
$inspect = "docker://${hubRef}"
}
return @{
IsDockerHub = $true
InspectRef = $inspect
SourceRepoPath = if ($MirrorRegistry) { "${MirrorRegistry}/${repo}" } else { "docker.io/${repo}" }
Tag = $tag
}
}
# Full registry reference e.g. ghcr.io/org/img:tag
$firstSlash = $path.IndexOf('/')
if ($firstSlash -lt 1) { throw "Invalid source: $Source" }
$hostPart = $path.Substring(0, $firstSlash)
$repoPath = $path.Substring($firstSlash + 1)
if (-not $repoPath) { throw "Invalid source: $Source" }
$inspect = "docker://${hostPart}/${repoPath}:${tag}"
return @{
IsDockerHub = $false
InspectRef = $inspect
SourceRepoPath = "${hostPart}/${repoPath}"
Tag = $tag
}
}
function Get-DockerAuthVolumeArgs {
param([string]$AuthFilePath)
if ($AuthFilePath -and (Test-Path -LiteralPath $AuthFilePath)) {
return @("-v", "${AuthFilePath}:/auth.json:ro")
}
return @()
}
function Invoke-SkopeoCopyWithAuth {
param(
[string]$SkopeoImage,
[string]$SourceRef,
[string]$DestRef,
[string]$AuthFilePath,
[int]$ParallelCopies = 16,
[int]$GoMaxProcs = 0
)
$parallelArgs = @()
if ($ParallelCopies -gt 0) {
$parallelArgs = @("--image-parallel-copies", "$ParallelCopies")
}
if ($GoMaxProcs -le 0) { $GoMaxProcs = [Environment]::ProcessorCount }
$vol = Get-DockerAuthVolumeArgs -AuthFilePath $AuthFilePath
if (-not (Test-CmdInPath "skopeo")) {
if (-not $AuthFilePath) {
throw "No auth file for skopeo copy. Use -DestUsername/-DestPassword, DEST_REGISTRY_*, ALIYUN_CR_*, or docker login with resolvable credentials."
}
# GOMAXPROCS lets the Go runtime use more threads for TLS/registry I/O alongside parallel blob copies
$dockerLine = @("run", "--rm", "-e", "GOMAXPROCS=$GoMaxProcs") + $vol + @($SkopeoImage) + @("copy", "--authfile", "/auth.json") + $parallelArgs + @($SourceRef, $DestRef)
& docker @dockerLine
$script:SkopeoLastExitCode = $LASTEXITCODE
return
}
if ($AuthFilePath) {
$env:GOMAXPROCS = "$GoMaxProcs"
try {
& skopeo copy --authfile $AuthFilePath @parallelArgs $SourceRef $DestRef
} finally {
Remove-Item Env:GOMAXPROCS -ErrorAction SilentlyContinue
}
} else {
$env:GOMAXPROCS = "$GoMaxProcs"
try {
& skopeo copy @parallelArgs $SourceRef $DestRef
} finally {
Remove-Item Env:GOMAXPROCS -ErrorAction SilentlyContinue
}
}
$script:SkopeoLastExitCode = $LASTEXITCODE
}
function Invoke-SkopeoInspectRaw {
param([string]$SkopeoImage, [string]$InspectRef)
if (Test-CmdInPath "skopeo") {
$rawLines = & skopeo inspect --raw $InspectRef 2>&1
$code = $LASTEXITCODE
} else {
$rawLines = & docker run --rm $SkopeoImage inspect --raw $InspectRef 2>&1
$code = $LASTEXITCODE
}
return [PSCustomObject]@{ RawLines = $rawLines; ExitCode = $code }
}
function Test-PlatformMatch {
param($ManifestEntry, [string]$OsWant, [string]$ArchWant)
if (-not $ManifestEntry.platform) { return $false }
$os = $ManifestEntry.platform.os
$arch = $ManifestEntry.platform.architecture
if ($os -ne $OsWant) { return $false }
if ($arch -eq $ArchWant) { return $true }
return $false
}
if (-not (Test-CmdInPath "docker")) {
Write-Error "docker not found."
}
$resolved = Resolve-SourceInspectReference -Source $Source -MirrorRegistry $MirrorRegistry
if (-not $DestTag) {
$DestTag = $resolved.Tag
}
$destHost = Get-RegistryHostFromRepo -Repo $DestRepo
$destImage = "${DestRepo}:${DestTag}"
if (-not (Test-CmdInPath "skopeo")) {
Write-Host "Using skopeo from Docker image: $SkopeoImage"
}
Write-Host "Inspect: $($resolved.InspectRef)"
Write-Host "Destination: $destImage"
Write-Host "Platforms: $($Platforms -join ', ')"
$inspectResult = Invoke-SkopeoInspectRaw -SkopeoImage $SkopeoImage -InspectRef $resolved.InspectRef
if ($inspectResult.ExitCode -ne 0) {
throw "skopeo inspect failed (exit $($inspectResult.ExitCode)): $($inspectResult.RawLines)"
}
$rawLines = $inspectResult.RawLines
$rawJson = if ($rawLines -is [array]) { $rawLines -join "`n" } else { [string]$rawLines }
$rawJson = $rawJson.Trim()
if ($rawJson -notmatch '^\s*\{') {
$idx = $rawJson.LastIndexOf('{')
if ($idx -ge 0) { $rawJson = $rawJson.Substring($idx) }
}
$index = $rawJson | ConvertFrom-Json
# Single manifest (not a list): copy tag-to-tag
if (-not $index.manifests) {
Write-Host "Source is a single manifest (not a multi-arch index). Copying tag as-is..."
$srcTagRef = $resolved.InspectRef
$authFileForPush = Resolve-DestinationAuthFile -RegistryHost $destHost
if (-not $authFileForPush) { throw "Could not resolve push credentials for $destHost." }
try {
Invoke-SkopeoCopyWithAuth -SkopeoImage $SkopeoImage -SourceRef $srcTagRef -DestRef "docker://${destImage}" -AuthFilePath $authFileForPush -ParallelCopies $script:EffectiveParallelCopies
if ($script:SkopeoLastExitCode -ne 0) { throw "skopeo copy failed (exit $($script:SkopeoLastExitCode))" }
Write-Host "Done: $destImage"
} finally {
if ($authFileForPush -and (Test-Path -LiteralPath $authFileForPush)) {
Remove-Item -LiteralPath $authFileForPush -Force -ErrorAction SilentlyContinue
}
}
exit 0
}
$digestByPlatform = @{}
foreach ($plat in $Platforms) {
$parts = $plat -split '/', 2
if ($parts.Length -ne 2) { throw "Invalid platform (use os/arch): $plat" }
$osW = $parts[0]
$archW = $parts[1]
$found = $null
foreach ($m in $index.manifests) {
if (Test-PlatformMatch -ManifestEntry $m -OsWant $osW -ArchWant $archW) {
$found = $m.digest
break
}
}
if (-not $found) {
throw "Platform $plat not found in source manifest list. Inspect with: docker buildx imagetools inspect $($resolved.InspectRef -replace '^docker://','')"
}
$digestByPlatform[$plat] = $found
}
foreach ($p in $Platforms) {
Write-Host "$p : $($digestByPlatform[$p])"
}
$srcBase = $resolved.SourceRepoPath
$dstBase = $DestRepo
$authFileForPush = Resolve-DestinationAuthFile -RegistryHost $destHost
if (-not $authFileForPush) {
throw @"
Could not resolve push credentials for $destHost.
Use: -DestUsername / -DestPassword, or env DEST_REGISTRY_USER + DEST_REGISTRY_PASS, or ALIYUN_CR_USER + ALIYUN_CR_PASS, or docker login.
"@
}
try {
Write-Host ""
Write-Host "Tip: After the 'Copying blob ...' lines, the console may stay quiet for many minutes while large layers upload to the registry (not frozen). Watch Task Manager -> Network (send) if unsure."
$step = 1
$total = $Platforms.Count
foreach ($plat in $Platforms) {
$d = $digestByPlatform[$plat]
Write-Host ""
Write-Host "[$step/$total] skopeo copy $plat ..."
$step++
Invoke-SkopeoCopyWithAuth -SkopeoImage $SkopeoImage -SourceRef "docker://${srcBase}@${d}" -DestRef "docker://${dstBase}@${d}" -AuthFilePath $authFileForPush -ParallelCopies $script:EffectiveParallelCopies
if ($script:SkopeoLastExitCode -ne 0) { throw "skopeo copy failed for $plat (exit $($script:SkopeoLastExitCode))" }
}
$refsForBuildx = @()
foreach ($plat in $Platforms) {
$refsForBuildx += "${dstBase}@$($digestByPlatform[$plat])"
}
Write-Host ""
Write-Host "[$($total + 1)/$($total + 1)] docker buildx imagetools create..."
& docker buildx imagetools create -t $destImage @refsForBuildx
if ($LASTEXITCODE -ne 0) { throw "docker buildx imagetools create failed" }
Write-Host ""
Write-Host "Done: $destImage"
Write-Host "Verify: docker buildx imagetools inspect $destImage"
} finally {
if ($authFileForPush -and (Test-Path -LiteralPath $authFileForPush)) {
Remove-Item -LiteralPath $authFileForPush -Force -ErrorAction SilentlyContinue
}
}

67
reset-docker-network.ps1 Normal file
View File

@ -0,0 +1,67 @@
#Requires -RunAsAdministrator
# WSL 与 Docker 网络配置重置脚本
# 需以管理员身份运行
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$ErrorActionPreference = "Continue"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " WSL & Docker 网络配置重置" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 1. 关闭 WSL
Write-Host "[1/5] 关闭 WSL..." -ForegroundColor Yellow
wsl --shutdown
Start-Sleep -Seconds 3
Write-Host " 完成" -ForegroundColor Green
# 2. 重置 Windows 网络栈(可选,可能需重启)
Write-Host "[2/5] 重置 Windows 网络栈..." -ForegroundColor Yellow
try {
netsh winsock reset 2>$null
netsh int ip reset 2>$null
Write-Host " 完成 (如有提示重启,建议执行)" -ForegroundColor Green
} catch {
Write-Host " 跳过: $($_.Exception.Message)" -ForegroundColor Gray
}
# 3. 清理 Docker 网络
Write-Host "[3/5] 清理 Docker 未使用网络..." -ForegroundColor Yellow
$dockerOk = $false
try {
$null = docker info 2>&1
$dockerOk = $true
} catch { }
if ($dockerOk) {
docker network prune -f 2>$null
Write-Host " 完成" -ForegroundColor Green
} else {
Write-Host " 跳过 (Docker 未运行,请先启动 Docker Desktop)" -ForegroundColor Gray
}
# 4. 清除 Docker 端口代理残留(若有)
Write-Host "[4/5] 检查端口代理..." -ForegroundColor Yellow
$proxies = netsh interface portproxy show all 2>$null
if ($proxies -and $proxies -match "3010|3001|3002|3003") {
Write-Host " 发现相关端口代理,请手动在管理员 CMD 执行:" -ForegroundColor Yellow
Write-Host " netsh interface portproxy reset" -ForegroundColor White
} else {
Write-Host " 无异常端口代理" -ForegroundColor Green
}
# 5. 提示
Write-Host "[5/5] 下一步操作:" -ForegroundColor Yellow
Write-Host ""
Write-Host " 1. 启动 Docker Desktop若已关闭" -ForegroundColor White
Write-Host " 2. 等待 Docker 完全就绪后,执行:" -ForegroundColor White
Write-Host " cd D:\01一键部署包\easyai" -ForegroundColor Cyan
Write-Host " docker compose up -d" -ForegroundColor Cyan
Write-Host ""
Write-Host " 3. 若端口仍不可访问,在 Docker Desktop 中:" -ForegroundColor White
Write-Host " [设置] -> [Troubleshoot] -> [Reset to factory defaults]" -ForegroundColor Cyan
Write-Host " (会清除所有容器/镜像,谨慎使用)" -ForegroundColor Gray
Write-Host ""
Write-Host " 4. 若执行了 netsh winsock/int ip reset建议重启电脑" -ForegroundColor White
Write-Host ""
Read-Host "按 Enter 键退出"

View File

@ -0,0 +1,27 @@
#!/usr/bin/env python3
# 验证 start.ps1 的 .env 替换逻辑(与 PowerShell 等效)
import re
DEPLOY_IP = "192.168.1.100"
content = """NUXT_PUBLIC_BASE_APIURL=http://127.0.0.1:3001
#NUXT_PUBLIC_BASE_APIURL=/api
NUXT_PUBLIC_BASE_SOCKETURL=ws://127.0.0.1:3002
NUXT_PUBLIC_SG_APIURL=http://127.0.0.1:3003
"""
content = re.sub(r'^NUXT_PUBLIC_BASE_APIURL=.*', f'NUXT_PUBLIC_BASE_APIURL=http://{DEPLOY_IP}:3001', content, flags=re.MULTILINE)
content = re.sub(r'^NUXT_PUBLIC_BASE_SOCKETURL=.*', f'NUXT_PUBLIC_BASE_SOCKETURL=ws://{DEPLOY_IP}:3002', content, flags=re.MULTILINE)
content = re.sub(r'^NUXT_PUBLIC_SG_APIURL=.*', f'NUXT_PUBLIC_SG_APIURL=http://{DEPLOY_IP}:3003', content, flags=re.MULTILINE)
expected = f"""NUXT_PUBLIC_BASE_APIURL=http://{DEPLOY_IP}:3001
#NUXT_PUBLIC_BASE_APIURL=/api
NUXT_PUBLIC_BASE_SOCKETURL=ws://{DEPLOY_IP}:3002
NUXT_PUBLIC_SG_APIURL=http://{DEPLOY_IP}:3003
"""
# 注释行不应被替换,检查第一行和第三行
lines = content.split('\n')
assert lines[0] == f'NUXT_PUBLIC_BASE_APIURL=http://{DEPLOY_IP}:3001', f"Got {lines[0]}"
assert lines[2] == f'NUXT_PUBLIC_BASE_SOCKETURL=ws://{DEPLOY_IP}:3002', f"Got {lines[2]}"
assert lines[3] == f'NUXT_PUBLIC_SG_APIURL=http://{DEPLOY_IP}:3003', f"Got {lines[3]}"
assert lines[1] == '#NUXT_PUBLIC_BASE_APIURL=/api', f"Comment should not change: {lines[1]}"
print("OK: .env replacement logic validated")

371
start.ps1 Normal file
View File

@ -0,0 +1,371 @@
#Requires -Version 5.1
#
# 从 Git 克隆后首次部署(推荐分行复制执行,避免参数被误传给 git浅克隆加 --depth 1
# git clone --depth 1 "https://git.51easyai.com/wangbo/easyai.git" "easyai"
# Set-Location ".\easyai"
# powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1"
#
# 若必须一行,请用分号分隔整条链,且 -File 后必须是带引号的脚本路径(不要用 Istart.ps1应为 .\start.ps1
# git clone --depth 1 "https://git.51easyai.com/wangbo/easyai.git" "easyai"; Set-Location "easyai"; powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1"
#
# 若出现 error: unknown switch 'E':说明 -ExecutionPolicy 被交给了 git可复现git clone URL -ExecutionPolicy
# 常见原因:整段命令未用分号分隔、或把 powershell 与 git 写在同一行且参数被 git 解析。
# "Istart.ps1" 多为把 ".\start.ps1" 复制错(点反斜杠被看成字母 I
#
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
$ErrorActionPreference = "Stop"
$script:Root = if ($PSScriptRoot) { $PSScriptRoot } else { (Get-Location).Path }
$script:LogFile = Join-Path $script:Root "start.ps1.log"
$script:DeployDryRun = ($env:DEPLOY_DRY_RUN -eq "1")
$script:DeployIP = ""
$script:SkipDeployQuestions = $false
$script:DockerDesktopUrl = "https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe"
function Write-Log {
param([string]$Message)
try {
Add-Content -Path $script:LogFile -Encoding UTF8 -Value ("[{0}] {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message)
} catch { }
}
function Wait-ForExit {
if ($env:CI -eq "true") { return }
if ($env:DEPLOY_NO_WAIT -eq "1") { return }
Write-Host ""
Read-Host "Press Enter to exit"
}
trap {
$msg = $_.Exception.Message
Write-Log "FATAL: $msg"
Write-Host ""
Write-Host "========================================" -ForegroundColor Red
Write-Host "Script failed. Log file: $script:LogFile" -ForegroundColor Red
Write-Host "========================================" -ForegroundColor Red
Write-Host $msg -ForegroundColor Red
Wait-ForExit
exit 1
}
function Step { param([string]$Message) Write-Host $Message }
function Ok { param([string]$Message) Write-Host "[OK] $Message" -ForegroundColor Green }
function Warn { param([string]$Message) Write-Host "[WARN] $Message" -ForegroundColor Yellow }
function Fail { param([string]$Message) Write-Host "[ERR] $Message" -ForegroundColor Red; throw $Message }
function Init-ProjectDir {
$composePath = Join-Path $script:Root "docker-compose.yml"
if (-not (Test-Path $composePath)) {
Fail "docker-compose.yml not found. Please run this script in easyai directory."
}
Set-Location $script:Root
Step "Project directory: $script:Root"
}
function Ensure-FileFromSample {
param([string]$Target,[string]$Sample)
if (Test-Path $Target) { return }
if (-not (Test-Path $Sample)) { Fail "Missing sample file: $Sample" }
Copy-Item $Sample $Target
Ok "$Target created"
}
function Get-DetectedLanIp {
try {
$ip = Get-NetIPAddress -AddressFamily IPv4 -ErrorAction SilentlyContinue | Where-Object {
$_.IPAddress -notmatch "^127\." -and
$_.IPAddress -notmatch "^169\.254\." -and
$_.InterfaceAlias -notmatch "Loopback"
} | Sort-Object InterfaceIndex | Select-Object -First 1 -ExpandProperty IPAddress
return $ip
} catch {
return $null
}
}
function Run-DeployQuestions {
Write-Host ""
Write-Host "================================"
Write-Host " EasyAI Deployment Config"
Write-Host "================================"
Write-Host ""
if ($env:DEPLOY_IP) {
$script:DeployIP = $env:DEPLOY_IP.Trim()
Step "Using DEPLOY_IP=$($script:DeployIP)"
return
}
Write-Host "Choose mode:"
Write-Host " [1] Local only (127.0.0.1)"
Write-Host " [2] LAN access"
$choice = Read-Host "Select [1/2]"
switch ($choice) {
"1" { $script:DeployIP = "127.0.0.1"; Step "Selected local mode" }
"2" {
$detected = Get-DetectedLanIp
if ($detected) {
Write-Host "Detected LAN IP: $detected"
$inputIp = (Read-Host "Input LAN IP (Enter to use detected)").Trim()
$script:DeployIP = if ([string]::IsNullOrWhiteSpace($inputIp)) { $detected } else { $inputIp }
} else {
$inputIp = (Read-Host "Input LAN IP").Trim()
if ([string]::IsNullOrWhiteSpace($inputIp)) { Fail "IP cannot be empty." }
$script:DeployIP = $inputIp
}
Warn "Allow firewall ports: 3001, 3002, 3003"
}
default { Fail "Invalid selection." }
}
}
function Upsert-Env {
param([string]$Content,[string]$Key,[string]$Value)
$line = "$Key=$Value"
$pattern = "(?m)^$Key=.*$"
if ($Content -match $pattern) { return ($Content -replace $pattern, $line) }
if ($Content -and -not $Content.EndsWith("`n")) { $Content += "`n" }
return ($Content + $line + "`n")
}
function Setup-EnvFiles {
Write-Host ""
Step "Configuring env files..."
Ensure-FileFromSample ".env.tools" ".env.tools.sample"
Ensure-FileFromSample ".env.ASG" ".env.ASG.sample"
Ensure-FileFromSample ".env.AMS" ".env.AMS.sample"
Ensure-FileFromSample ".env" ".env.sample"
$content = Get-Content ".env" -Raw -Encoding UTF8
if (-not $content) { $content = "" }
$content = Upsert-Env $content "NUXT_PUBLIC_BASE_APIURL" "http://$($script:DeployIP):3001"
$content = Upsert-Env $content "NUXT_PUBLIC_BASE_SOCKETURL" "ws://$($script:DeployIP):3002"
$content = Upsert-Env $content "NUXT_PUBLIC_SG_APIURL" "http://$($script:DeployIP):3003"
[System.IO.File]::WriteAllText((Join-Path $script:Root ".env"), $content, [System.Text.UTF8Encoding]::new($false))
Ok ".env configured for IP=$($script:DeployIP)"
}
function Test-DockerInstalled {
$docker = Get-Command docker -ErrorAction SilentlyContinue
if (-not $docker) { return $false }
try { & docker --version *> $null; return $true } catch { return $false }
}
function Test-DockerRunning {
param([int]$TimeoutSeconds = 10)
try {
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = "docker"
$psi.Arguments = "info"
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.UseShellExecute = $false
$psi.CreateNoWindow = $true
$p = [System.Diagnostics.Process]::Start($psi)
$ok = $p.WaitForExit($TimeoutSeconds * 1000)
if (-not $ok) { try { $p.Kill() } catch { }; return $false }
return ($p.ExitCode -eq 0)
} catch {
return $false
}
}
function Start-DockerDesktopAndWait {
param([int]$MaxWaitSeconds = 120, [int]$CheckIntervalSeconds = 5)
Step "Docker not running, trying to start Docker Desktop..."
$path = Join-Path $env:ProgramFiles "Docker\Docker\Docker Desktop.exe"
if (-not (Test-Path $path)) { $path = Join-Path ${env:ProgramFiles(x86)} "Docker\Docker\Docker Desktop.exe" }
if (-not (Test-Path $path)) { Warn "Docker Desktop executable not found."; return $false }
$startedByCli = $false
try {
& docker desktop start *> $null
if ($LASTEXITCODE -eq 0) { $startedByCli = $true; Step "Sent docker desktop start command" }
} catch { }
if (-not $startedByCli) { Start-Process -FilePath $path -WindowStyle Hidden }
$elapsed = 0
while ($elapsed -lt $MaxWaitSeconds) {
Start-Sleep -Seconds $CheckIntervalSeconds
$elapsed += $CheckIntervalSeconds
if (Test-DockerRunning) { Ok "Docker engine ready"; return $true }
}
Warn "Timeout waiting for Docker."
return $false
}
function Ensure-DockerRunning {
if (-not (Test-DockerInstalled)) { return $false }
if (Test-DockerRunning) { Ok "Docker engine running"; return $true }
return (Start-DockerDesktopAndWait)
}
function Install-DockerDesktop {
function Test-Winget {
return [bool](Get-Command winget -ErrorAction SilentlyContinue)
}
function Test-Choco {
return [bool](Get-Command choco -ErrorAction SilentlyContinue)
}
if (Test-Winget) {
Step "Installing Docker Desktop via winget..."
Write-Log "winget install Docker.DockerDesktop"
$wingetOut = & winget install --id Docker.DockerDesktop -e --accept-source-agreements --accept-package-agreements 2>&1
$wingetOut | ForEach-Object { Write-Host $_ }
$wingetCode = $LASTEXITCODE
Write-Log "winget exit code: $wingetCode"
if ($wingetCode -eq 0) {
Ok "Install started. Reopen terminal and rerun script."
Write-Log "winget reported success"
exit 0
}
if (Test-DockerInstalled) {
Ok "Docker CLI detected after winget. Reopen terminal if docker commands fail, then rerun script."
Write-Log "winget exit $wingetCode but docker is available"
exit 0
}
Warn "winget did not report success (exit code: $wingetCode). Trying Chocolatey if available..."
} else {
Warn "winget not found (install 'App Installer' from Microsoft Store or use Windows 11 / recent Windows 10). Trying Chocolatey if available..."
}
if (Test-Choco) {
Step "Installing Docker Desktop via choco..."
Write-Log "choco install docker-desktop"
$chocoOut = & choco install docker-desktop -y 2>&1
$chocoOut | ForEach-Object { Write-Host $_ }
$chocoCode = $LASTEXITCODE
Write-Log "choco exit code: $chocoCode"
if ($chocoCode -eq 0) {
Ok "Install started. Reopen terminal and rerun script."
exit 0
}
if (Test-DockerInstalled) {
Ok "Docker CLI detected after choco. Reopen terminal if docker commands fail, then rerun script."
exit 0
}
Warn "choco did not report success (exit code: $chocoCode)."
} else {
Warn "Chocolatey (choco) not found."
}
Warn "Automatic install was not completed. Please install Docker Desktop manually:"
Write-Host " $script:DockerDesktopUrl"
Write-Log "Docker auto-install failed (winget/choco unavailable or non-zero exit)"
Wait-ForExit
exit 1
}
function Test-Docker {
Write-Host ""
Write-Host "================================"
Write-Host " Docker Check"
Write-Host "================================"
Write-Host ""
if (Test-DockerInstalled) {
Ok "Docker installed"
if (-not (Ensure-DockerRunning)) { Warn "Docker failed to start automatically."; Wait-ForExit; exit 1 }
return
}
Warn "Docker Desktop not detected."
Write-Host "Choose:"
Write-Host " [1] Manual install (open URL and exit)"
Write-Host " [2] Auto install (winget/choco)"
$choice = (Read-Host "Select [1/2]").Trim()
switch ($choice) {
"1" { Start-Process $script:DockerDesktopUrl; Wait-ForExit; exit 1 }
"2" { Install-DockerDesktop }
default { Fail "Invalid selection." }
}
}
function Start-Services {
Write-Host ""
Step "Starting EasyAI services..."
$useComposeV2 = $false
try { & docker compose version *> $null; if ($LASTEXITCODE -eq 0) { $useComposeV2 = $true } } catch { }
if ($useComposeV2) {
docker compose pull
if ($LASTEXITCODE -ne 0) { Fail "docker compose pull failed." }
docker compose up -d
if ($LASTEXITCODE -ne 0) { Fail "docker compose up failed." }
} else {
docker-compose pull
if ($LASTEXITCODE -ne 0) { Fail "docker-compose pull failed." }
docker-compose up -d
if ($LASTEXITCODE -ne 0) { Fail "docker-compose up failed." }
}
Ok "EasyAI started"
}
function Main {
Init-ProjectDir
if ((Test-Path ".env") -and -not $env:DEPLOY_FORCE_RECONFIG -and -not $env:DEPLOY_IP) {
$answer = (Read-Host "Existing .env found. Reconfigure? [y/N]").Trim().ToLower()
$yes = ($answer.Length -gt 0) -and ($answer[0] -eq [char]121)
if (-not $yes) {
$line = Get-Content ".env" -Encoding UTF8 | Where-Object { $_ -like "NUXT_PUBLIC_BASE_APIURL=*" } | Select-Object -First 1
if ($line -and $line -like "*:3001*") { $script:DeployIP = ($line -replace ".*http://", "" -replace ":3001.*", "").Trim() }
$script:SkipDeployQuestions = $true
Step "Using existing env config"
}
}
if (-not $script:SkipDeployQuestions) {
Run-DeployQuestions
Setup-EnvFiles
} else {
Ensure-FileFromSample ".env.tools" ".env.tools.sample"
Ensure-FileFromSample ".env.ASG" ".env.ASG.sample"
Ensure-FileFromSample ".env.AMS" ".env.AMS.sample"
}
if ($script:DeployDryRun) {
Warn "dry-run mode: skip docker and services"
} else {
Test-Docker
Start-Services
}
$ip = if ($script:DeployIP) { $script:DeployIP } else { "127.0.0.1" }
Write-Host ""
if ($script:DeployDryRun) {
Write-Host "================================" -ForegroundColor Yellow
Write-Host " 配置已生成(未启动 Docker 服务)" -ForegroundColor Yellow
Write-Host "================================" -ForegroundColor Yellow
Write-Host ""
Write-Host " 预期访问: " -NoNewline; Write-Host "http://${ip}:3010" -ForegroundColor Cyan
Write-Host ""
Write-Host " 默认管理员: admin / 123456启动服务后用于登录" -ForegroundColor DarkGray
} else {
Write-Host "================================" -ForegroundColor Green
Write-Host " 部署成功" -ForegroundColor Green
Write-Host "================================" -ForegroundColor Green
Write-Host ""
Write-Host " 访问地址: " -NoNewline; Write-Host "http://${ip}:3010" -ForegroundColor Cyan
Write-Host ""
Write-Host " -------- 默认管理员(首次登录后请修改密码)--------" -ForegroundColor Yellow
Write-Host " 账号: " -NoNewline; Write-Host "admin" -ForegroundColor White
Write-Host " 密码: " -NoNewline; Write-Host "123456" -ForegroundColor White
}
Write-Host ""
Wait-ForExit
}
Write-Log "=== script start ==="
Write-Host "EasyAI deploy script starting..." -ForegroundColor Cyan
Write-Host "Log file: $script:LogFile"
Write-Host ""
Main
Write-Log "=== script end ==="

542
start.sh
View File

@ -1,186 +1,436 @@
#!/bin/bash #!/bin/bash
# EasyAI 一键部署脚本
# 支持交互式问答配置,兼容 IP 与域名两种访问方式
# 一行命令: git clone --depth 1 https://git.51easyai.com/wangbo/easyai.git && cd easyai && chmod +x ./start.sh && ./start.sh
set -e # 发生错误时终止脚本执行 set -e
echo "===========================" # 仅配置模式验证用DEPLOY_DRY_RUN=1 只生成配置文件,不执行 Docker 安装和启动
echo "🚀 开始自动安装 Docker 和 Docker Compose" DEPLOY_DRY_RUN="${DEPLOY_DRY_RUN:-0}"
echo "==========================="
# 获取操作系统类型和版本 # ==================== 项目初始化 ====================
OS_FAMILY=$(hostnamectl | grep "Operating System" | awk '{print $3}') init_project_dir() {
OS_VERSION_ID=$(grep -oP '(?<=^VERSION_ID=")[0-9.]+' /etc/os-release | cut -d'.' -f1) local script_source
script_source="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
if [ -f "${script_source}/docker-compose.yml" ]; then
echo "📁 项目目录: ${script_source}"
cd "$script_source"
return 0
fi
echo "❌ 未找到 docker-compose.yml请在 easyai 项目目录下运行 start.sh"
echo " 启动命令: git clone --depth 1 https://git.51easyai.com/wangbo/easyai.git && cd easyai && chmod +x ./start.sh && ./start.sh"
exit 1
}
# ==================== 配置变量(支持环境变量非交互模式) ====================
DEPLOY_MODE="" # ip | domain
DEPLOY_IP=""
DEPLOY_DOMAIN=""
DEPLOY_HTTPS=false
sanitize_domain() {
local domain="$1"
domain="${domain#http://}"
domain="${domain#https://}"
domain="${domain%%/*}"
domain="${domain%;}"
echo "$domain"
}
validate_domain() {
local domain="$1"
# 基础域名校验:仅允许字母、数字、连字符和点;必须包含至少一个点;不能以点或连字符开头结尾
if [[ ! "$domain" =~ ^[A-Za-z0-9.-]+$ ]]; then
return 1
fi
if [[ "$domain" != *.* ]]; then
return 1
fi
if [[ "$domain" =~ ^[.-] || "$domain" =~ [.-]$ ]]; then
return 1
fi
if [[ "$domain" == *".."* ]]; then
return 1
fi
return 0
}
prompt_or_env() {
local var_name=$1
local prompt_text=$2
local env_name=$3
local default=$4
if [ -n "${!env_name}" ]; then
eval "$var_name=\"${!env_name}\""
return
fi
if [ -n "$default" ]; then
read -r -p "${prompt_text} [$default]: " input
eval "$var_name=\"${input:-$default}\""
else
read -r -p "${prompt_text}: " input
eval "$var_name=\"$input\""
fi
}
run_deploy_questions() {
echo ""
echo "================================"
echo " EasyAI 部署配置(问答模式)"
echo "================================"
echo ""
# 非交互模式环境变量已完整设置则直接使用CI/自动化部署)
if [ -n "$DEPLOY_ACCESS" ]; then
if [ "$DEPLOY_ACCESS" = "ip" ] && [ -n "$DEPLOY_IP" ]; then
DEPLOY_MODE="ip"
echo "使用环境变量: IP 模式, IP=$DEPLOY_IP"
return
fi
if [ "$DEPLOY_ACCESS" = "domain" ] && [ -n "$DEPLOY_DOMAIN" ]; then
DEPLOY_DOMAIN="$(sanitize_domain "$DEPLOY_DOMAIN")"
if ! validate_domain "$DEPLOY_DOMAIN"; then
echo "❌ 环境变量 DEPLOY_DOMAIN 格式不合法: ${DEPLOY_DOMAIN}"
exit 1
fi
DEPLOY_MODE="domain"
DEPLOY_HTTPS="${DEPLOY_HTTPS_INPUT:-false}"
echo "使用环境变量: 域名模式, 域名=$DEPLOY_DOMAIN"
return
fi
fi
# 1. IP 或域名访问
if [ -z "$DEPLOY_ACCESS" ]; then
echo "1. 通过 IP 地址还是域名访问?"
echo " [1] IP 地址(需开放 3001、3002、3003 端口)"
echo " [2] 域名"
read -r -p "请选择 [1/2]: " choice
case "$choice" in
1) DEPLOY_MODE="ip" ;;
2) DEPLOY_MODE="domain" ;;
*) echo "❌ 无效选择"; exit 1 ;;
esac
else
DEPLOY_MODE="$DEPLOY_ACCESS"
fi
if [ "$DEPLOY_MODE" = "ip" ]; then
# 2. 输入服务器 IP
prompt_or_env DEPLOY_IP "2. 请输入服务器 IP 地址" "DEPLOY_IP" ""
if [ -z "$DEPLOY_IP" ]; then
echo "❌ IP 不能为空"
exit 1
fi
echo " 请确保防火墙已放行 3001、3002、3003 端口"
else
# 3. 输入域名
prompt_or_env DEPLOY_DOMAIN "3. 请输入域名(不含 https:// 前缀,如 51easyai.com" "DEPLOY_DOMAIN" ""
DEPLOY_DOMAIN="$(sanitize_domain "$DEPLOY_DOMAIN")"
if [ -z "$DEPLOY_DOMAIN" ]; then
echo "❌ 域名不能为空"
exit 1
fi
if ! validate_domain "$DEPLOY_DOMAIN"; then
echo "❌ 域名格式不合法: ${DEPLOY_DOMAIN}"
echo " 请输入类似 51easyai.com 的域名,不要包含协议、路径或分号"
exit 1
fi
# 3.1 是否启用 HTTPS
if [ -n "$DEPLOY_HTTPS_INPUT" ]; then
DEPLOY_HTTPS=$DEPLOY_HTTPS_INPUT
else
read -r -p "3.1 是否签名 HTTPS 证书?原来已经有 HTTPS 证书这里选择 N第一次部署或者原来没有证书选 Y [y/N]: " https_choice
DEPLOY_HTTPS=false
if [[ "$https_choice" =~ ^[yY] ]]; then
DEPLOY_HTTPS=true
fi
fi
if [ "$DEPLOY_HTTPS" = true ]; then
echo " 启用 HTTPS 需确保防火墙已放行 80、443 端口"
fi
fi
}
# ==================== 生成配置文件 ====================
setup_env_files() {
echo ""
echo "📝 配置环境文件..."
# 6. 复制 .env.tools、.env.ASG、.env.AMS无 example 后缀的从 .sample 生成)
if [ ! -f .env.tools ]; then
cp .env.tools.sample .env.tools
echo " ✓ .env.tools"
fi
if [ ! -f .env.ASG ]; then
cp .env.ASG.sample .env.ASG
echo " ✓ .env.ASG"
fi
if [ ! -f .env.AMS ]; then
cp .env.AMS.sample .env.AMS
echo " ✓ .env.AMS"
fi
# 4/5. 配置 .env
if [ ! -f .env ]; then
cp .env.sample .env
fi
if [ "$DEPLOY_MODE" = "ip" ]; then
# IP 模式
sed -i.bak "s|^NUXT_PUBLIC_BASE_APIURL=.*|NUXT_PUBLIC_BASE_APIURL=http://${DEPLOY_IP}:3001|" .env
sed -i.bak "s|^NUXT_PUBLIC_BASE_SOCKETURL=.*|NUXT_PUBLIC_BASE_SOCKETURL=ws://${DEPLOY_IP}:3002|" .env
sed -i.bak "s|^NUXT_PUBLIC_SG_APIURL=.*|NUXT_PUBLIC_SG_APIURL=http://${DEPLOY_IP}:3003|" .env
echo " ✓ .env 已配置为 IP 模式 (${DEPLOY_IP})"
else
# 域名模式
sed -i.bak "s|^NUXT_PUBLIC_BASE_APIURL=.*|NUXT_PUBLIC_BASE_APIURL=/api|" .env
sed -i.bak "s|^NUXT_PUBLIC_BASE_SOCKETURL=.*|NUXT_PUBLIC_BASE_SOCKETURL=wss://${DEPLOY_DOMAIN}/socket.io|" .env
sed -i.bak "s|^NUXT_PUBLIC_SG_APIURL=.*|NUXT_PUBLIC_SG_APIURL=/asg-api|" .env
echo " ✓ .env 已配置为域名模式 (${DEPLOY_DOMAIN})"
# 7. Nginx 配置(域名模式)
PROXY_CONF="${DEPLOY_DOMAIN}.conf"
if [ ! -f "$PROXY_CONF" ]; then
local proxy_template="easyai-proxy.conf.sample"
if [ ! -f "$proxy_template" ]; then
echo "❌ 未找到 Nginx 配置模板: easyai-proxy.conf.sample"
echo " 请确认仓库文件完整后重试"
exit 1
fi
sed "s/51easyai.com/${DEPLOY_DOMAIN}/g" "$proxy_template" > "$PROXY_CONF"
echo " ✓ Nginx 配置已生成: $PROXY_CONF"
fi
fi
rm -f .env.bak
}
# ==================== Docker 安装(复用原 start.sh 逻辑) ====================
install_docker() {
echo ""
echo "================================"
echo " Docker 安装与检查"
echo "================================"
local host_os
host_os="$(uname -s 2>/dev/null || echo Unknown)"
if [[ "$host_os" == "Darwin" ]]; then
OS_FAMILY="macOS"
OS_VERSION_ID="0"
OS_CODENAME=""
elif [ -f /etc/os-release ]; then
. /etc/os-release
case "${ID:-}" in
ubuntu|debian) OS_FAMILY="Ubuntu" ;;
centos|rhel|fedora) OS_FAMILY="CentOS" ;;
*) OS_FAMILY="${ID:-Unknown}" ;;
esac
OS_VERSION_ID=$(grep -oP '(?<=^VERSION_ID=")[0-9.]+' /etc/os-release 2>/dev/null | cut -d'.' -f1 || echo "0")
OS_CODENAME="" OS_CODENAME=""
if [[ "$OS_FAMILY" == "Ubuntu" ]]; then if [[ "$OS_FAMILY" == "Ubuntu" ]]; then
OS_CODENAME=$(lsb_release -cs) OS_CODENAME=$(lsb_release -cs 2>/dev/null || (grep VERSION_CODENAME /etc/os-release 2>/dev/null | cut -d= -f2 | tr -d '"'))
fi fi
# 定义国内镜像源
# Ubuntu 镜像源
UBUNTU_DOCKER_MIRROR_URL="https://mirrors.ustc.edu.cn/docker-ce" # 中科大
UBUNTU_DOCKER_GPG_URL="https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg"
# CentOS 镜像源 (选择一个即可,这里提供清华和阿里云)
CENTOS_DOCKER_MIRROR_URL="https://mirrors.tuna.tsinghua.edu.cn/docker-ce" # 清华大学
# CENTOS_DOCKER_MIRROR_URL="https://mirrors.aliyun.com/docker-ce" # 阿里云 - 如果清华源不稳定可以尝试这个
# 函数:检查并等待网络连接
check_network() {
echo "🌐 检查网络连接到 Docker 官方仓库 (备用)..."
if curl -sSf https://download.docker.com/ &> /dev/null; then
echo "✅ 网络连接到 Docker 官方仓库正常。"
return 0
else else
echo "⚠️ 无法连接到 Docker 官方仓库。将尝试使用国内镜像源。" OS_FAMILY=$(hostnamectl 2>/dev/null | grep "Operating System" | awk '{print $3}' || echo "Unknown")
# 即使无法连接官方源,也继续尝试国内源 OS_VERSION_ID="0"
OS_CODENAME=""
fi
UBUNTU_DOCKER_MIRROR_URL="https://mirrors.ustc.edu.cn/docker-ce"
UBUNTU_DOCKER_GPG_URL="https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg"
CENTOS_DOCKER_MIRROR_URL="https://mirrors.tuna.tsinghua.edu.cn/docker-ce"
check_network() {
if curl -sSf --connect-timeout 5 https://download.docker.com/ &>/dev/null; then
echo "✅ 网络连接正常"
return 0 return 0
fi fi
echo "⚠️ 将使用国内镜像源"
return 0
} }
# 预检网络连接(非阻塞,仅作为提示)
check_network check_network
# Docker 安装 install_docker_macos() {
if ! command -v brew &>/dev/null; then
echo "❌ 未检测到 Homebrew无法自动安装 Docker Desktop。"
echo " 请先安装 Homebrew: https://brew.sh/"
return 1
fi
if brew list --cask docker &>/dev/null; then
echo "✅ Docker Desktop 已安装Homebrew"
else
echo "📦 正在通过 Homebrew 安装 Docker Desktop..."
brew install --cask docker
fi
echo "🚀 正在尝试启动 Docker Desktop..."
open -a Docker || true
echo "⏳ 等待 Docker 引擎就绪(最多 120 秒)..."
local i
for i in $(seq 1 60); do
if docker info &>/dev/null; then
echo "✅ Docker Desktop 已启动并可用"
return 0
fi
sleep 2
done
echo "⚠️ Docker Desktop 已安装,但尚未就绪。"
echo " 请手动打开 Docker Desktop待状态正常后重新运行 ./start.sh"
return 1
}
if command -v docker &>/dev/null; then if command -v docker &>/dev/null; then
echo "✅ Docker 已安装,跳过安装步骤" echo "✅ Docker 已安装"
else else
if [[ "$OS_FAMILY" == "Ubuntu" ]]; then if [[ "$OS_FAMILY" == "Ubuntu" ]]; then
echo "📦 安装依赖 (Ubuntu)..."
sudo apt update -y sudo apt update -y
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release
echo "🔑 添加 Docker GPG 密钥 (Ubuntu) - 优先使用国内镜像源..."
# 现代 Ubuntu 推荐使用 gpg --dearmor
sudo install -m 0755 -d /etc/apt/keyrings sudo install -m 0755 -d /etc/apt/keyrings
if ! curl -fsSL "$UBUNTU_DOCKER_GPG_URL" | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg; then curl -fsSL "$UBUNTU_DOCKER_GPG_URL" | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg 2>/dev/null || \
echo "❌ 无法从国内镜像源获取 GPG 密钥,尝试从官方源获取..." curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg || { sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo "❌ 无法获取 Docker GPG 密钥,请检查网络或 GPG 密钥 URL。" echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] $UBUNTU_DOCKER_MIRROR_URL/linux/ubuntu $OS_CODENAME stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
exit 1
}
fi
sudo chmod a+r /etc/apt/keyrings/docker.gpg # 确保可读权限
echo "🌍 添加 Docker 源 (Ubuntu) - 使用国内镜像源..."
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] $UBUNTU_DOCKER_MIRROR_URL/linux/ubuntu \
$OS_CODENAME stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update -y sudo apt-get update -y
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
echo "🐳 安装 Docker (Ubuntu)..."
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin || {
echo "❌ Docker 或其组件安装失败。请检查错误日志或尝试手动安装。"
exit 1
}
elif [[ "$OS_FAMILY" == "CentOS" ]]; then elif [[ "$OS_FAMILY" == "CentOS" ]]; then
echo "📦 安装依赖 (CentOS)..." sudo yum install -y yum-utils
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
echo "🌍 添加 Docker 源 (CentOS) - 使用国内镜像源..."
# 添加 Docker CE 官方 repo
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo sed -i "s+https://download.docker.com+$CENTOS_DOCKER_MIRROR_URL+g" /etc/yum.repos.d/docker-ce.repo
# 替换为国内镜像源 [[ "$OS_VERSION_ID" -ge "8" ]] && sudo yum module disable -y container-tools 2>/dev/null || true
echo "🔄 替换 Docker 源为国内镜像 ($CENTOS_DOCKER_MIRROR_URL)..." sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo sed -i "s+https://download.docker.com+$CENTOS_DOCKER_MIRROR_URL+" /etc/yum.repos.d/docker-ce.repo || { elif [[ "$OS_FAMILY" == "macOS" ]]; then
echo "❌ 替换 Docker 源失败,可能 repo 文件路径不正确或无权限。" echo "⚠️ 检测到 macOS未找到 Docker。"
echo "请选择安装方式:"
echo " [1] 自动安装 Docker Desktop需要 Homebrew"
echo " [2] 手动安装(默认)"
read -r -p "请选择 [1/2]: " mac_install_choice
case "${mac_install_choice:-2}" in
1)
if ! install_docker_macos; then
exit 1 exit 1
}
# CentOS 8+ 可能会遇到 module 冲突,禁用默认的 container-tools 模块
if [[ "$OS_VERSION_ID" -ge "8" ]]; then
echo "⚙️ 禁用 CentOS 8+ 默认的 container-tools 模块以避免冲突..."
sudo yum module disable -y container-tools
sudo yum module enable -y container-tools:docker
fi fi
sudo yum makecache ;;
2)
echo "🐳 安装 Docker (CentOS)..." echo " 请手动安装 Docker Desktop: https://www.docker.com/products/docker-desktop/"
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin || { echo " 安装并启动 Docker Desktop 后,重新运行 ./start.sh"
echo "❌ Docker 或其组件安装失败。请检查错误日志或尝试手动安装。"
echo "提示:如果仍遇到下载问题,请检查网络、防火墙或尝试切换另一个国内镜像源。"
exit 1 exit 1
} ;;
*)
echo "❌ 无效选择"
exit 1
;;
esac
else else
echo "❌ 未知操作系统 ($OS_FAMILY),无法安装 Docker。" echo "❌ 不支持的操作系统: $OS_FAMILY"
exit 1 exit 1
fi fi
if [[ "$OS_FAMILY" != "macOS" ]]; then
echo "✅ 启动并设置 Docker 开机自启..."
sudo systemctl enable docker sudo systemctl enable docker
sudo systemctl start docker sudo systemctl start docker
getent group docker | grep -qw "$USER" || sudo usermod -aG docker "$USER"
# 将当前用户添加到 docker 组,以便无需 sudo 运行 Docker 命令
if ! getent group docker | grep -qw "$USER"; then
echo "👥 将当前用户 ($USER) 添加到 docker 组..."
sudo usermod -aG docker "$USER"
echo "🔔 请注销并重新登录,以便更改生效。"
fi fi
fi fi
# Docker Compose 检查和安装 (优先使用 docker-compose-plugin) if docker compose version &>/dev/null; then
if command -v docker &> /dev/null && docker compose version &> /dev/null; then echo "✅ Docker Compose 已就绪"
echo "✅ Docker Compose (插件版) 已安装,跳过安装步骤" elif command -v docker-compose &>/dev/null; then
elif command -v docker-compose &> /dev/null && ! command -v docker &> /dev/null; then echo "✅ Docker Compose (兼容模式) 已就绪"
echo "⚠️ 检测到旧版 Docker Compose 独立安装,但未检测到 Docker 插件版。"
echo "建议在安装 Docker CE 时一起安装 docker-compose-plugin。"
else else
echo "⚙️ 安装 Docker Compose (插件版)..." echo "❌ 请安装 docker-compose-plugin"
PLUGIN_INSTALL_SUCCESS=1
# 如果 Docker CE 安装成功docker-compose-plugin 应该已经安装了。
# 这里是额外的检查,以防万一。
if [[ "$OS_FAMILY" == "Ubuntu" ]]; then
sudo apt-get install -y docker-compose-plugin || PLUGIN_INSTALL_SUCCESS=0
elif [[ "$OS_FAMILY" == "CentOS" ]]; then
sudo yum install -y docker-compose-plugin || PLUGIN_INSTALL_SUCCESS=0
else
echo "❌ 未知操作系统,无法安装 Docker Compose 插件版。"
PLUGIN_INSTALL_SUCCESS=0
fi
# 检查插件版安装是否成功
if [[ $PLUGIN_INSTALL_SUCCESS -eq 1 ]]; then
echo "✅ Docker Compose 插件版安装成功"
else
echo "⚠️ Docker Compose 插件版安装失败,尝试使用本地二进制文件安装..."
#将文件移动至/usr/bin目录下并重命名
sudo cp ./docker-compose-linux-x86_64 /usr/bin/docker-compose
# 添加执行权限
sudo chmod +x /usr/bin/docker-compose
# 验证安装
if command -v docker-compose &> /dev/null; then
echo "✅ Docker Compose 二进制文件安装成功"
else
echo "❌ Docker Compose 二进制文件安装失败,请手动检查。"
exit 1 exit 1
fi fi
fi }
fi
# ==================== 启动服务 ====================
echo "📌 Docker 运行状态:" start_services() {
sudo systemctl status docker --no-pager || true echo ""
echo "🚀 启动 EasyAI 服务..."
echo "📌 Docker Compose 版本:" if docker compose version &>/dev/null; then
# 优先使用 docker compose 命令(新版),如果不行再尝试 docker-compose旧版或别名
if command -v docker &> /dev/null && docker compose version &> /dev/null; then
docker compose version
elif command -v docker-compose &> /dev/null; then
docker-compose -v
else
echo "❌ 无法检测 Docker Compose 版本。"
fi
echo "🎉 Docker 和 Docker Compose 已就绪!"
echo "🚀 启动EasyAI"
# 对于新版 docker-compose-plugin命令是 'docker compose'
if command -v docker &> /dev/null && docker compose version &> /dev/null; then
sudo docker compose pull && sudo docker compose up -d sudo docker compose pull && sudo docker compose up -d
else # 兼容旧版独立安装的 docker-compose else
sudo docker-compose pull && sudo docker-compose up -d sudo docker-compose pull && sudo docker-compose up -d
fi fi
echo "🎉 EasyAI 应用启动成功" echo "🎉 EasyAI 应用启动成功"
}
# ==================== 执行 HTTPS 配置 ====================
run_https_setup() {
if [ "$DEPLOY_HTTPS" = true ] && [ -n "$DEPLOY_DOMAIN" ]; then
echo ""
echo "🔒 执行 HTTPS 配置(请确保服务器已放行 80、443 端口)..."
if [ -f "./https.sh" ]; then
# https.sh 依赖 easyai-proxy.conf需使用生成的域名配置文件
export EASYAI_PROXY_CONF="${DEPLOY_DOMAIN}.conf"
bash ./https.sh
else
echo "⚠️ 未找到 https.sh请手动配置 HTTPS"
fi
fi
}
# ==================== 主流程 ====================
main() {
init_project_dir
# 检查是否已有 .env 且非强制重新配置
if [ -f .env ] && [ -z "$DEPLOY_FORCE_RECONFIG" ] && [ -z "$DEPLOY_ACCESS" ]; then
echo "📁 检测到已有 .env 配置"
read -r -p "是否重新配置部署方式?[y/N]: " reconfigure
if [[ ! "$reconfigure" =~ ^[yY] ]]; then
echo "⏭️ 使用现有配置继续..."
DEPLOY_MODE="skip"
fi
fi
if [ "$DEPLOY_MODE" != "skip" ]; then
run_deploy_questions
fi
if [ "$DEPLOY_MODE" != "skip" ]; then
setup_env_files
else
if [ ! -f .env.tools ]; then
cp .env.tools.sample .env.tools
fi
if [ ! -f .env.ASG ]; then
cp .env.ASG.sample .env.ASG
fi
if [ ! -f .env.AMS ]; then
cp .env.AMS.sample .env.AMS
fi
fi
if [ "$DEPLOY_DRY_RUN" = "1" ]; then
echo ""
echo "⚠️ dry-run 模式:跳过 Docker 安装和服务启动"
echo " 配置文件已生成,可直接运行 ./start.sh 完成部署"
else
install_docker
start_services
run_https_setup
fi
echo ""
echo "================================"
echo " 部署完成"
echo "================================"
if [ "$DEPLOY_MODE" = "ip" ] && [ -n "$DEPLOY_IP" ]; then
echo "访问地址: http://${DEPLOY_IP}:3010"
elif [ "$DEPLOY_MODE" = "domain" ] && [ -n "$DEPLOY_DOMAIN" ]; then
echo "访问地址: http://${DEPLOY_DOMAIN} (配置 Nginx 后)"
if [ "$DEPLOY_HTTPS" = true ]; then
echo "HTTPS 已启用"
fi
fi
echo ""
}
main "$@"

201
update.ps1 Normal file
View File

@ -0,0 +1,201 @@
#Requires -Version 5.1
# EasyAI Windows 更新脚本
# 拉取仓库最新代码,更新镜像并重启服务
# 用法: .\update.ps1
# 设置控制台编码为 UTF-8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
$ErrorActionPreference = "Stop"
$script:LogDir = $PSScriptRoot
if (-not $script:LogDir) { $script:LogDir = $env:TEMP }
$script:LogFile = Join-Path $script:LogDir "update.ps1.log"
function Write-Log {
param([string]$Msg)
try {
$line = "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] $Msg"
Add-Content -Path $script:LogFile -Value $line -Encoding UTF8 -ErrorAction SilentlyContinue
} catch { }
}
trap {
$errMsg = $_.Exception.Message
try {
Add-Content -Path $script:LogFile -Value "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] 错误: $errMsg" -Encoding UTF8 -ErrorAction SilentlyContinue
} catch { }
Write-Host ""
Write-Host "发生错误: $errMsg" -ForegroundColor Red
if ($env:CI -ne "true") { Read-Host "按 Enter 键退出" }
exit 1
}
function Wait-ForExit {
if ($env:CI -eq "true") { return }
Write-Host ""
Read-Host "按 Enter 键退出"
}
function Write-Step { param($Msg) Write-Host $Msg }
function Write-Ok { param($Msg) Write-Host "$Msg" -ForegroundColor Green }
function Write-Err { param($Msg) Write-Host "$Msg" -ForegroundColor Red; throw $Msg }
function Write-Warn { param($Msg) Write-Host "⚠️ $Msg" -ForegroundColor Yellow }
# -h/--help
if ($args -contains "-h" -or $args -contains "--help") {
Write-Host "用法: .\update.ps1"
Write-Host ""
Write-Host "脚本将提示选择更新方式,默认拉取仓库并更新镜像。"
exit 0
}
# 进入项目目录
$scriptDir = $PSScriptRoot
if (-not $scriptDir) { Write-Err "无法获取脚本所在目录" }
$composePath = Join-Path $scriptDir "docker-compose.yml"
if (-not (Test-Path $composePath)) { Write-Err "未找到 docker-compose.yml请在 easyai 目录下运行 update.ps1" }
Set-Location $scriptDir
Write-Step "📁 项目目录: $scriptDir"
# ==================== 命令行内选择 ====================
Write-Host ""
Write-Host "请选择更新方式:"
Write-Host " [1] 更新并拉取仓库git pull+ 更新镜像并重启(默认)"
Write-Host " [2] 仅更新镜像并重启(跳过 git pull"
$choice = Read-Host "请选择 [1/2回车默认 1]"
if ([string]::IsNullOrWhiteSpace($choice)) { $choice = "1" }
$skipRepoUpdate = $false
switch ($choice) {
"2" { $skipRepoUpdate = $true }
"1" { }
default {
Write-Warn "无效选择,将使用默认:更新并拉取仓库"
$skipRepoUpdate = $false
}
}
# ==================== 拉取仓库 ====================
if (-not $skipRepoUpdate) {
Write-Host ""
Write-Host "==========================="
Write-Host "📥 拉取仓库最新代码"
Write-Host "==========================="
if (-not (Test-Path ".git")) {
Write-Err "当前目录不是 Git 仓库,请使用 git clone 克隆项目后使用 update.ps1"
}
Write-Step "📥 正在执行 git pull..."
try {
$output = git pull 2>&1
if ($LASTEXITCODE -ne 0) { throw "git pull 返回 $LASTEXITCODE" }
Write-Ok "仓库已更新到最新版本"
} catch {
Write-Err "git pull 失败,请检查网络或远程仓库配置"
}
# 确保环境配置文件存在
Write-Host ""
Write-Step "📝 检查环境配置文件..."
if (-not (Test-Path ".env") -and (Test-Path ".env.sample")) {
Copy-Item ".env.sample" ".env"
Write-Ok ".env"
}
if (-not (Test-Path ".env.tools") -and (Test-Path ".env.tools.sample")) {
Copy-Item ".env.tools.sample" ".env.tools"
Write-Ok ".env.tools"
}
if (-not (Test-Path ".env.ASG") -and (Test-Path ".env.ASG.sample")) {
Copy-Item ".env.ASG.sample" ".env.ASG"
Write-Ok ".env.ASG"
}
if (-not (Test-Path ".env.AMS") -and (Test-Path ".env.AMS.sample")) {
Copy-Item ".env.AMS.sample" ".env.AMS"
Write-Ok ".env.AMS"
}
Write-Host ""
} else {
Write-Host ""
Write-Step "⏭️ 跳过仓库更新,仅更新镜像并重启"
Write-Host ""
}
# ==================== Docker 检查 ====================
function Test-DockerInstalled {
$docker = Get-Command docker -ErrorAction SilentlyContinue
if (-not $docker) { return $false }
try { $null = & docker --version 2>&1; return $true } catch { return $false }
}
function Test-DockerRunning {
param([int]$TimeoutSeconds = 10)
try {
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = "docker"; $psi.Arguments = "info"
$psi.RedirectStandardOutput = $true; $psi.RedirectStandardError = $true
$psi.UseShellExecute = $false; $psi.CreateNoWindow = $true
$p = [System.Diagnostics.Process]::Start($psi)
$exited = $p.WaitForExit($TimeoutSeconds * 1000)
if (-not $exited) { try { $p.Kill() } catch { }; return $false }
return ($p.ExitCode -eq 0)
} catch { return $false }
}
function Ensure-DockerRunning {
if (-not (Test-DockerInstalled)) { return $false }
if (Test-DockerRunning) {
Write-Ok "Docker 引擎已运行"
$v = docker --version 2>$null; if ($v) { Write-Host " $v" }
return $true
}
Write-Warn "Docker 未运行,请手动启动 Docker Desktop 后重新执行"
return $false
}
Write-Host "==========================="
Write-Host "🚀 检查 Docker"
Write-Host "==========================="
Write-Host ""
if (-not (Test-DockerInstalled)) {
Write-Err "未检测到 Docker请先运行 start.ps1 完成首次部署"
}
if (-not (Ensure-DockerRunning)) {
Write-Host ""
Write-Host "请启动 Docker Desktop确认其完全就绪后再重新运行 update.ps1"
Wait-ForExit
exit 1
}
# 检测 docker compose
$hasComposeV2 = $false
try { $null = docker compose version 2>&1; $hasComposeV2 = $true } catch { }
# ==================== 更新并启动 ====================
Write-Host ""
Write-Step "🚀 重新启动 EasyAI..."
if ($hasComposeV2) {
docker compose pull
if ($LASTEXITCODE -ne 0) { Write-Err "docker compose pull 失败" }
docker compose up -d
if ($LASTEXITCODE -ne 0) { Write-Err "docker compose up 失败" }
} else {
docker-compose pull
if ($LASTEXITCODE -ne 0) { Write-Err "docker-compose pull 失败" }
docker-compose up -d
if ($LASTEXITCODE -ne 0) { Write-Err "docker-compose up 失败" }
}
Write-Host ""
Write-Host "================================"
Write-Host " 更新完成"
Write-Host "================================"
Write-Host "🎉 EasyAI 应用更新成功"
Write-Host "访问地址: http://127.0.0.1:3010"
Write-Host ""
Write-Log "=== 更新完成 ==="
Wait-ForExit

108
update.sh
View File

@ -2,75 +2,65 @@
set -e # 发生错误时终止脚本执行 set -e # 发生错误时终止脚本执行
# 参数解析 # 仅支持 -h/--help 快速查看
SKIP_COMPOSE_UPDATE=false if [[ "${1:-}" =~ ^(-h|--help)$ ]]; then
echo "用法: $0"
# 解析命令行参数
while [[ $# -gt 0 ]]; do
case $1 in
--skip-compose-update|-s)
SKIP_COMPOSE_UPDATE=true
shift
;;
--help|-h)
echo "用法: $0 [选项]"
echo ""
echo "选项:"
echo " -s, --skip-compose-update 跳过 docker-compose.yml 的更新"
echo " -h, --help 显示此帮助信息"
echo "" echo ""
echo "脚本将提示选择更新方式,默认拉取仓库并更新镜像。"
exit 0 exit 0
;; fi
*)
echo "❌ 未知参数: $1" # 进入脚本所在目录(项目根目录)
echo "使用 --help 或 -h 查看帮助信息" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
exit 1 cd "$SCRIPT_DIR"
;;
# 命令行内选择更新方式(默认:更新并拉取仓库)
echo ""
echo "请选择更新方式:"
echo " [1] 更新并拉取仓库git pull+ 更新镜像并重启(默认)"
echo " [2] 仅更新镜像并重启(跳过 git pull"
read -r -p "请选择 [1/2回车默认 1]: " choice
choice="${choice:-1}"
SKIP_REPO_UPDATE=false
case "$choice" in
2) SKIP_REPO_UPDATE=true ;;
1) ;;
*) echo "❌ 无效选择,将使用默认:更新并拉取仓库"; SKIP_REPO_UPDATE=false ;;
esac esac
done
# 更新 docker-compose.yml 文件 # 拉取整个仓库更新
if [ "$SKIP_COMPOSE_UPDATE" = false ]; then if [ "$SKIP_REPO_UPDATE" = false ]; then
echo "" echo ""
echo "===========================" echo "==========================="
echo "📄 检查并更新 docker-compose.yml" echo "📥 拉取仓库最新代码"
echo "===========================" echo "==========================="
COMPOSE_FILE="docker-compose.yml" if [ ! -d .git ]; then
COMPOSE_URL="https://git.51easyai.com/wangbo/easyai/raw/main/docker-compose.yml" echo "❌ 当前目录不是 Git 仓库,无法执行 git pull"
TEMP_FILE=$(mktemp) echo " 请使用 git clone 克隆项目后即可使用 update.sh 更新"
echo " 克隆命令: git clone https://git.51easyai.com/wangbo/easyai && cd easyai"
exit 1
fi
# 检查本地文件是否存在 echo "📥 正在执行 git pull..."
if [ ! -f "$COMPOSE_FILE" ]; then if git pull; then
echo "⚠️ 本地 $COMPOSE_FILE 不存在,直接下载最新版本..." echo "✅ 仓库已更新到最新版本"
curl -fsSL "$COMPOSE_URL" -o "$COMPOSE_FILE"
echo "$COMPOSE_FILE 已下载"
else else
echo "📥 正在下载远程 $COMPOSE_FILE..." echo "❌ git pull 失败,请检查网络或远程仓库配置"
if curl -fsSL "$COMPOSE_URL" -o "$TEMP_FILE"; then exit 1
# 比较本地文件和远程文件的内容
if cmp -s "$COMPOSE_FILE" "$TEMP_FILE"; then
echo "✅ 本地 $COMPOSE_FILE 已是最新版本,无需更新"
rm -f "$TEMP_FILE"
else
echo "🔄 检测到新版本,正在更新..."
# 备份原文件
BACKUP_FILE="${COMPOSE_FILE}.bak"
cp "$COMPOSE_FILE" "$BACKUP_FILE"
echo "💾 原文件已备份为 $BACKUP_FILE"
# 替换为新文件
mv "$TEMP_FILE" "$COMPOSE_FILE"
echo "$COMPOSE_FILE 已更新到最新版本"
fi
else
echo "❌ 无法下载远程文件,跳过更新步骤"
rm -f "$TEMP_FILE"
fi
fi fi
# 确保环境配置文件存在(从 .sample 生成,不覆盖已有文件)
echo ""
echo "📝 检查环境配置文件..."
[ ! -f .env ] && [ -f .env.sample ] && cp .env.sample .env && echo " ✓ .env"
[ ! -f .env.tools ] && [ -f .env.tools.sample ] && cp .env.tools.sample .env.tools && echo " ✓ .env.tools"
[ ! -f .env.ASG ] && [ -f .env.ASG.sample ] && cp .env.ASG.sample .env.ASG && echo " ✓ .env.ASG"
[ ! -f .env.AMS ] && [ -f .env.AMS.sample ] && cp .env.AMS.sample .env.AMS && echo " ✓ .env.AMS"
echo "" echo ""
else else
echo "⏭️ 跳过 docker-compose.yml 更新(已使用 --skip-compose-update 参数)" echo "⏭️ 跳过仓库更新,仅更新镜像并重启"
echo "" echo ""
fi fi
@ -112,9 +102,11 @@ elif command -v docker-compose &> /dev/null; then
echo "✅ 检测到 Docker Compose (旧版本: docker-compose)" echo "✅ 检测到 Docker Compose (旧版本: docker-compose)"
else else
echo "⚙️ 安装 Docker Compose..." echo "⚙️ 安装 Docker Compose..."
sudo mv ./docker-compose-linux-x86_64 /usr/bin/docker-compose COMPOSE_BIN_URL="https://static.51easyai.com/docker-compose-linux-x86_64"
#设置权限 TMP_COMPOSE_BIN="/tmp/docker-compose-linux-x86_64"
chmod +x /usr/bin/docker-compose curl -fL "$COMPOSE_BIN_URL" -o "$TMP_COMPOSE_BIN"
sudo install -m 0755 "$TMP_COMPOSE_BIN" /usr/bin/docker-compose
rm -f "$TMP_COMPOSE_BIN"
DOCKER_COMPOSE_CMD="docker-compose" DOCKER_COMPOSE_CMD="docker-compose"
echo "✅ Docker Compose 安装完成" echo "✅ Docker Compose 安装完成"
fi fi