refactor(deploy,update): drop standalone edition and add sandbox upgrade confirmation

- Remove standalone Docker edition (Dockerfile.standalone, docker-compose.standalone.yml, release.yml standalone jobs, and dual-edition env/script branches).
- Remove deploy_edition field from /api/update/check and dual-edition UI/i18n branching in UpdateCard.
- Replace window.confirm on upgrade with AlertDialog informing users of the irreversible Standalone -> Sandbox security upgrade.
This commit is contained in:
ji ruo committed 2026-12-04 15:14:06 +08:00
1 parent 8efd26b8b7
commit f5b446e3bf
15 files changed
+330 -944

No files matched your search

+1 -6
View File
@@ -1,13 +1,8 @@
# Docker 部署配置(复制为 .env)
# 部署形态:sandbox(沙箱隔离版,docker-compose.yml)或 standalone(单容器版,docker-compose.standalone.yml)
ARTEX_DEPLOY_EDITION=sandbox
# 本仓库发布的 Docker Hub 镜像地址;参见 README 的部署说明。
ARTEX_IMAGE=ruoji6/artex
ARTEX_TAG=latest
# 单容器版(docker-compose.standalone.yml)使用的镜像标签:
# 默认 standalone(新版全功能镜像);如需回退拆分前历史版本(如 v0.3.32)可直接填 v0.3.32
ARTEX_STANDALONE_TAG=standalone
# 沙箱隔离版透明代理网关镜像
# 全流量透明代理网关镜像
ARTEX_GATEWAY_IMAGE=ruoji6/artex-gateway
POSTGRES_USER=artex
POSTGRES_PASSWORD=change-me-please
+6 -45
View File
@@ -257,7 +257,7 @@ jobs:
jq -e --arg version "${RELEASE_TAG#v}" '.version == $version' /tmp/artex-version.json
curl --fail http://127.0.0.1:8787/ > /tmp/artex-index.html
grep -qi '<!doctype html' /tmp/artex-index.html
- name: Push tested control-plane architecture image (sandbox edition)
- name: Push tested control-plane architecture image
uses: docker/build-push-action@v6
with:
context: .
@@ -271,38 +271,6 @@ jobs:
org.opencontainers.image.revision=${{ needs.prepare.outputs.commit }}
org.opencontainers.image.licenses=AGPL-3.0
cache-from: type=gha,scope=docker-${{ matrix.arch }}
- name: Build standalone all-in-one image for native smoke test
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.standalone
platforms: linux/${{ matrix.arch }}
load: true
tags: artex-standalone:smoke
cache-from: type=gha,scope=docker-standalone-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=docker-standalone-${{ matrix.arch }}
- name: Smoke test standalone image tools and startup
run: |
docker run --rm --entrypoint sh artex-standalone:smoke -c '
/app/artex -h >/dev/null
python3 --version
nmap --version | head -n 1
playwright-mcp --version
'
- name: Push tested standalone architecture image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.standalone
platforms: linux/${{ matrix.arch }}
push: true
tags: ${{ vars.ARTEX_DOCKER_IMAGE }}:${{ needs.prepare.outputs.tag }}-standalone-${{ matrix.arch }}
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ needs.prepare.outputs.tag }}
org.opencontainers.image.revision=${{ needs.prepare.outputs.commit }}
org.opencontainers.image.licenses=AGPL-3.0
cache-from: type=gha,scope=docker-standalone-${{ matrix.arch }}
- name: Build and push transparent gateway architecture image
uses: docker/build-push-action@v6
with:
@@ -334,7 +302,7 @@ jobs:
cache-from: type=gha,scope=docker-sandbox-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=docker-sandbox-${{ matrix.arch }}
# ⑤ 只有两种架构都通过启动验证,才发布双形态(沙箱隔离版 + 单容器版)多架构镜像。
# ⑤ 只有两种架构都通过启动验证,才发布多架构镜像(控制面 + 透明网关 + 沙箱执行环境)。
docker-publish:
needs: [prepare, docker]
runs-on: ubuntu-24.04
@@ -344,31 +312,24 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Publish multi-platform images (sandbox + standalone + gateway + sandbox-worker)
- name: Publish multi-platform images (control-plane + gateway + sandbox-worker)
env:
IMAGE: ${{ vars.ARTEX_DOCKER_IMAGE }}
RELEASE_TAG: ${{ needs.prepare.outputs.tag }}
run: |
# 1. Control-plane slim image (sandbox edition)
# 1. Control-plane slim image
docker buildx imagetools create \
--tag "$IMAGE:$RELEASE_TAG" --tag "$IMAGE:latest" \
"$IMAGE:$RELEASE_TAG-amd64" "$IMAGE:$RELEASE_TAG-arm64"
docker buildx imagetools inspect "$IMAGE:$RELEASE_TAG" --raw > /tmp/artex-manifest.json
jq -e '[.manifests[].platform | select(.os == "linux") | .architecture] | index("amd64") != null and index("arm64") != null' /tmp/artex-manifest.json
# 2. All-in-one standalone image (legacy single-container edition)
docker buildx imagetools create \
--tag "$IMAGE:$RELEASE_TAG-standalone" --tag "$IMAGE:standalone" \
"$IMAGE:$RELEASE_TAG-standalone-amd64" "$IMAGE:$RELEASE_TAG-standalone-arm64"
docker buildx imagetools inspect "$IMAGE:$RELEASE_TAG-standalone" --raw > /tmp/artex-standalone-manifest.json
jq -e '[.manifests[].platform | select(.os == "linux") | .architecture] | index("amd64") != null and index("arm64") != null' /tmp/artex-standalone-manifest.json
# 3. Transparent gateway image
# 2. Transparent gateway image
docker buildx imagetools create \
--tag "$IMAGE-gateway:$RELEASE_TAG" --tag "$IMAGE-gateway:latest" \
"$IMAGE-gateway:$RELEASE_TAG-amd64" "$IMAGE-gateway:$RELEASE_TAG-arm64"
# 4. Sandbox worker image
# 3. Sandbox worker image
docker buildx imagetools create \
--tag "$IMAGE-sandbox:$RELEASE_TAG" --tag "$IMAGE-sandbox:latest" \
"$IMAGE-sandbox:$RELEASE_TAG-amd64" "$IMAGE-sandbox:$RELEASE_TAG-arm64"
-61
View File
@@ -1,61 +0,0 @@
# syntax=docker/dockerfile:1
#
# 单容器全功能镜像(Standalone 版,兼容上一版本单容器部署形态):
# 在一个容器内同时包含 ARTEX 主程序、Python 3.12、Node 22、Playwright/Chromium
# 与常用渗透工具链(nmap / ripgrep / curl / dnsutils / netcat 等),以
# ARTEX_SANDBOX_MODE=local 运行,无需 docker-socket-proxy、/dev/net/tun 或
# CAP_NET_ADMIN 透明网关容器。
#
# 本地手动构建镜像时,先自行准备二进制:
# cd web && npm run build:static && cd ..
# rm -rf server/webui/dist && cp -r web/out server/webui/dist
# CGO_ENABLED=0 GOARCH=amd64 go build -tags embedui -o dist/amd64/artex ./cmd/artex
# docker build -f Dockerfile.standalone -t ruoji6/artex:standalone .
FROM python:3.12-slim-bookworm
ARG TARGETARCH
ARG APT_MIRROR=""
ARG NPM_REGISTRY=""
ARG PIP_INDEX_URL=""
ARG PLAYWRIGHT_DOWNLOAD_HOST=""
ENV TZ=Asia/Shanghai \
DEBIAN_FRONTEND=noninteractive \
PLAYWRIGHT_DOWNLOAD_HOST=${PLAYWRIGHT_DOWNLOAD_HOST} \
ARTEX_SANDBOX_MODE=local
RUN if [ -n "$APT_MIRROR" ]; then \
sed -i "s|deb.debian.org|${APT_MIRROR}|g; s|security.debian.org|${APT_MIRROR}|g" /etc/apt/sources.list.d/debian.sources 2>/dev/null || true; \
fi \
&& apt-get update && apt-get install -y --no-install-recommends \
ca-certificates ripgrep curl wget vim git jq unzip \
tzdata procps \
dnsutils iputils-ping netcat-openbsd inetutils-telnet whois nmap \
&& curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
&& apt-get install -y --no-install-recommends nodejs \
&& rm -rf /var/lib/apt/lists/*
# 预装 Playwright MCP 与 CLI(全局),运行时优先直接调用 playwright-mcp,无需 npx 联网下载。
RUN npm install -g ${NPM_REGISTRY:+--registry="$NPM_REGISTRY"} @playwright/mcp@latest @playwright/cli@latest \
&& playwright-mcp --version \
&& playwright-cli --help \
&& playwright-mcp install-browser --with-deps chromium \
&& playwright-cli install-browser chromium \
&& rm -rf /var/lib/apt/lists/*
RUN if [ -n "$PIP_INDEX_URL" ]; then \
pip install --no-cache-dir -i "$PIP_INDEX_URL" requests httpx beautifulsoup4 pyyaml; \
else \
pip install --no-cache-dir requests httpx beautifulsoup4 pyyaml; \
fi
WORKDIR /app
# 预编译好的对应架构二进制(dist/amd64/artex 或 dist/arm64/artex)
COPY dist/${TARGETARCH}/artex /app/artex
# 守护启动脚本:进程退出后按退出码决定是否重新拉起,页面一键更新与回滚靠它完成换装。
COPY start.sh /app/start.sh
RUN chmod +x /app/artex /app/start.sh
COPY skills/ /app/skills/
# data/(SQLite + jwt.key)持久化点
VOLUME ["/app/data"]
EXPOSE 8787 8788
ENTRYPOINT ["/app/start.sh"]
CMD ["-addr", ":8787", "-proxy", ":8788"]
+14 -40
View File
@@ -124,23 +124,20 @@ cd ARTEX
./install.sh
```
脚本提供两种 Docker 部署形态与本地编译模式:
脚本提供 Docker 部署与本地编译两种方式:
- **① Docker 沙箱隔离版(推荐,当前完整版)**:对应 `docker-compose.yml`,包含 `postgres` + `docker-socket-proxy` + `artex` + `artex-gateway`(TUN/netstack 透明网关)+ 动态拉起的 `artex-sandbox` 非 root 沙箱容器。脚本会自动填写 `ARTEX_HOST_DATA_DIR`、`ARTEX_GATEWAY_TOKEN` 与随机 `POSTGRES_PASSWORD`。
- **② Docker 单容器版(兼容上一版本)**:对应 `docker-compose.standalone.yml`,仅启动 `postgres` + 全功能 `artex`(内置 Python / Node / Playwright / nmap 等工具链,`ARTEX_SANDBOX_MODE=local`),无需 `docker-socket-proxy`、`/dev/net/tun` 或 `CAP_NET_ADMIN`,适合老用户延续、macOS Docker Desktop 或受限环境。
- **③ 本地运行**:选数据库(连已有 / 用 Docker 起一个)→ 生成 `config.json` → `go` 编译内嵌单二进制 → 启动。
- **① Docker 部署(推荐)**:对应 `docker-compose.yml`,包含 `postgres` + `docker-socket-proxy` + `artex` + `artex-gateway`(TUN/netstack 透明网关)+ 动态拉起的 `artex-sandbox` 非 root 沙箱容器。脚本会自动填写 `ARTEX_HOST_DATA_DIR`、`ARTEX_GATEWAY_TOKEN` 与随机 `POSTGRES_PASSWORD`。
- **② 本地运行**:选数据库(连已有 / 用 Docker 起一个)→ 生成 `config.json` → `go` 编译内嵌单二进制 → 启动。
也支持非交互参数直接安装:
```bash
./install.sh --edition sandbox --yes # 沙箱隔离版
./install.sh --edition standalone --yes # 单容器版
./install.sh --docker --yes
```
装好后打开 **http://localhost:8787**(首次进入 `/setup` 设置管理员密码)。
### 方式二:Docker Compose(手动)
**沙箱隔离版(`docker-compose.yml`)**:
```bash
git clone https://github.com/RuoJi6/ARTEX.git
cd ARTEX
@@ -149,16 +146,7 @@ docker compose up -d # 启动 postgres + docker-socket-proxy + artex +
# → http://localhost:8787
```
**单容器版(`docker-compose.standalone.yml`,兼容上一版本)**:
```bash
cp .env.example .env # 填 POSTGRES_PASSWORD,设置 ARTEX_DEPLOY_EDITION=standalone
docker compose -f docker-compose.standalone.yml up -d
# → http://localhost:8787
```
两个版本共享同一个 `pgdata` 数据卷、`artex-internal` 网络、`./data` 与 `./skills` 目录。镜像均支持 `linux/amd64` 与 `linux/arm64`:
- 沙箱隔离版:`ruoji6/artex:<tag>` + `ruoji6/artex-gateway:<tag>` + `ruoji6/artex-sandbox:<tag>`(默认 `latest`)
- 单容器版:`ruoji6/artex:<tag>-standalone`(默认 `ruoji6/artex:standalone`;若需固定或回退至拆分前历史版本如 `v0.3.32`,直接设 `ARTEX_STANDALONE_TAG=v0.3.32`)
镜像均支持 `linux/amd64` 与 `linux/arm64`:`ruoji6/artex:<tag>` + `ruoji6/artex-gateway:<tag>` + `ruoji6/artex-sandbox:<tag>`(默认 `latest`)。
#### 内存与进程保护
- **Compose 容器**:`artex` 默认最多使用 **4 GiB 内存、512 个进程/线程**,并禁用容器 swap;PostgreSQL 不受这两个上限限制。通过 `.env` 的 `ARTEX_MEMORY_LIMIT`、`ARTEX_PIDS_LIMIT` 调整。小内存 VPS 应调低内存上限,给宿主机、数据库和其他服务留出余量。更新 Compose 或 `.env` 后,运行 `docker compose up -d artex` 重建容器;只热更新程序不会改变容器限制。
@@ -298,52 +286,38 @@ curl --fail http://127.0.0.1:8787/api/health
这会保留现有数据库、data 和 skills 挂载。登录系统配置页检查更新源与版本。容器内替换的程序仍属于容器可写层,删除或重建容器会丢失替换结果;需要重建时应使用包含本仓库程序的镜像。程序回滚不回退数据库迁移,升级前请备份数据库和 data。
### 方式二:一键升级、双版本迁移与回滚脚本(推荐)
### 方式二:一键升级与回滚脚本(推荐)
```bash
cd ARTEX
./update.sh
```
脚本会自动识别当前部署形态(单容器版 / 沙箱隔离版),并在**每次升级或切换形态前自动生成回滚快照**(保存在 `.artex-deploy/snapshots/<id>/`,包含 `.env`、当前镜像精确 ID 的本地回滚标签 `artex-rollback/*` 及 PostgreSQL 逻辑备份 `postgres.sql.gz`):
脚本会在**每次升级前自动生成回滚快照**(保存在 `.artex-deploy/snapshots/<id>/`,包含 `.env`、当前镜像精确 ID 的本地回滚标签 `artex-rollback/*` 及 PostgreSQL 逻辑备份 `postgres.sql.gz`):
- **继续升级当前形态**(保留单容器版或升级沙箱隔离版):
- **升级 Docker 部署**:
```bash
./update.sh --upgrade # 保持当前形态升级
./update.sh --upgrade --tag v0.3.33 # 指定版本升级(单容器版自动映射为 v0.3.33-standalone)
./update.sh --upgrade # 升级到最新镜像
./update.sh --upgrade --tag v0.3.33 # 指定版本升级
```
- **从上一版本(单容器)迁移至沙箱隔离版**:
```bash
./update.sh --migrate-sandbox
```
保留原 `pgdata` 数据卷、`./data`、`./skills`,自动补齐 `.env` 中的 `ARTEX_HOST_DATA_DIR` / `ARTEX_GATEWAY_TOKEN`,并安全校准既有 `./data/tasks`、`./data/sessions` 与 `./data/ephemeral` 的非 root 写权限(跳过符号链接)。若新版健康检查未通过,自动回滚回迁移前快照。
- **从沙箱隔离版切回单容器版**:
```bash
./update.sh --switch-standalone # 切回最新单容器版
./update.sh --switch-standalone --tag v0.3.32 # 切回拆分前历史版本
```
自动停止运行中的沙箱容器并优雅停止 `artex-gateway`(清理 TUN 与 iptables 规则),随后以 `--remove-orphans` 切回两容器拓扑。
保留原 `pgdata` 数据卷、`./data`、`./skills`,自动补齐 `.env` 中的 `ARTEX_HOST_DATA_DIR` / `ARTEX_GATEWAY_TOKEN`,并安全校准既有 `./data/tasks`、`./data/sessions` 与 `./data/ephemeral` 的非 root 写权限(跳过符号链接)。若新版健康检查未通过,自动回滚回升级前快照。
- **回滚到历史快照**:
```bash
./update.sh --list-snapshots # 查看所有可用快照
./update.sh --rollback # 回滚到最近一次快照(支持跨形态无损回滚)
./update.sh --rollback # 回滚到最近一次快照
./update.sh --rollback <SNAP_ID> # 回滚到指定快照
./update.sh --rollback <SNAP_ID> --restore-db # 同时用快照中的 postgres.sql.gz 恢复数据库
```
> 回滚优先使用本地固定的精确镜像 ID(`artex-rollback/*`),即便 `:latest` 已被覆盖或宿主机离线也能准确恢复。单容器版与当前沙箱隔离版的 PostgreSQL/SQLite 结构前向与后向兼容,常规回滚无需覆盖数据库。
> 注意:沙箱隔离版下页面内「一键更新 / 回滚」仅作用于 `artex` 主控二进制,不会同步切换 `artex-gateway` 与 `artex-sandbox` 镜像,整套升级与回滚请使用 `./update.sh`。
> 回滚优先使用本地固定的精确镜像 ID(`artex-rollback/*`),即便 `:latest` 已被覆盖或宿主机离线也能准确恢复。数据库结构前向与后向兼容,常规回滚无需覆盖数据库。
> 注意:Docker 下页面内「一键更新 / 回滚」仅作用于 `artex` 主控二进制,不会同步切换 `artex-gateway` 与 `artex-sandbox` 镜像,整套升级与回滚请使用 `./update.sh`。
### 方式三:Docker Compose(手动)
```bash
cd ARTEX
git pull # 更新 compose / 脚本(可选)
# 沙箱隔离版:
docker compose pull && docker pull "${ARTEX_SANDBOX_IMAGE:-ruoji6/artex-sandbox:latest}"
docker compose up -d --remove-orphans
# 单容器版:
docker compose -f docker-compose.standalone.yml pull artex
docker compose -f docker-compose.standalone.yml up -d --remove-orphans
```
### 方式四:预编译二进制(Releases)
-75
View File
@@ -1,75 +0,0 @@
# 单容器版(Standalone,兼容上一版本部署形态):
# 仅启动 postgres + artex 两个容器,工具链与 Playwright 内置在 artex 镜像内,
# 无需 docker-socket-proxy、/dev/net/tun 或 CAP_NET_ADMIN。
#
# 与沙箱隔离版(docker-compose.yml)共享同一个 pgdata 数据卷、artex-internal 网络、
# ./data 与 ./skills 目录,可随时通过 ./update.sh 迁移到沙箱隔离版或无损回滚。
#
# 手动启动:
# docker compose -f docker-compose.standalone.yml up -d
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: ${POSTGRES_USER:-artex}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?请在 .env 设置 POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB:-artex}
volumes:
- pgdata:/var/lib/postgresql/data
networks:
- artex-internal
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-artex} -d ${POSTGRES_DB:-artex}"]
interval: 5s
timeout: 3s
retries: 10
restart: unless-stopped
artex:
# 默认使用全功能 standalone 标签(如 ruoji6/artex:standalone 或 v0.3.33-standalone);
# 若需回退至拆分前的历史版本(如 v0.3.32),直接将 ARTEX_STANDALONE_TAG=v0.3.32 即可。
image: ${ARTEX_STANDALONE_IMAGE:-${ARTEX_IMAGE:-ruoji6/artex}}:${ARTEX_STANDALONE_TAG:-standalone}
depends_on:
postgres:
condition: service_healthy
environment:
TZ: Asia/Shanghai
ARTEX_PG_DSN: postgres://${POSTGRES_USER:-artex}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-artex}?sslmode=disable
ARTEX_SANDBOX_MODE: local
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
OPENAI_API_KEY: ${OPENAI_API_KEY:-}
GEMINI_API_KEY: ${GEMINI_API_KEY:-}
ARTEX_LLM_PROVIDER: ${ARTEX_LLM_PROVIDER:-}
ARTEX_LLM_MODEL: ${ARTEX_LLM_MODEL:-}
ARTEX_LLM_BASE_URL: ${ARTEX_LLM_BASE_URL:-}
ARTEX_LLM_PROXY: ${ARTEX_LLM_PROXY:-}
ARTEX_HTTP_USER_AGENT: ${ARTEX_HTTP_USER_AGENT:-}
ARTEX_TOOL_MEMORY_LIMIT_MB: ${ARTEX_TOOL_MEMORY_LIMIT_MB:-}
ARTEX_TOOL_TIMEOUT_S: ${ARTEX_TOOL_TIMEOUT_S:-}
ARTEX_TOOL_PIDS_LIMIT: ${ARTEX_TOOL_PIDS_LIMIT:-}
ARTEX_PROXY_BLOCK_PRIVATE: ${ARTEX_PROXY_BLOCK_PRIVATE:-false}
ARTEX_PROXY_PROTECT_IPS: ${ARTEX_PROXY_PROTECT_IPS:-}
ports:
- "8787:8787"
- "127.0.0.1:8788:8788"
volumes:
# 把数据目录(含 jwt.key、SQLite 等)绑定到项目根目录的 data/,
# 方便在宿主机直接查看/备份,容器重建也不丢。
- ./data:/app/data
# 把项目根目录的 skills 挂进容器(覆盖镜像内置的 /app/skills);
# 改 skill 无需重建镜像,容器读的就是宿主机这份。
- ./skills:/app/skills
networks:
- artex-internal
# 单容器模式下工具链与 Playwright 都在本容器内运行,默认沿用 4 GiB 内存上限。
mem_limit: ${ARTEX_MEMORY_LIMIT:-4g}
memswap_limit: ${ARTEX_MEMORY_LIMIT:-4g}
pids_limit: ${ARTEX_PIDS_LIMIT:-512}
restart: unless-stopped
networks:
artex-internal:
driver: bridge
volumes:
pgdata:
+29 -44
View File
@@ -1,12 +1,11 @@
#!/usr/bin/env bash
# ARTEX 安装脚本:
# 1) Docker 沙箱隔离版(推荐,当前完整版:独立沙箱容器 + 全流量透明网关 + 出口代理控制)
# 2) Docker 单容器版(兼容上一版本:仅 postgres + artex,无需 docker-socket-proxy / /dev/net/tun)
# 3) 本地编译运行(Go 编译)
# 1) Docker 部署(推荐:独立沙箱容器 + 全流量透明网关 + 出口代理控制)
# 2) 本地编译运行(Go 编译)
#
# 非交互用法示例:
# ./install.sh --edition sandbox --yes
# ./install.sh --edition standalone --tag standalone --yes
# ./install.sh --docker --yes
# ./install.sh --docker --tag v0.3.33 --yes
# ./install.sh --local
set -euo pipefail
cd "$(cd "$(dirname "$0")" && pwd)"
@@ -34,24 +33,17 @@ ensure_docker(){
esac
}
# ── ① Docker 安装(支持 sandbox / standalone 双形态)───────────────
# ── ① Docker 部署 ───────────────────────────────────────────────
install_docker(){
local edition="${1:-sandbox}" tag="${2:-}"
local tag="${1:-}"
ensure_docker
if [ "$edition" = "sandbox" ]; then
preflight_sandbox
fi
preflight_docker
umask 077
local is_fresh=0
[ -f .env ] || is_fresh=1
if [ "$edition" = "sandbox" ]; then
prepare_env_for_sandbox "$tag" .env
else
prepare_env_for_standalone "$tag" .env
fi
prepare_env_for_docker "$tag" .env
if [ "$is_fresh" -eq 1 ] && [ "${ARTEX_NONINTERACTIVE:-0}" != "1" ]; then
local key
@@ -59,16 +51,14 @@ install_docker(){
[ -n "$key" ] && env_set ANTHROPIC_API_KEY "$key" .env
fi
local compose_file
compose_file="$(compose_file_for_edition "$edition")"
pull_edition_images "$edition"
info "启动 $(edition_label "$edition")(${compose_file})…"
docker compose -f "$compose_file" up -d --remove-orphans
wait_for_health "$compose_file" || warn "服务仍在启动中,请执行 docker compose -f ${compose_file} logs -f artex 观察"
pull_docker_images
info "启动服务(${COMPOSE_FILE})…"
docker compose -f "$COMPOSE_FILE" up -d --remove-orphans
wait_for_health "$COMPOSE_FILE" || warn "服务仍在启动中,请执行 docker compose -f ${COMPOSE_FILE} logs -f artex 观察"
ok "启动完成($(edition_label "$edition"))→ http://localhost:8787"
info "查看日志:docker compose -f ${compose_file} logs -f artex"
info "后续升级 / 切换版本形态 / 回滚:./update.sh"
ok "启动完成 → http://localhost:8787"
info "查看日志:docker compose -f ${COMPOSE_FILE} logs -f artex"
info "后续升级 / 回滚:./update.sh"
}
# ── ② 本地编译运行 ──────────────────────────────
@@ -131,22 +121,22 @@ usage(){
用法: ./install.sh [选项]
选项:
--edition sandbox|standalone 直接指定 Docker 部署形态(sandbox=沙箱隔离版,standalone=单容器版)
--tag <TAG> 指定镜像版本 tag(如 v0.3.33 / v0.3.32 / latest / standalone)
--local 使用本地 Go 编译运行
--skip-pull 跳过镜像拉取(适用于本地已构建镜像)
-y, --yes 非交互模式(自动填充默认值)
-h, --help 显示本帮助
--docker 直接执行 Docker 部署(docker-compose.yml)
--tag <TAG> 指定镜像版本 tag(如 v0.3.33 / latest)
--local 使用本地 Go 编译运行
--skip-pull 跳过镜像拉取(适用于本地已构建镜像)
-y, --yes 非交互模式(自动填充默认值)
-h, --help 显示本帮助
USAGE
}
OPT_EDITION=""
OPT_DOCKER=0
OPT_TAG=""
OPT_LOCAL=0
while [ "$#" -gt 0 ]; do
case "$1" in
--edition) shift; [ "$#" -gt 0 ] || die "--edition 需要参数"; OPT_EDITION="$1" ;;
--docker) OPT_DOCKER=1 ;;
--tag) shift; [ "$#" -gt 0 ] || die "--tag 需要参数"; OPT_TAG="$1" ;;
--local) OPT_LOCAL=1 ;;
--skip-pull) export ARTEX_SKIP_PULL=1 ;;
@@ -162,23 +152,18 @@ if [ "$OPT_LOCAL" -eq 1 ]; then
exit 0
fi
if [ -n "$OPT_EDITION" ]; then
case "$OPT_EDITION" in
sandbox|standalone) install_docker "$OPT_EDITION" "$OPT_TAG" ;;
*) die "无效 --edition 值:${OPT_EDITION}(仅支持 sandbox 或 standalone)" ;;
esac
if [ "$OPT_DOCKER" -eq 1 ]; then
install_docker "$OPT_TAG"
exit 0
fi
echo "=========================================="
echo " ARTEX 安装部署"
echo " 1) Docker 沙箱隔离版(推荐:独立沙箱 + 全流量网关)"
echo " 2) Docker 单容器版(兼容上一版本:仅 postgres + artex)"
echo " 3) 本地运行(Go 编译)"
echo " 1) Docker 部署(推荐:独立沙箱 + 全流量网关)"
echo " 2) 本地运行(Go 编译)"
echo "=========================================="
case "$(ask '选择' 1)" in
1) install_docker sandbox "$OPT_TAG" ;;
2) install_docker standalone "$OPT_TAG" ;;
3) install_local ;;
1) install_docker "$OPT_TAG" ;;
2) install_local ;;
*) die "无效选择" ;;
esac
+1 -1
View File
@@ -9,7 +9,7 @@
#
# Run on the Docker host after the networks exist. Safe to repeat.
# Pass --cleanup to remove ARTEX sandbox firewall and residual gateway rules
# (used when switching back / rolling back from sandbox edition to standalone).
# (used on teardown or rollback).
set -eu
sandbox_net="${ARTEX_SANDBOX_NETWORK:-artex-sandbox}"
+91 -283
View File
@@ -1,12 +1,11 @@
#!/usr/bin/env bash
# ARTEX 双版本部署(单容器版 standalone / 沙箱隔离版 sandbox)、平滑迁移与安全回滚公共库。
# ARTEX Docker 部署、平滑升级与安全回滚公共库。
# 由 install.sh 与 update.sh 加载,兼容 macOS Bash 3.2 与 Linux Bash 4/5。
DEPLOY_STATE_DIR="${ARTEX_DEPLOY_STATE_DIR:-.artex-deploy}"
DEPLOY_SNAP_DIR="${DEPLOY_STATE_DIR}/snapshots"
DEPLOY_MAX_SNAPSHOTS="${ARTEX_DEPLOY_MAX_SNAPSHOTS:-10}"
COMPOSE_SANDBOX_FILE="${ARTEX_COMPOSE_SANDBOX_FILE:-docker-compose.yml}"
COMPOSE_STANDALONE_FILE="${ARTEX_COMPOSE_STANDALONE_FILE:-docker-compose.standalone.yml}"
COMPOSE_FILE="${ARTEX_COMPOSE_FILE:-docker-compose.yml}"
HEALTH_CHECK_URL="${ARTEX_HEALTH_URL:-http://127.0.0.1:8787/api/health}"
HEALTH_CHECK_TIMEOUT="${ARTEX_HEALTH_TIMEOUT:-60}"
@@ -83,74 +82,8 @@ env_ensure(){
fi
}
# ── 版本标签与部署形态工具函数 ──────────────────────────────────────────
compose_file_for_edition(){
case "${1:-}" in
standalone) echo "$COMPOSE_STANDALONE_FILE" ;;
sandbox) echo "$COMPOSE_SANDBOX_FILE" ;;
*) die "未知部署形态:${1:-<空>}(仅支持 sandbox / standalone)" ;;
esac
}
edition_label(){
case "${1:-}" in
standalone) echo "单容器版 (standalone)" ;;
sandbox) echo "沙箱隔离版 (sandbox)" ;;
*) echo "未部署 (none)" ;;
esac
}
# v0.3.32 及之前的正式版没有 *-standalone 独立标签,原 tag 本身就是单容器镜像;
# 之后的新版单容器镜像使用 <tag>-standalone(或 latest -> standalone)。
is_legacy_presplit_tag(){
local t="${1#v}" maj min pat
case "$t" in
*[!0-9.]*) return 1 ;;
esac
IFS='.' read -r maj min pat <<EOF
$t
EOF
[ -n "${maj:-}" ] && [ -n "${min:-}" ] && [ -n "${pat:-}" ] || return 1
if [ "$maj" -eq 0 ] && [ "$min" -lt 3 ]; then
return 0
fi
if [ "$maj" -eq 0 ] && [ "$min" -eq 3 ] && [ "$pat" -le 32 ]; then
return 0
fi
return 1
}
normalize_standalone_tag(){
local tag="${1:-}"
if [ -z "$tag" ] || [ "$tag" = "latest" ] || [ "$tag" = "standalone" ]; then
echo "standalone"
return 0
fi
case "$tag" in
*-standalone)
echo "$tag"
return 0
;;
esac
if [ "${ARTEX_RAW_TAG:-0}" = "1" ]; then
echo "$tag"
return 0
fi
if is_legacy_presplit_tag "$tag"; then
echo "$tag"
return 0
fi
case "$tag" in
v[0-9]*.[0-9]*.[0-9]*)
echo "${tag}-standalone"
;;
*)
echo "$tag"
;;
esac
}
normalize_sandbox_tag(){
# ── 版本标签与容器查询 ───────────────────────────────────────────────────
normalize_tag(){
local tag="${1:-}"
if [ -z "$tag" ] || [ "$tag" = "standalone" ]; then
echo "latest"
@@ -166,64 +99,16 @@ normalize_sandbox_tag(){
esac
}
# 从指定 compose 文件或两种 compose 文件中查找服务容器 ID。
# 从 compose 文件中查找服务容器 ID。
find_service_cid(){
local svc="$1" file="${2:-}" cid="" f
local svc="$1" file="${2:-$COMPOSE_FILE}" cid=""
if [ -n "$file" ] && [ -f "$file" ]; then
cid="$(docker compose -f "$file" ps -a -q "$svc" 2>/dev/null | head -n 1 || true)"
[ -n "$cid" ] && { echo "$cid"; return 0; }
fi
for f in "$COMPOSE_SANDBOX_FILE" "$COMPOSE_STANDALONE_FILE"; do
[ -f "$f" ] || continue
cid="$(docker compose -f "$f" ps -a -q "$svc" 2>/dev/null | head -n 1 || true)"
[ -n "$cid" ] && { echo "$cid"; return 0; }
done
return 0
}
# 自动识别当前目录的已部署形态:sandbox / standalone / none
detect_current_edition(){
local env_file="${1:-.env}" cid="" gw_cid="" proxy_cid="" sbx_mode=""
if command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1; then
gw_cid="$(find_service_cid artex-gateway "$COMPOSE_SANDBOX_FILE")"
proxy_cid="$(find_service_cid docker-socket-proxy "$COMPOSE_SANDBOX_FILE")"
if [ -n "$gw_cid" ] || [ -n "$proxy_cid" ]; then
echo "sandbox"
return 0
fi
cid="$(find_service_cid artex)"
if [ -n "$cid" ]; then
sbx_mode="$(docker inspect --format '{{range .Config.Env}}{{println .}}{{end}}' "$cid" 2>/dev/null \
| awk -F= '$1=="ARTEX_SANDBOX_MODE"{print $2; exit}' || true)"
case "$sbx_mode" in
docker) echo "sandbox"; return 0 ;;
local) echo "standalone"; return 0 ;;
esac
fi
fi
if [ -f "$env_file" ]; then
local ed
ed="$(env_get ARTEX_DEPLOY_EDITION "$env_file")"
if [ "$ed" = "sandbox" ] || [ "$ed" = "standalone" ]; then
echo "$ed"
return 0
fi
local mode host_dir
mode="$(env_get ARTEX_SANDBOX_MODE "$env_file")"
host_dir="$(env_get ARTEX_HOST_DATA_DIR "$env_file")"
if [ "$mode" = "docker" ] && [ -n "$host_dir" ] && [ "$host_dir" != "/path/to/ARTEX/data" ]; then
echo "sandbox"
return 0
fi
# 兼容旧版 .env(不含 ARTEX_DEPLOY_EDITION / ARTEX_HOST_DATA_DIR)
echo "standalone"
return 0
fi
echo "none"
}
# ── .env 初始化与迁移补齐 ────────────────────────────────────────────────
init_base_env(){
local file="${1:-.env}"
@@ -260,19 +145,14 @@ is_snapshot_tag(){
}
# 从回滚固定镜像(artex-rollback/*)恢复为上游镜像仓库/标签,确保回滚后再次执行
# ./update.sh --upgrade 或迁移时不会尝试向 Docker Hub 拉取本地 artex-rollback/* 标签。
# ./update.sh --upgrade 时不会尝试向 Docker Hub 拉取本地 artex-rollback/* 标签。
unpin_rollback_env(){
local edition="$1" file="${2:-.env}" cur up
local file="${1:-.env}" cur up
cur="$(env_get ARTEX_IMAGE "$file")"
if is_rollback_image_ref "$cur"; then
up="$(env_get ARTEX_UPSTREAM_IMAGE "$file")"
env_set ARTEX_IMAGE "${up:-ruoji6/artex}" "$file"
fi
cur="$(env_get ARTEX_STANDALONE_IMAGE "$file")"
if is_rollback_image_ref "$cur"; then
up="$(env_get ARTEX_UPSTREAM_STANDALONE_IMAGE "$file")"
env_set ARTEX_STANDALONE_IMAGE "${up:-ruoji6/artex}" "$file"
fi
cur="$(env_get ARTEX_GATEWAY_IMAGE "$file")"
if is_rollback_image_ref "$cur"; then
up="$(env_get ARTEX_UPSTREAM_GATEWAY_IMAGE "$file")"
@@ -283,26 +163,17 @@ unpin_rollback_env(){
up="$(env_get ARTEX_UPSTREAM_SANDBOX_IMAGE "$file")"
env_set ARTEX_SANDBOX_IMAGE "${up:-ruoji6/artex-sandbox:latest}" "$file"
fi
if [ "$edition" = "sandbox" ]; then
cur="$(env_get ARTEX_TAG "$file")"
if is_snapshot_tag "$cur"; then
up="$(env_get ARTEX_UPSTREAM_TAG "$file")"
env_set ARTEX_TAG "${up:-latest}" "$file"
fi
else
cur="$(env_get ARTEX_STANDALONE_TAG "$file")"
if is_snapshot_tag "$cur"; then
up="$(env_get ARTEX_UPSTREAM_STANDALONE_TAG "$file")"
env_set ARTEX_STANDALONE_TAG "${up:-standalone}" "$file"
fi
cur="$(env_get ARTEX_TAG "$file")"
if is_snapshot_tag "$cur"; then
up="$(env_get ARTEX_UPSTREAM_TAG "$file")"
env_set ARTEX_TAG "${up:-latest}" "$file"
fi
}
prepare_env_for_sandbox(){
prepare_env_for_docker(){
local tag="${1:-}" file="${2:-.env}"
init_base_env "$file"
unpin_rollback_env "sandbox" "$file"
env_set ARTEX_DEPLOY_EDITION "sandbox" "$file"
unpin_rollback_env "$file"
env_ensure ARTEX_IMAGE "ruoji6/artex" "$file"
env_ensure ARTEX_GATEWAY_IMAGE "ruoji6/artex-gateway" "$file"
env_ensure ARTEX_SANDBOX_IMAGE "ruoji6/artex-sandbox:latest" "$file"
@@ -327,39 +198,21 @@ prepare_env_for_sandbox(){
if [ -n "$tag" ]; then
local norm
norm="$(normalize_sandbox_tag "$tag")"
norm="$(normalize_tag "$tag")"
env_set ARTEX_TAG "$norm" "$file"
ok "已将沙箱版 ARTEX_TAG 设为 ${norm}"
ok "已将 ARTEX_TAG 设为 ${norm}"
else
local cur_tag
cur_tag="$(env_get ARTEX_TAG "$file")"
case "$cur_tag" in
""|standalone|*-standalone)
env_set ARTEX_TAG "$(normalize_sandbox_tag "$cur_tag")" "$file"
env_set ARTEX_TAG "$(normalize_tag "$cur_tag")" "$file"
;;
esac
fi
}
prepare_env_for_standalone(){
local tag="${1:-}" file="${2:-.env}"
init_base_env "$file"
unpin_rollback_env "standalone" "$file"
env_set ARTEX_DEPLOY_EDITION "standalone" "$file"
env_ensure ARTEX_IMAGE "ruoji6/artex" "$file"
env_set ARTEX_SANDBOX_MODE "local" "$file"
if [ -n "$tag" ]; then
local norm
norm="$(normalize_standalone_tag "$tag")"
env_set ARTEX_STANDALONE_TAG "$norm" "$file"
ok "已将单容器版 ARTEX_STANDALONE_TAG 设为 ${norm}"
else
env_ensure ARTEX_STANDALONE_TAG "standalone" "$file"
fi
}
# 单容器版(root 运行)迁移到沙箱隔离版(uid 1000)时,为既有工作区补足非 root 写权限。
# 从旧版 root 容器升级到非 root(uid 1000)沙箱时,为既有工作区补足写权限。
# 严格跳过符号链接,防止符号链接越界修改宿主机文件。
prepare_migrated_workspaces(){
local data_dir="${1:-./data}" d use_sudo=0
@@ -383,20 +236,19 @@ prepare_migrated_workspaces(){
done
}
# 沙箱隔离版环境预检(Linux /dev/net/tun 等)
preflight_sandbox(){
# Docker 部署环境预检(Linux /dev/net/tun 等)
preflight_docker(){
local os_name
os_name="$(uname -s)"
if [ "$os_name" != "Linux" ]; then
warn "检测到当前宿主机为 ${os_name}(非 Linux)。沙箱透明网关(artex-gateway)需要 Linux 宿主机网络栈与 /dev/net/tun。"
warn "若在 macOS / Windows Docker Desktop 上运行,建议使用「单容器版 (standalone)」。"
warn "检测到当前宿主机为 ${os_name}(非 Linux)。透明网关(artex-gateway)需要 Linux 宿主机网络栈与 /dev/net/tun。"
if [ "${ARTEX_NONINTERACTIVE:-0}" != "1" ]; then
[ "$(ask '仍继续部署沙箱隔离版? (y/n)' n)" = "y" ] || die "已取消,可改选单容器版 (standalone)"
[ "$(ask '仍继续部署? (y/n)' n)" = "y" ] || die "已取消部署"
fi
return 0
fi
if [ ! -e /dev/net/tun ]; then
warn "宿主机未发现 /dev/net/tun:artex-gateway 启动时可能无法开启 TUN 模式(请确认内核加载 tun 模块或改用单容器版)。"
warn "宿主机未发现 /dev/net/tun:artex-gateway 启动时可能无法开启 TUN 模式(请确认内核加载 tun 模块)。"
fi
}
@@ -410,12 +262,12 @@ stop_sandbox_runtime(){
# shellcheck disable=SC2086
docker stop -t 10 $sbx_cids >/dev/null 2>&1 || true
fi
if [ -f "$COMPOSE_SANDBOX_FILE" ]; then
if [ -f "$COMPOSE_FILE" ]; then
local gw_cid
gw_cid="$(find_service_cid artex-gateway "$COMPOSE_SANDBOX_FILE")"
gw_cid="$(find_service_cid artex-gateway "$COMPOSE_FILE")"
if [ -n "$gw_cid" ]; then
info "优雅停止透明代理网关 artex-gateway(自动清理 TUN 与 iptables 规则)…"
docker compose -f "$COMPOSE_SANDBOX_FILE" stop -t 15 artex-gateway >/dev/null 2>&1 || true
docker compose -f "$COMPOSE_FILE" stop -t 15 artex-gateway >/dev/null 2>&1 || true
fi
fi
fi
@@ -484,11 +336,11 @@ prune_old_snapshots(){
done
}
# 记录当前部署状态(.env、运行镜像精确 ID + 固定回滚标签、部署形态、PG 逻辑备份)
# 记录当前部署状态(.env、运行镜像精确 ID + 固定回滚标签、PG 逻辑备份)
# 仅向 stdout 输出 snapshot ID,便于调用方捕获。
create_deploy_snapshot(){
local reason="${1:-upgrade}" skip_db="${2:-0}"
local ts snap_id snap_dir edition artex_cid gw_cid pg_cid
local ts snap_id snap_dir artex_cid gw_cid pg_cid
local artex_ref="" artex_id="" artex_rb=""
local gw_ref="" gw_id="" gw_rb=""
local sbx_ref="" sbx_id="" sbx_rb=""
@@ -501,7 +353,6 @@ create_deploy_snapshot(){
snap_dir="${DEPLOY_SNAP_DIR}/${snap_id}"
mkdir -p "$snap_dir"
edition="$(detect_current_edition .env)"
[ -f .env ] && cp .env "${snap_dir}/dot.env"
if command -v docker >/dev/null 2>&1; then
@@ -514,7 +365,7 @@ create_deploy_snapshot(){
fi
fi
gw_cid="$(find_service_cid artex-gateway "$COMPOSE_SANDBOX_FILE")"
gw_cid="$(find_service_cid artex-gateway "$COMPOSE_FILE")"
if [ -n "$gw_cid" ]; then
gw_ref="$(docker inspect --format '{{.Config.Image}}' "$gw_cid" 2>/dev/null || true)"
gw_id="$(docker inspect --format '{{.Image}}' "$gw_cid" 2>/dev/null || true)"
@@ -525,13 +376,12 @@ create_deploy_snapshot(){
sbx_ref="$(env_get ARTEX_SANDBOX_IMAGE .env)"
[ -n "$sbx_ref" ] || sbx_ref="ruoji6/artex-sandbox:latest"
if [ "$edition" = "sandbox" ] && docker image inspect "$sbx_ref" >/dev/null 2>&1; then
if docker image inspect "$sbx_ref" >/dev/null 2>&1; then
sbx_id="$(docker image inspect --format '{{.Id}}' "$sbx_ref" 2>/dev/null || true)"
if snapshot_tag_image "$sbx_id" "artex-rollback/sandbox:${snap_id}"; then
sbx_rb="artex-rollback/sandbox:${snap_id}"
fi
fi
if [ "$skip_db" != "1" ]; then
pg_cid="$(find_service_cid postgres)"
if [ -n "$pg_cid" ] && [ "$(docker inspect --format '{{.State.Running}}' "$pg_cid" 2>/dev/null || true)" = "true" ]; then
@@ -555,7 +405,6 @@ create_deploy_snapshot(){
SNAP_ID=${snap_id}
SNAP_TIME=${ts}
SNAP_REASON=${reason}
SNAP_EDITION=${edition}
ARTEX_IMAGE_REF=${artex_ref}
ARTEX_IMAGE_ID=${artex_id}
ARTEX_ROLLBACK_TAG=${artex_rb}
@@ -574,20 +423,19 @@ META
list_deploy_snapshots(){
if [ ! -d "$DEPLOY_SNAP_DIR" ]; then
info "暂无部署快照(升级或迁移前会自动生成)"
info "暂无部署快照(升级前会自动生成)"
return 0
fi
local found=0 dir snap_id ed img pg reason
local found=0 dir snap_id img pg reason
for dir in $(ls -1dt "${DEPLOY_SNAP_DIR}"/*/ 2>/dev/null || true); do
[ -f "${dir}/meta.env" ] || continue
found=1
snap_id="$(env_get SNAP_ID "${dir}/meta.env")"
ed="$(env_get SNAP_EDITION "${dir}/meta.env")"
img="$(env_get ARTEX_IMAGE_REF "${dir}/meta.env")"
pg="$(env_get HAS_PG_DUMP "${dir}/meta.env")"
reason="$(env_get SNAP_REASON "${dir}/meta.env")"
printf ' - %s [形态: %s] [镜像: %s] [DB备份: %s] [来源: %s]\n' \
"$snap_id" "${ed:-unknown}" "${img:-unknown}" "$([ "$pg" = "1" ] && echo "有" || echo "无")" "${reason:-?}"
printf ' - %s [镜像: %s] [DB备份: %s] [来源: %s]\n' \
"$snap_id" "${img:-unknown}" "$([ "$pg" = "1" ] && echo "有" || echo "无")" "${reason:-?}"
done
if [ "$found" -eq 0 ]; then
info "暂无部署快照"
@@ -596,7 +444,7 @@ list_deploy_snapshots(){
# 将快照中的本地回滚镜像还原到对应目标标签,确保即便 :latest 已被覆盖或离线也能 100% 精准回滚。
restore_snapshot_images(){
local meta="$1" edition="$2"
local meta="$1"
local artex_rb artex_ref gw_rb gw_ref sbx_rb sbx_ref
artex_rb="$(env_get ARTEX_ROLLBACK_TAG "$meta")"
artex_ref="$(env_get ARTEX_IMAGE_REF "$meta")"
@@ -606,11 +454,9 @@ restore_snapshot_images(){
sbx_ref="$(env_get SANDBOX_IMAGE_REF "$meta")"
# 先保存非回滚上游仓库与标签,确保回滚后再次执行 ./update.sh --upgrade 能正确切回上游镜像。
local orig_img orig_tag orig_simg orig_stag orig_gw orig_sbx
local orig_img orig_tag orig_gw orig_sbx
orig_img="$(env_get ARTEX_IMAGE .env)"
orig_tag="$(env_get ARTEX_TAG .env)"
orig_simg="$(env_get ARTEX_STANDALONE_IMAGE .env)"
orig_stag="$(env_get ARTEX_STANDALONE_TAG .env)"
orig_gw="$(env_get ARTEX_GATEWAY_IMAGE .env)"
orig_sbx="$(env_get ARTEX_SANDBOX_IMAGE .env)"
if [ -n "$orig_img" ] && ! is_rollback_image_ref "$orig_img"; then
@@ -619,12 +465,6 @@ restore_snapshot_images(){
if [ -n "$orig_tag" ] && ! is_snapshot_tag "$orig_tag"; then
env_set ARTEX_UPSTREAM_TAG "$orig_tag" .env
fi
if [ -n "$orig_simg" ] && ! is_rollback_image_ref "$orig_simg"; then
env_set ARTEX_UPSTREAM_STANDALONE_IMAGE "$orig_simg" .env
fi
if [ -n "$orig_stag" ] && ! is_snapshot_tag "$orig_stag"; then
env_set ARTEX_UPSTREAM_STANDALONE_TAG "$orig_stag" .env
fi
if [ -n "$orig_gw" ] && ! is_rollback_image_ref "$orig_gw"; then
env_set ARTEX_UPSTREAM_GATEWAY_IMAGE "$orig_gw" .env
fi
@@ -633,46 +473,44 @@ restore_snapshot_images(){
fi
if [ -n "$artex_rb" ] && docker image inspect "$artex_rb" >/dev/null 2>&1; then
if [ "$edition" = "standalone" ]; then
# 直接指向独立回滚 repo:tag,彻底规避旧版 .env 使用 :latest / :v0.3.32 导致的标签漂移。
env_set ARTEX_STANDALONE_IMAGE "${artex_rb%:*}" .env
env_set ARTEX_STANDALONE_TAG "${artex_rb##*:}" .env
else
if [ -n "$artex_ref" ] && ! is_rollback_image_ref "$artex_ref"; then
docker tag "$artex_rb" "$artex_ref" >/dev/null 2>&1 || true
fi
env_set ARTEX_IMAGE "${artex_rb%:*}" .env
env_set ARTEX_TAG "${artex_rb##*:}" .env
if [ -n "$artex_ref" ] && ! is_rollback_image_ref "$artex_ref"; then
docker tag "$artex_rb" "$artex_ref" >/dev/null 2>&1 || true
fi
env_set ARTEX_IMAGE "${artex_rb%:*}" .env
env_set ARTEX_TAG "${artex_rb##*:}" .env
ok "已绑定本地精确回滚镜像:${artex_rb}(原镜像:${artex_ref:-unknown})"
elif [ "$edition" = "standalone" ] && [ -n "$artex_ref" ]; then
# 本地镜像已被 prune 时,用快照记录的精确 repo:tag 拉取还原(支持回滚到 v0.3.32 等历史版本)。
elif [ -n "$artex_ref" ]; then
local repo="${artex_ref%:*}" tag="${artex_ref##*:}"
if [ "$repo" != "$artex_ref" ] && [ -n "$tag" ]; then
env_set ARTEX_STANDALONE_IMAGE "$repo" .env
env_set ARTEX_STANDALONE_TAG "$tag" .env
env_set ARTEX_IMAGE "$repo" .env
env_set ARTEX_TAG "$tag" .env
fi
fi
if [ "$edition" = "sandbox" ]; then
if [ -n "$gw_rb" ] && docker image inspect "$gw_rb" >/dev/null 2>&1; then
if [ -n "$gw_ref" ] && ! is_rollback_image_ref "$gw_ref"; then
docker tag "$gw_rb" "$gw_ref" >/dev/null 2>&1 || true
fi
env_set ARTEX_GATEWAY_IMAGE "${gw_rb%:*}" .env
# artex-rollback/artex 与 artex-rollback/gateway 共享同一个 :<snap_id> 标签,互不冲突。
local cur_tag
cur_tag="$(env_get ARTEX_TAG .env)"
if [ -n "$cur_tag" ] && [ "$cur_tag" != "${gw_rb##*:}" ]; then
docker tag "$gw_rb" "${gw_rb%:*}:${cur_tag}" >/dev/null 2>&1 || true
fi
local cur_tag
cur_tag="$(env_get ARTEX_TAG .env)"
if [ -n "$gw_rb" ] && docker image inspect "$gw_rb" >/dev/null 2>&1; then
if [ -n "$gw_ref" ] && ! is_rollback_image_ref "$gw_ref"; then
docker tag "$gw_rb" "$gw_ref" >/dev/null 2>&1 || true
fi
if [ -n "$sbx_rb" ] && docker image inspect "$sbx_rb" >/dev/null 2>&1; then
if [ -n "$sbx_ref" ] && ! is_rollback_image_ref "$sbx_ref"; then
docker tag "$sbx_rb" "$sbx_ref" >/dev/null 2>&1 || true
fi
env_set ARTEX_SANDBOX_IMAGE "$sbx_rb" .env
env_set ARTEX_GATEWAY_IMAGE "${gw_rb%:*}" .env
# artex-rollback/artex 与 artex-rollback/gateway 共享同一个 :<snap_id> 标签,互不冲突。
if [ -n "$cur_tag" ] && [ "$cur_tag" != "${gw_rb##*:}" ]; then
docker tag "$gw_rb" "${gw_rb%:*}:${cur_tag}" >/dev/null 2>&1 || true
fi
elif is_snapshot_tag "$cur_tag"; then
local fallback_gw="${orig_gw:-ruoji6/artex-gateway}:latest"
if docker image inspect "$fallback_gw" >/dev/null 2>&1; then
docker tag "$fallback_gw" "artex-rollback/gateway:${cur_tag}" >/dev/null 2>&1 || true
env_set ARTEX_GATEWAY_IMAGE "artex-rollback/gateway" .env
fi
fi
if [ -n "$sbx_rb" ] && docker image inspect "$sbx_rb" >/dev/null 2>&1; then
if [ -n "$sbx_ref" ] && ! is_rollback_image_ref "$sbx_ref"; then
docker tag "$sbx_rb" "$sbx_ref" >/dev/null 2>&1 || true
fi
env_set ARTEX_SANDBOX_IMAGE "$sbx_rb" .env
fi
}
@@ -705,20 +543,9 @@ rollback_to_snapshot(){
local meta="${snap_dir}/meta.env"
[ -f "$meta" ] || die "快照不存在:${snap_id}(可用 ./update.sh --list-snapshots 查看)"
local target_ed cur_ed target_compose
target_ed="$(env_get SNAP_EDITION "$meta")"
if [ "$target_ed" != "sandbox" ] && [ "$target_ed" != "standalone" ]; then
die "快照 ${snap_id} 未记录有效的部署形态(SNAP_EDITION=${target_ed:-<空>})"
fi
cur_ed="$(detect_current_edition .env)"
target_compose="$(compose_file_for_edition "$target_ed")"
info "开始回滚到快照 ${snap_id}…"
info "开始回滚到快照 ${snap_id}(目标形态:$(edition_label "$target_ed"))…"
# 只要当前在沙箱版且回滚到单容器版(或需要重启网关),都先优雅停止沙箱与网关清理规则。
if [ "$cur_ed" = "sandbox" ] || [ "$target_ed" = "standalone" ]; then
stop_sandbox_runtime
fi
stop_sandbox_runtime
if [ -f .env ]; then
cp .env "${DEPLOY_STATE_DIR}/env.before-rollback.$(date +%Y%m%d-%H%M%S)" 2>/dev/null || true
@@ -728,70 +555,51 @@ rollback_to_snapshot(){
chmod 600 .env 2>/dev/null || true
fi
env_set ARTEX_DEPLOY_EDITION "$target_ed" .env
if [ "$target_ed" = "standalone" ]; then
env_set ARTEX_SANDBOX_MODE "local" .env
else
env_set ARTEX_SANDBOX_MODE "docker" .env
fi
restore_snapshot_images "$meta" "$target_ed"
env_set ARTEX_SANDBOX_MODE "docker" .env
restore_snapshot_images "$meta"
if [ "$restore_db" = "1" ]; then
docker compose -f "$target_compose" up -d postgres
restore_postgres_dump "${snap_dir}/postgres.sql.gz" "$target_compose"
docker compose -f "$COMPOSE_FILE" up -d postgres
restore_postgres_dump "${snap_dir}/postgres.sql.gz" "$COMPOSE_FILE"
fi
info "按目标形态启动服务(${target_compose} --remove-orphans)…"
docker compose -f "$target_compose" up -d --remove-orphans
info "启动服务(${COMPOSE_FILE} --remove-orphans)…"
docker compose -f "$COMPOSE_FILE" up -d --remove-orphans
if wait_for_health "$target_compose"; then
ok "回滚完成!当前形态:$(edition_label "$target_ed") → http://localhost:8787"
if wait_for_health "$COMPOSE_FILE"; then
ok "回滚完成 → http://localhost:8787"
else
die "回滚后健康检查未通过,请执行 docker compose -f ${target_compose} logs --tail=80 artex 排查"
die "回滚后健康检查未通过,请执行 docker compose -f ${COMPOSE_FILE} logs --tail=80 artex 排查"
fi
}
# ── 拉取并启动指定形态 ───────────────────────────────────────────────────
pull_edition_images(){
local edition="$1" compose_file sbx_img
compose_file="$(compose_file_for_edition "$edition")"
# ── 拉取并启动服务 ───────────────────────────────────────────────────────
pull_docker_images(){
local sbx_img
if [ "${ARTEX_SKIP_PULL:-0}" = "1" ]; then
info "已跳过镜像拉取(ARTEX_SKIP_PULL=1)"
return 0
fi
if [ "$edition" = "sandbox" ]; then
info "拉取沙箱隔离版镜像(artex / artex-gateway / docker-socket-proxy / postgres)…"
docker compose -f "$compose_file" pull
sbx_img="$(env_get ARTEX_SANDBOX_IMAGE .env)"
[ -n "$sbx_img" ] || sbx_img="ruoji6/artex-sandbox:latest"
info "拉取沙箱执行镜像(${sbx_img})…"
docker pull "$sbx_img"
else
info "拉取单容器版镜像(artex standalone / postgres)…"
docker compose -f "$compose_file" pull artex
local pg_cid
pg_cid="$(find_service_cid postgres "$compose_file")"
if [ -z "$pg_cid" ]; then
docker compose -f "$compose_file" pull postgres
fi
fi
info "拉取镜像(artex / artex-gateway / docker-socket-proxy / postgres)…"
docker compose -f "$COMPOSE_FILE" pull
sbx_img="$(env_get ARTEX_SANDBOX_IMAGE .env)"
[ -n "$sbx_img" ] || sbx_img="ruoji6/artex-sandbox:latest"
info "拉取沙箱执行镜像(${sbx_img})…"
docker pull "$sbx_img"
}
deploy_edition_with_rollback(){
local target_ed="$1" snap_id="$2"
local compose_file
compose_file="$(compose_file_for_edition "$target_ed")"
deploy_with_rollback(){
local snap_id="${1:-}"
pull_edition_images "$target_ed"
info "启动 $(edition_label "$target_ed")(${compose_file})…"
if ! docker compose -f "$compose_file" up -d --remove-orphans || ! wait_for_health "$compose_file"; then
pull_docker_images
info "启动服务(${COMPOSE_FILE})…"
if ! docker compose -f "$COMPOSE_FILE" up -d --remove-orphans || ! wait_for_health "$COMPOSE_FILE"; then
warn "新版本启动或健康检查失败!"
if [ -n "$snap_id" ] && [ -f "${DEPLOY_SNAP_DIR}/${snap_id}/meta.env" ]; then
warn "正在自动回滚到操作前快照 ${snap_id}…"
rollback_to_snapshot "$snap_id" 0
die "已自动回滚到 ${snap_id},请排查失败原因后重试"
fi
die "启动失败,请查看日志:docker compose -f ${compose_file} logs --tail=80 artex"
die "启动失败,请查看日志:docker compose -f ${COMPOSE_FILE} logs --tail=80 artex"
fi
}
+68 -89
View File
@@ -1,12 +1,12 @@
#!/usr/bin/env bash
# Automated regression tests for dual-edition deployment (standalone / sandbox),
# migration from legacy v0.3.32, snapshot creation, manual rollback, DB restore,
# Automated regression tests for Docker deployment, upgrade from legacy .env,
# snapshot creation, manual rollback, DB restore, post-rollback upstream unpinning,
# and automatic rollback on failed health check.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
trap 'chmod -R u+w "$TMP_DIR" 2>/dev/null || true; rm -rf "$TMP_DIR"' EXIT
pass() { printf 'PASS: %s\n' "$*"; }
fail() { printf 'FAIL: %s\n' "$*" >&2; exit 1; }
@@ -31,18 +31,10 @@ pass "shell syntax checks"
cd "$TMP_DIR"
# shellcheck source=scripts/deploy-lib.sh
. "$REPO_ROOT/scripts/deploy-lib.sh"
assert_eq "$(normalize_standalone_tag "")" "standalone" "empty standalone tag"
assert_eq "$(normalize_standalone_tag "latest")" "standalone" "latest -> standalone"
assert_eq "$(normalize_standalone_tag "standalone")" "standalone" "standalone -> standalone"
assert_eq "$(normalize_standalone_tag "v0.3.32")" "v0.3.32" "legacy pre-split tag preserved"
assert_eq "$(normalize_standalone_tag "v0.3.17")" "v0.3.17" "older pre-split tag preserved"
assert_eq "$(normalize_standalone_tag "v0.3.33")" "v0.3.33-standalone" "new tag mapped to -standalone"
assert_eq "$(normalize_standalone_tag "v0.4.0")" "v0.4.0-standalone" "minor bump mapped to -standalone"
assert_eq "$(normalize_standalone_tag "v0.3.33-standalone")" "v0.3.33-standalone" "already suffixed preserved"
assert_eq "$(normalize_sandbox_tag "standalone")" "latest" "sandbox standalone -> latest"
assert_eq "$(normalize_sandbox_tag "v0.3.33-standalone")" "v0.3.33" "sandbox strips -standalone"
assert_eq "$(normalize_sandbox_tag "v0.3.33")" "v0.3.33" "sandbox keeps semver"
assert_eq "$(normalize_tag "")" "latest" "empty tag -> latest"
assert_eq "$(normalize_tag "standalone")" "latest" "legacy standalone -> latest"
assert_eq "$(normalize_tag "v0.3.33-standalone")" "v0.3.33" "strips legacy -standalone suffix"
assert_eq "$(normalize_tag "v0.3.33")" "v0.3.33" "keeps semver tag"
env_set FOO "/a/b|c&d" "$TMP_DIR/t.env"
assert_eq "$(env_get FOO "$TMP_DIR/t.env")" "/a/b|c&d" "env_set/get preserves special chars"
@@ -58,16 +50,19 @@ BIN_STUB="$TMP_DIR/bin"
STATE_STUB="$TMP_DIR/stub-state"
mkdir -p "$WORK/scripts" "$BIN_STUB" "$STATE_STUB/images"
cp "$REPO_ROOT/install.sh" "$REPO_ROOT/update.sh" "$REPO_ROOT/.env.example" \
"$REPO_ROOT/docker-compose.yml" "$REPO_ROOT/docker-compose.standalone.yml" "$WORK/"
"$REPO_ROOT/docker-compose.yml" "$WORK/"
cp "$REPO_ROOT/scripts/deploy-lib.sh" "$REPO_ROOT/scripts/artex-sandbox-firewall.sh" "$WORK/scripts/"
chmod +x "$WORK/install.sh" "$WORK/update.sh" "$WORK/scripts/deploy-lib.sh" "$WORK/scripts/artex-sandbox-firewall.sh"
# Seed mock docker image store (v0.3.32 standalone image)
printf 'sha256:old0332standalone\n' > "$STATE_STUB/images/sha256_old0332standalone"
printf 'sha256:old0332standalone\n' > "$STATE_STUB/images/ruoji6_artex_v0.3.32"
printf 'standalone\n' > "$STATE_STUB/running_edition"
# Seed mock docker image store (existing installation before upgrade)
printf 'sha256:old0332artex\n' > "$STATE_STUB/images/sha256_old0332artex"
printf 'sha256:old0332artex\n' > "$STATE_STUB/images/ruoji6_artex_v0.3.32"
printf 'sha256:old0332gw\n' > "$STATE_STUB/images/sha256_old0332gw"
printf 'sha256:old0332gw\n' > "$STATE_STUB/images/ruoji6_artex-gateway_latest"
printf 'sha256:old0332sbx\n' > "$STATE_STUB/images/sha256_old0332sbx"
printf 'sha256:old0332sbx\n' > "$STATE_STUB/images/ruoji6_artex-sandbox_latest"
printf 'ruoji6/artex:v0.3.32\n' > "$STATE_STUB/artex_image_ref"
printf 'sha256:old0332standalone\n' > "$STATE_STUB/artex_image_id"
printf 'sha256:old0332artex\n' > "$STATE_STUB/artex_image_id"
printf 'ok\n' > "$STATE_STUB/health_mode"
cat > "$BIN_STUB/docker" <<'STUB'
@@ -88,14 +83,12 @@ case "${1:-}" in
case "$sub" in
version) echo "Docker Compose version v2.29.0"; exit 0 ;;
ps)
# ps -a -q <svc>
svc="${!#}"
ed="$(cat "$STATE/running_edition")"
case "$svc" in
artex) echo "cid-artex" ;;
postgres) echo "cid-pg" ;;
artex-gateway) [ "$ed" = "sandbox" ] && echo "cid-gw" || true ;;
docker-socket-proxy) [ "$ed" = "sandbox" ] && echo "cid-dsp" || true ;;
artex-gateway) echo "cid-gw" ;;
docker-socket-proxy) echo "cid-dsp" ;;
esac
exit 0 ;;
pull)
@@ -104,20 +97,16 @@ case "${1:-}" in
exit 0 ;;
up)
if [ "$cfile" = "docker-compose.yml" ]; then
printf 'sandbox\n' > "$STATE/running_edition"
printf 'ruoji6/artex:latest\n' > "$STATE/artex_image_ref"
printf 'sha256:new0333sandbox\n' > "$STATE/artex_image_id"
printf 'sha256:new0333sandbox\n' > "$STATE/images/sha256_new0333sandbox"
printf 'sha256:new0333artex\n' > "$STATE/artex_image_id"
printf 'sha256:new0333artex\n' > "$STATE/images/sha256_new0333artex"
printf 'sha256:new0333gw\n' > "$STATE/images/sha256_new0333gw"
printf 'sha256:new0333sbx\n' > "$STATE/images/ruoji6_artex-sandbox_latest"
elif [ "$cfile" = "docker-compose.standalone.yml" ]; then
printf 'standalone\n' > "$STATE/running_edition"
fi
exit 0 ;;
esac ;;
ps)
ed="$(cat "$STATE/running_edition")"
if [ "$ed" = "sandbox" ]; then echo "cid-sbx-1"; fi
echo "cid-sbx-1"
exit 0 ;;
stop|pull|rmi)
exit 0 ;;
@@ -145,11 +134,8 @@ case "${1:-}" in
cid-artex:*Config.Image*) cat "$STATE/artex_image_ref" ;;
cid-artex:*.Image*) cat "$STATE/artex_image_id" ;;
cid-artex:*State.Status*) echo "running" ;;
cid-artex:*Config.Env*)
[ "$(cat "$STATE/running_edition")" = "sandbox" ] && echo "ARTEX_SANDBOX_MODE=docker" || echo "ARTEX_SANDBOX_MODE=local"
;;
cid-gw:*Config.Image*) echo "ruoji6/artex-gateway:latest" ;;
cid-gw:*.Image*) echo "sha256:new0333gw" ;;
cid-gw:*.Image*) echo "sha256:old0332gw" ;;
cid-pg:*State.Running*) echo "true" ;;
esac
exit 0 ;;
@@ -183,7 +169,7 @@ exit 22
STUB
chmod +x "$BIN_STUB/curl"
# Create legacy v0.3.32 .env (no ARTEX_DEPLOY_EDITION, no ARTEX_HOST_DATA_DIR, no ARTEX_GATEWAY_TOKEN)
# Create legacy .env (no ARTEX_HOST_DATA_DIR, no ARTEX_GATEWAY_TOKEN)
cat > "$WORK/.env" <<'ENV'
ARTEX_IMAGE=ruoji6/artex
ARTEX_TAG=v0.3.32
@@ -206,77 +192,70 @@ export PATH="$BIN_STUB:$PATH"
export ARTEX_TEST_STUB_STATE="$STATE_STUB"
export ARTEX_HEALTH_TIMEOUT=2
# 3a. Detect legacy v0.3.32 standalone deployment
ed="$(cd "$WORK" && . ./scripts/deploy-lib.sh && detect_current_edition .env)"
assert_eq "$ed" "standalone" "detect legacy v0.3.32 as standalone"
pass "legacy standalone detection"
# 3b. Migrate legacy standalone -> sandbox
# 3a. Upgrade legacy .env -> current Docker topology
(
cd "$WORK"
./update.sh --migrate-sandbox --skip-git-pull --yes
./update.sh --upgrade --tag v0.3.33 --skip-git-pull --yes
)
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_DEPLOY_EDITION .env)" "sandbox" "edition migrated to sandbox"
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_TAG .env)" "v0.3.33" "ARTEX_TAG updated"
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_SANDBOX_MODE .env)" "docker" "ARTEX_SANDBOX_MODE set to docker"
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_HOST_DATA_DIR .env)" "$WORK/data" "ARTEX_HOST_DATA_DIR populated"
[ -n "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_GATEWAY_TOKEN .env)" ] || fail "ARTEX_GATEWAY_TOKEN not generated"
[ -w "$WORK/data/tasks/5/findings/note.txt" ] || fail "migrated task file not writable"
# Outside symlink target must still be 0400
outside_perm="$(stat -f '%Lp' "$OUTSIDE_FILE" 2>/dev/null || stat -c '%a' "$OUTSIDE_FILE")"
assert_eq "$outside_perm" "400" "symlink target permissions must not be modified"
snap_mig="$(cat "$WORK/.artex-deploy/latest")"
assert_contains "$WORK/.artex-deploy/snapshots/$snap_mig/meta.env" "SNAP_EDITION=standalone" "migration snapshot records standalone"
assert_contains "$WORK/.artex-deploy/snapshots/$snap_mig/meta.env" "ARTEX_IMAGE_REF=ruoji6/artex:v0.3.32" "migration snapshot records v0.3.32 image"
assert_contains "$WORK/.artex-deploy/snapshots/$snap_mig/meta.env" "HAS_PG_DUMP=1" "migration snapshot includes PG dump"
assert_contains "$STATE_STUB/docker.log" "compose -f docker-compose.yml up -d --remove-orphans" "started sandbox compose"
pass "legacy standalone -> sandbox migration"
snap_upg="$(cat "$WORK/.artex-deploy/latest")"
assert_contains "$WORK/.artex-deploy/snapshots/$snap_upg/meta.env" "ARTEX_IMAGE_REF=ruoji6/artex:v0.3.32" "upgrade snapshot records v0.3.32 image"
assert_contains "$WORK/.artex-deploy/snapshots/$snap_upg/meta.env" "HAS_PG_DUMP=1" "upgrade snapshot includes PG dump"
assert_contains "$STATE_STUB/docker.log" "compose -f docker-compose.yml up -d --remove-orphans" "started compose"
pass "upgrade + legacy workspace permission migration"
# 3c. Rollback from sandbox back to legacy standalone (including --restore-db)
# 3b. Manual rollback (including --restore-db)
(
cd "$WORK"
./update.sh --rollback "$snap_mig" --restore-db --yes
./update.sh --rollback "$snap_upg" --restore-db --yes
)
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_DEPLOY_EDITION .env)" "standalone" "rolled back edition to standalone"
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_STANDALONE_IMAGE .env)" "artex-rollback/artex" "rollback pinned local image repo"
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_STANDALONE_TAG .env)" "$snap_mig" "rollback pinned local image tag"
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_IMAGE .env)" "artex-rollback/artex" "rollback pinned local image repo"
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_TAG .env)" "$snap_upg" "rollback pinned local image tag"
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_GATEWAY_IMAGE .env)" "artex-rollback/gateway" "rollback pinned local gateway repo"
assert_contains "$STATE_STUB/docker.log" "stop -t 10 cid-sbx-1" "stopped running sandbox container on rollback"
assert_contains "$STATE_STUB/docker.log" "compose -f docker-compose.yml stop -t 15 artex-gateway" "gracefully stopped artex-gateway on rollback"
assert_contains "$STATE_STUB/docker.log" "compose -f docker-compose.standalone.yml up -d --remove-orphans" "started standalone compose on rollback"
assert_contains "$STATE_STUB/docker.log" "exec -i cid-pg psql" "restored PG dump when --restore-db passed"
pass "sandbox -> standalone rollback + DB restore"
pass "manual rollback + DB restore"
# 3d. Failed upgrade triggers automatic rollback
printf 'fail-once\n' > "$STATE_STUB/health_mode"
if ( cd "$WORK" && ./update.sh --upgrade --tag v0.3.34 --skip-git-pull --yes ); then
fail "upgrade with failing health check should exit non-zero after auto-rollback"
fi
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_DEPLOY_EDITION .env)" "standalone" "auto-rollback preserved standalone edition"
pass "auto-rollback on failed upgrade health check"
# 3e. Switch sandbox -> standalone pinning legacy v0.3.32 tag (also verifies unpinning artex-rollback/* after rollback)
printf 'sandbox\n' > "$STATE_STUB/running_edition"
# 3c. Post-rollback upgrade unpins artex-rollback/* back to upstream
printf 'ok\n' > "$STATE_STUB/health_mode"
(
cd "$WORK"
./update.sh --switch-standalone --tag v0.3.32 --skip-git-pull --yes
./update.sh --upgrade --tag v0.3.34 --skip-git-pull --yes
)
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_STANDALONE_IMAGE .env)" "ruoji6/artex" "post-rollback switch unpinned artex-rollback/* standalone image"
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_STANDALONE_TAG .env)" "v0.3.32" "switch-standalone kept v0.3.32 tag"
pass "switch sandbox -> standalone with legacy tag and rollback unpin"
# 3f. Fresh install for both editions
for ed_opt in standalone sandbox; do
FRESH="$TMP_DIR/fresh-$ed_opt"
mkdir -p "$FRESH/scripts"
cp "$REPO_ROOT/install.sh" "$REPO_ROOT/.env.example" \
"$REPO_ROOT/docker-compose.yml" "$REPO_ROOT/docker-compose.standalone.yml" "$FRESH/"
cp "$REPO_ROOT/scripts/deploy-lib.sh" "$REPO_ROOT/scripts/artex-sandbox-firewall.sh" "$FRESH/scripts/"
chmod +x "$FRESH/install.sh" "$FRESH/scripts/deploy-lib.sh"
( cd "$FRESH" && ./install.sh --edition "$ed_opt" --yes )
assert_eq "$(cd "$FRESH" && . ./scripts/deploy-lib.sh && env_get ARTEX_DEPLOY_EDITION .env)" "$ed_opt" "fresh install edition=$ed_opt"
if [ "$ed_opt" = "sandbox" ]; then
assert_eq "$(cd "$FRESH" && . ./scripts/deploy-lib.sh && env_get ARTEX_HOST_DATA_DIR .env)" "$FRESH/data" "fresh sandbox sets ARTEX_HOST_DATA_DIR"
[ -n "$(cd "$FRESH" && . ./scripts/deploy-lib.sh && env_get ARTEX_GATEWAY_TOKEN .env)" ] || fail "fresh sandbox sets ARTEX_GATEWAY_TOKEN"
fi
done
pass "fresh dual-edition install.sh"
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_IMAGE .env)" "ruoji6/artex" "post-rollback upgrade unpinned artex-rollback/* image"
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_GATEWAY_IMAGE .env)" "ruoji6/artex-gateway" "post-rollback upgrade unpinned gateway image"
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_TAG .env)" "v0.3.34" "post-rollback upgrade applied requested tag"
pass "post-rollback upstream unpinning"
echo "ALL DEPLOY/MIGRATION/ROLLBACK TESTS PASSED"
# 3d. Failed upgrade triggers automatic rollback
printf 'fail-once\n' > "$STATE_STUB/health_mode"
if ( cd "$WORK" && ./update.sh --upgrade --tag v0.3.35 --skip-git-pull --yes ); then
fail "upgrade with failing health check should exit non-zero after auto-rollback"
fi
snap_auto="$(cat "$WORK/.artex-deploy/latest")"
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_IMAGE .env)" "artex-rollback/artex" "auto-rollback pinned previous image"
assert_eq "$(cd "$WORK" && . ./scripts/deploy-lib.sh && env_get ARTEX_TAG .env)" "$snap_auto" "auto-rollback pinned snapshot tag"
pass "auto-rollback on failed upgrade health check"
# 3e. Fresh install
FRESH="$TMP_DIR/fresh"
mkdir -p "$FRESH/scripts"
cp "$REPO_ROOT/install.sh" "$REPO_ROOT/.env.example" "$REPO_ROOT/docker-compose.yml" "$FRESH/"
cp "$REPO_ROOT/scripts/deploy-lib.sh" "$REPO_ROOT/scripts/artex-sandbox-firewall.sh" "$FRESH/scripts/"
chmod +x "$FRESH/install.sh" "$FRESH/scripts/deploy-lib.sh"
printf 'ok\n' > "$STATE_STUB/health_mode"
( cd "$FRESH" && ./install.sh --docker --yes )
assert_eq "$(cd "$FRESH" && . ./scripts/deploy-lib.sh && env_get ARTEX_SANDBOX_MODE .env)" "docker" "fresh install sets ARTEX_SANDBOX_MODE=docker"
assert_eq "$(cd "$FRESH" && . ./scripts/deploy-lib.sh && env_get ARTEX_HOST_DATA_DIR .env)" "$FRESH/data" "fresh install sets ARTEX_HOST_DATA_DIR"
[ -n "$(cd "$FRESH" && . ./scripts/deploy-lib.sh && env_get ARTEX_GATEWAY_TOKEN .env)" ] || fail "fresh install sets ARTEX_GATEWAY_TOKEN"
pass "fresh install.sh"
echo "ALL DEPLOY/UPGRADE/ROLLBACK TESTS PASSED"
+8 -14
View File
@@ -11,7 +11,6 @@ import (
"sync"
"time"
"github.com/Autumn-27/artex/internal/sandbox"
"github.com/Autumn-27/artex/selfupdate"
)
@@ -215,21 +214,16 @@ func (s *Server) updateCheck(w http.ResponseWriter, r *http.Request) {
if selfupdate.InDocker() {
mode = "docker"
}
deployEdition := "standalone"
if mgr := sandbox.Default(); mgr != nil && mgr.Enabled() {
deployEdition = "sandbox"
}
boot := bootUpdateState()
out := map[string]any{
"current": current,
"mode": mode,
"deploy_edition": deployEdition,
"os": runtime.GOOS,
"arch": runtime.GOARCH,
"has_backup": selfupdate.HasBackup(),
"repo": selfupdate.Repo,
"boot_notice": boot.Detail,
"rolled_back": boot.RolledBack,
"current": current,
"mode": mode,
"os": runtime.GOOS,
"arch": runtime.GOARCH,
"has_backup": selfupdate.HasBackup(),
"repo": selfupdate.Repo,
"boot_notice": boot.Detail,
"rolled_back": boot.RolledBack,
}
// 顶栏提示走缓存(默认);用户点"检查更新"时带 force=1 强制回源。
-65
View File
@@ -2,14 +2,11 @@ package server
import (
"context"
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/Autumn-27/artex/internal/sandbox"
"github.com/Autumn-27/artex/selfupdate"
)
@@ -199,65 +196,3 @@ func TestUpdateSettingsValidation(t *testing.T) {
}
}
}
func TestUpdateCheckReportsDeployEdition(t *testing.T) {
origMgr := sandbox.Default()
origFetch := relCache.fetch
t.Cleanup(func() {
sandbox.SetDefault(origMgr)
relCache.mu.Lock()
relCache.fetch = origFetch
relCache.at = time.Time{}
relCache.mu.Unlock()
})
relCache.mu.Lock()
relCache.fetch = func(context.Context, *http.Client) (*selfupdate.Release, error) {
return &selfupdate.Release{TagName: "v0.3.33"}, nil
}
relCache.at = time.Time{}
relCache.mu.Unlock()
s := &Server{m: &Manager{}}
// Local/standalone mode
localMgr, err := sandbox.New(sandbox.Config{Mode: sandbox.ModeLocal, DataDir: t.TempDir()})
if err != nil {
t.Fatalf("sandbox.New local: %v", err)
}
sandbox.SetDefault(localMgr)
rec := httptest.NewRecorder()
s.updateCheck(rec, httptest.NewRequest(http.MethodGet, "/api/update/check", nil))
if rec.Code != http.StatusOK {
t.Fatalf("updateCheck local status=%d body=%s", rec.Code, rec.Body.String())
}
var resp map[string]any
if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
t.Fatalf("decode local resp: %v", err)
}
if resp["deploy_edition"] != "standalone" {
t.Fatalf("expected deploy_edition=standalone, got %v", resp["deploy_edition"])
}
// Docker sandbox mode
dockerMgr, err := sandbox.New(sandbox.Config{
Mode: sandbox.ModeDocker,
DockerHost: "http://127.0.0.1:2375",
DataDir: t.TempDir(),
})
if err != nil {
t.Fatalf("sandbox.New docker: %v", err)
}
sandbox.SetDefault(dockerMgr)
rec2 := httptest.NewRecorder()
s.updateCheck(rec2, httptest.NewRequest(http.MethodGet, "/api/update/check", nil))
if rec2.Code != http.StatusOK {
t.Fatalf("updateCheck docker status=%d body=%s", rec2.Code, rec2.Body.String())
}
var resp2 map[string]any
if err := json.Unmarshal(rec2.Body.Bytes(), &resp2); err != nil {
t.Fatalf("decode docker resp: %v", err)
}
if resp2["deploy_edition"] != "sandbox" {
t.Fatalf("expected deploy_edition=sandbox, got %v", resp2["deploy_edition"])
}
}
+43 -146
View File
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
# ARTEX 升级、双版本迁移与回滚脚本:
# - 升级当前部署形态(继续使用单容器版 standalone,或升级沙箱隔离版 sandbox)
# - 从上一版本单容器部署无缝迁移至当前沙箱隔离版(保留 pgdata / ./data / ./skills)
# - 从沙箱隔离版切回单容器版(优雅停止沙箱与透明网关,清理 TUN/iptables 规则)
# ARTEX 升级与回滚脚本:
# - 升级 Docker 部署(保留 pgdata / ./data / ./skills,兼容旧版自动校准目录权限)
# - 回滚到任意历史部署快照(本地固定镜像 ID,离线/覆盖 latest 也可 100% 精准回滚;健康检查失败自动回滚)
# - 本地 Go 编译更新(自动备份 ./artex -> ./artex.old 支持回滚)
set -euo pipefail
@@ -26,105 +24,28 @@ require_docker_env(){
[ -f .env ] || die "未找到 .env,请先运行 ./install.sh 完成首次部署"
}
# ── ① 原地升级当前形态(保持 standalone 或 sandbox)──────────────────────
update_docker_in_place(){
local target_ed="${1:-}" tag="${2:-}" skip_db="${3:-0}"
# ── ① Docker 升级(自动快照 + 失败自动回滚)─────────────────────────────
update_docker(){
local tag="${1:-}" skip_db="${2:-0}"
require_docker_env
preflight_docker
local cur_ed
cur_ed="$(detect_current_edition .env)"
if [ -z "$target_ed" ]; then
if [ "$cur_ed" = "sandbox" ] || [ "$cur_ed" = "standalone" ]; then
target_ed="$cur_ed"
else
target_ed="sandbox"
fi
fi
info "当前部署形态:$(edition_label "$cur_ed") → 原地升级:$(edition_label "$target_ed")"
if [ -z "$tag" ] && [ "${ARTEX_NONINTERACTIVE:-0}" != "1" ]; then
if [ "$target_ed" = "standalone" ]; then
tag="$(ask '目标镜像 tag(回车沿用 .env;如 standalone / v0.3.33 / v0.3.32)' '')"
else
tag="$(ask '目标镜像 tag(回车沿用 .env / latest;如 v0.3.33)' '')"
fi
tag="$(ask '目标镜像 tag(回车沿用 .env / latest;如 v0.3.33)' '')"
fi
info "正在创建升级前部署快照(用于失败自动回滚或手动回滚)…"
local snap_id
snap_id="$(create_deploy_snapshot "upgrade-${target_ed}" "$skip_db")"
snap_id="$(create_deploy_snapshot "upgrade" "$skip_db")"
ok "已创建回滚快照:${snap_id}"
if [ "$target_ed" = "sandbox" ]; then
prepare_env_for_sandbox "$tag" .env
else
prepare_env_for_standalone "$tag" .env
fi
deploy_edition_with_rollback "$target_ed" "$snap_id"
local compose_file
compose_file="$(compose_file_for_edition "$target_ed")"
ok "升级完成($(edition_label "$target_ed"))→ http://localhost:8787"
info "如需回滚到升级前状态:./update.sh --rollback ${snap_id}"
info "查看日志:docker compose -f ${compose_file} logs -f artex"
}
# ── ② 从单容器版迁移至沙箱隔离版(Standalone -> Sandbox)────────────────
migrate_to_sandbox(){
local tag="${1:-}" skip_db="${2:-0}"
require_docker_env
preflight_sandbox
local cur_ed
cur_ed="$(detect_current_edition .env)"
if [ "$cur_ed" = "sandbox" ]; then
info "当前已是沙箱隔离版,将直接执行沙箱版配置校准与升级…"
else
info "准备从 $(edition_label "$cur_ed") 迁移至 $(edition_label sandbox)(pgdata / ./data / ./skills 全量保留)"
fi
if [ -z "$tag" ] && [ "${ARTEX_NONINTERACTIVE:-0}" != "1" ]; then
tag="$(ask '目标沙箱版镜像 tag(回车使用 latest)' '')"
fi
info "正在创建迁移前完整快照(含 .env / 当前镜像 ID / PostgreSQL 备份)…"
local snap_id
snap_id="$(create_deploy_snapshot "migrate-to-sandbox" "$skip_db")"
ok "已创建回滚快照:${snap_id}"
prepare_env_for_sandbox "$tag" .env
prepare_env_for_docker "$tag" .env
prepare_migrated_workspaces ./data
deploy_edition_with_rollback sandbox "$snap_id"
ok "已成功迁移至沙箱隔离版 → http://localhost:8787"
info "查看主服务日志:docker compose logs -f artex"
info "查看透明网关日志:docker compose logs -f artex-gateway"
info "若需无损回滚回单容器版:./update.sh --rollback ${snap_id}"
}
# ── ③ 从沙箱隔离版切回单容器版(Sandbox -> Standalone)──────────────────
switch_to_standalone(){
local tag="${1:-}" skip_db="${2:-0}"
require_docker_env
if [ -z "$tag" ] && [ "${ARTEX_NONINTERACTIVE:-0}" != "1" ]; then
tag="$(ask '目标单容器版镜像 tag(回车使用 standalone;回退历史版本可填如 v0.3.32)' '')"
fi
info "正在创建切换前部署快照…"
local snap_id
snap_id="$(create_deploy_snapshot "switch-to-standalone" "$skip_db")"
ok "已创建回滚快照:${snap_id}"
stop_sandbox_runtime
prepare_env_for_standalone "$tag" .env
deploy_edition_with_rollback standalone "$snap_id"
ok "已切换至单容器版(standalone)→ http://localhost:8787"
info "查看日志:docker compose -f ${COMPOSE_STANDALONE_FILE} logs -f artex"
info "若需恢复回沙箱隔离版:./update.sh --rollback ${snap_id}"
deploy_with_rollback "$snap_id"
ok "升级完成 → http://localhost:8787"
info "如需回滚到升级前状态:./update.sh --rollback ${snap_id}"
info "查看日志:docker compose -f ${COMPOSE_FILE} logs -f artex"
}
# ── ④ 回滚到历史部署快照 ────────────────────────────────────────────────
@@ -184,27 +105,23 @@ usage(){
用法: ./update.sh [动作] [选项]
动作(不传则进入交互菜单):
--upgrade 升级当前部署形态(保持 standalone 或 sandbox 不变)
--migrate-sandbox 从上一版本单容器部署迁移至当前沙箱隔离版(保留全部数据)
--switch-standalone 从沙箱隔离版切换回单容器版(自动清理沙箱与透明网关规则)
--rollback [SNAPSHOT_ID] 回滚到最新或指定的历史部署快照
--list-snapshots 列出所有可用的部署回滚快照
--local 本地 Go 重新编译更新
--upgrade 升级 Docker 部署(自动创建回滚快照)
--rollback [SNAPSHOT_ID] 回滚到最新或指定的历史部署快照
--list-snapshots 列出所有可用的部署回滚快照
--local 本地 Go 重新编译更新
选项:
--edition sandbox|standalone 配合 --upgrade 指定升级目标形态
--tag <TAG> 指定目标镜像版本 tag(如 v0.3.33 / v0.3.32 / latest / standalone)
--restore-db 配合 --rollback 同时恢复快照中的 PostgreSQL 备份
--no-db-backup 创建快照时跳过 pg_dump
--skip-pull 跳过镜像拉取
--skip-git-pull 跳过 git pull
-y, --yes 非交互模式
-h, --help 显示本帮助
--tag <TAG> 指定目标镜像版本 tag(如 v0.3.33 / latest)
--restore-db 配合 --rollback 同时恢复快照中的 PostgreSQL 备份
--no-db-backup 创建快照时跳过 pg_dump
--skip-pull 跳过镜像拉取
--skip-git-pull 跳过 git pull
-y, --yes 非交互模式
-h, --help 显示本帮助
USAGE
}
ACTION=""
OPT_EDITION=""
OPT_TAG=""
OPT_SNAP=""
OPT_RESTORE_DB=0
@@ -212,9 +129,7 @@ OPT_SKIP_DB=0
while [ "$#" -gt 0 ]; do
case "$1" in
--upgrade) ACTION="upgrade" ;;
--migrate-sandbox) ACTION="migrate-sandbox" ;;
--switch-standalone) ACTION="switch-standalone" ;;
--upgrade) ACTION="upgrade" ;;
--rollback)
ACTION="rollback"
if [ "${2:-}" != "" ] && [ "${2#-}" = "${2}" ]; then
@@ -222,17 +137,16 @@ while [ "$#" -gt 0 ]; do
OPT_SNAP="$1"
fi
;;
--list-snapshots) ACTION="list-snapshots" ;;
--local) ACTION="local" ;;
--edition) shift; [ "$#" -gt 0 ] || die "--edition 需要参数"; OPT_EDITION="$1" ;;
--tag) shift; [ "$#" -gt 0 ] || die "--tag 需要参数"; OPT_TAG="$1" ;;
--restore-db) OPT_RESTORE_DB=1 ;;
--no-db-backup) OPT_SKIP_DB=1 ;;
--skip-pull) export ARTEX_SKIP_PULL=1 ;;
--skip-git-pull) export ARTEX_SKIP_GIT_PULL=1 ;;
-y|--yes) export ARTEX_NONINTERACTIVE=1 ;;
-h|--help) usage; exit 0 ;;
*) die "未知参数:$1(使用 --help 查看帮助)" ;;
--list-snapshots) ACTION="list-snapshots" ;;
--local) ACTION="local" ;;
--tag) shift; [ "$#" -gt 0 ] || die "--tag 需要参数"; OPT_TAG="$1" ;;
--restore-db) OPT_RESTORE_DB=1 ;;
--no-db-backup) OPT_SKIP_DB=1 ;;
--skip-pull) export ARTEX_SKIP_PULL=1 ;;
--skip-git-pull) export ARTEX_SKIP_GIT_PULL=1 ;;
-y|--yes) export ARTEX_NONINTERACTIVE=1 ;;
-h|--help) usage; exit 0 ;;
*) die "未知参数:$1(使用 --help 查看帮助)" ;;
esac
shift
done
@@ -240,17 +154,7 @@ done
case "$ACTION" in
upgrade)
sync_repo
update_docker_in_place "$OPT_EDITION" "$OPT_TAG" "$OPT_SKIP_DB"
exit 0
;;
migrate-sandbox)
sync_repo
migrate_to_sandbox "$OPT_TAG" "$OPT_SKIP_DB"
exit 0
;;
switch-standalone)
sync_repo
switch_to_standalone "$OPT_TAG" "$OPT_SKIP_DB"
update_docker "$OPT_TAG" "$OPT_SKIP_DB"
exit 0
;;
rollback)
@@ -268,22 +172,15 @@ case "$ACTION" in
;;
esac
CUR_ED="$(detect_current_edition .env)"
echo "=========================================="
echo " ARTEX 升级 / 迁移 / 回滚"
echo " 当前检测到形态:$(edition_label "$CUR_ED")"
echo "------------------------------------------"
echo " 1) 升级当前版本(保持 $(edition_label "$CUR_ED"))"
echo " 2) 从单容器版迁移至沙箱隔离版(保留数据 + 自动快照)"
echo " 3) 从沙箱隔离版切换回单容器版(清理网关 + 自动快照)"
echo " 4) 回滚到上一部署快照(支持跨形态无损回滚)"
echo " 5) 本地更新(Go 重新编译)"
echo " ARTEX 升级与回滚"
echo " 1) Docker 升级(自动创建回滚快照)"
echo " 2) 回滚到历史部署快照"
echo " 3) 本地更新(Go 重新编译)"
echo "=========================================="
case "$(ask '选择' 1)" in
1) sync_repo; update_docker_in_place "$OPT_EDITION" "$OPT_TAG" "$OPT_SKIP_DB" ;;
2) sync_repo; migrate_to_sandbox "$OPT_TAG" "$OPT_SKIP_DB" ;;
3) sync_repo; switch_to_standalone "$OPT_TAG" "$OPT_SKIP_DB" ;;
4) interactive_rollback "$OPT_SNAP" "$OPT_RESTORE_DB" ;;
5) sync_repo; update_local ;;
1) sync_repo; update_docker "$OPT_TAG" "$OPT_SKIP_DB" ;;
2) interactive_rollback "$OPT_SNAP" "$OPT_RESTORE_DB" ;;
3) sync_repo; update_local ;;
*) die "无效选择" ;;
esac
@@ -8,10 +8,21 @@ import {
ExternalLinkIcon,
RefreshCwIcon,
RotateCcwIcon,
ShieldCheckIcon,
TriangleAlertIcon,
} from "lucide-react";
import { toast } from "sonner";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
@@ -45,6 +56,7 @@ export function UpdateCard() {
const { t, liveT } = useLiveTranslation();
const [info, setInfo] = React.useState<UpdateCheck | null>(null);
const [checking, setChecking] = React.useState(true);
const [confirmOpen, setConfirmOpen] = React.useState(false);
const [progress, setProgress] = React.useState<UpdateProgress | null>(null);
// 与 progress 分开:暂存完成后进程就没了,SSE 会断,此时要切到轮询 /api/version。
const [restarting, setRestarting] = React.useState(false);
@@ -186,25 +198,10 @@ export function UpdateCard() {
[waitForNewVersion, liveT],
);
const isSandboxDocker = info?.mode === "docker" && info?.deploy_edition === "sandbox";
let editionBadgeLabel = t("settings.standalone");
if (info?.mode === "docker") {
editionBadgeLabel = isSandboxDocker ? t("settings.dockerSandboxEdition") : t("settings.dockerStandaloneEdition");
}
const doUpdate = () => {
const executeUpdate = () => {
if (!info) return;
const from = info.current;
let dockerWarn = "";
if (info.mode === "docker") {
dockerWarn = isSandboxDocker
? t("settings.sandboxUpdateWarning")
: t("settings.dockerUpdateWarningStart") + t("settings.dockerUpdateWarningEnd");
}
const ok = window.confirm(
t("settings.confirmUpdateVersion", { version: info.latest }) + t("settings.updateInterruptWarning") + dockerWarn,
);
if (!ok) return;
setConfirmOpen(false);
setBusy(true);
setProgress({ phase: "downloading", percent: 0, message: t("settings.preparing") });
api
@@ -221,9 +218,10 @@ export function UpdateCard() {
const doRollback = () => {
if (!info) return;
const confirmMsg = isSandboxDocker
? t("settings.confirmRollback") + t("settings.sandboxRollbackWarning")
: t("settings.confirmRollback");
const confirmMsg =
info.mode === "docker"
? t("settings.confirmRollback") + t("settings.dockerRollbackWarning")
: t("settings.confirmRollback");
if (!window.confirm(confirmMsg)) return;
const from = info.current;
setBusy(true);
@@ -303,7 +301,7 @@ export function UpdateCard() {
<Badge variant="outline" className="font-mono">
{info.os}/{info.arch}
</Badge>
<Badge variant="outline">{editionBadgeLabel}</Badge>
<Badge variant="outline">{info.mode === "docker" ? "Docker" : t("settings.standalone")}</Badge>
</>
)}
{info?.latest && (
@@ -378,23 +376,11 @@ export function UpdateCard() {
{info?.mode === "docker" && (info.has_update || info.has_backup) && (
<p className="text-muted-foreground text-xs">
{isSandboxDocker ? (
<>
{t("settings.sandboxUpdateHelpStart")}
<span className="font-mono"> ./update.sh </span>
{t("settings.sandboxUpdateHelpMiddle")}
<span className="font-mono"> ./update.sh --rollback</span>
{t("settings.sandboxUpdateHelpEnd")}
</>
) : (
<>
{t("settings.dockerUpdateHelpStart")}
<span className="font-mono"> docker compose up -d </span>
{t("settings.dockerUpdateHelpMiddle")}
<span className="font-mono"> ./update.sh</span>
{t("settings.dockerUpdateHelpEnd")}
</>
)}
{t("settings.dockerUpdateHelpStart")}
<span className="font-mono"> ./update.sh </span>
{t("settings.dockerUpdateHelpMiddle")}
<span className="font-mono"> ./update.sh --rollback</span>
{t("settings.dockerUpdateHelpEnd")}
</p>
)}
@@ -433,7 +419,7 @@ export function UpdateCard() {
</Button>
<Button
size="sm"
onClick={doUpdate}
onClick={() => setConfirmOpen(true)}
disabled={
checking ||
networkDirty ||
@@ -465,6 +451,32 @@ export function UpdateCard() {
{t("settings.restartScriptHelpEnd")}
</p>
</CardContent>
<AlertDialog open={confirmOpen} onOpenChange={setConfirmOpen}>
<AlertDialogContent className="sm:max-w-md">
<AlertDialogHeader>
<AlertDialogTitle>{t("settings.confirmUpdateVersion", { version: info?.latest ?? "" })}</AlertDialogTitle>
<AlertDialogDescription asChild>
<div className="space-y-2.5 text-left">
<p>{t("settings.updateInterruptWarning")}</p>
<div className="space-y-1 rounded-md border border-amber-500/40 bg-amber-500/10 p-3 text-amber-800 text-xs dark:text-amber-300">
<p className="flex items-center gap-1.5 font-medium">
<ShieldCheckIcon className="size-4 shrink-0" />
{t("settings.standaloneToSandboxTitle")}
</p>
<p className="leading-relaxed">{t("settings.standaloneToSandboxWarning")}</p>
</div>
{info?.mode === "docker" && (
<p className="text-muted-foreground text-xs">{t("settings.dockerUpdateWarning")}</p>
)}
</div>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t("common.cancel")}</AlertDialogCancel>
<AlertDialogAction onClick={executeUpdate}>{t("settings.confirmUpgradeAction")}</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</Card>
);
}
+18 -34
View File
@@ -677,26 +677,24 @@ export const settingsMessages = {
"等待服务重启超时。请检查后端日志,或确认 artex 是通过 start.sh / start.bat 启动的。",
"Timed out waiting for the service to restart. Check the backend logs and confirm ARTEX was started with start.sh / start.bat.",
],
"settings.confirmUpdateVersion": ["确定更新到 {{version}}?\n\n", "Update to {{version}}?\n\n"],
"settings.confirmUpdateVersion": ["确定更新到 {{version}}?", "Update to {{version}}?"],
"settings.updateInterruptWarning": [
"更新会重启程序,正在运行的任务会被中断。\n",
"The application will restart and running tasks will be interrupted.\n",
"更新会重启程序,正在运行的任务会被中断。",
"The application will restart and running tasks will be interrupted.",
],
"settings.dockerUpdateWarningStart": [
"\n注意:容器内更新只替换程序本身,不会更新镜像里的 playwright / nmap 等工具链;",
"\nNote: Updating inside a container replaces only ARTEX, not tools such as playwright / nmap in the image. ",
"settings.standaloneToSandboxTitle": ["单容器版(standalone)→ 沙箱隔离版(sandbox)", "Standalone → Sandbox"],
"settings.standaloneToSandboxWarning": [
"此次升级将从单容器版(standalone)升级至沙箱隔离版(sandbox),升级后无法回滚,但会显著提高运行安全性。",
"This upgrade migrates from Standalone edition to Sandbox edition. It cannot be rolled back afterwards, but significantly improves security.",
],
"settings.dockerUpdateWarningEnd": [
"若新版本依赖新工具或需跨版本迁移,请改用 ./update.sh。",
"Use ./update.sh if the new version requires updated tools or edition migration.",
"settings.confirmUpgradeAction": ["确认升级", "Confirm upgrade"],
"settings.dockerUpdateWarning": [
"注意:Docker 容器内更新仅替换 artex 主控程序,不会同步更新 artex-gateway 与 artex-sandbox 镜像。推荐使用 ./update.sh 完成整套升级。",
"Note: In-app Docker updates replace only the artex control-plane binary and do not update artex-gateway or artex-sandbox images. Use ./update.sh for a full upgrade.",
],
"settings.sandboxUpdateWarning": [
"\n注意:当前为沙箱隔离版,容器内更新仅替换 artex 主控程序,不会同步更新 artex-gateway 透明网关与 artex-sandbox 沙箱镜像。推荐使用 ./update.sh 完成整套升级并自动生成回滚快照。",
"\nNote: In Sandbox edition, in-app updates replace only the artex control-plane binary and do not update artex-gateway or artex-sandbox images. Use ./update.sh for a full-stack upgrade with automatic rollback snapshots.",
],
"settings.sandboxRollbackWarning": [
"\n\n注意:当前为沙箱隔离版,页面回滚仅回退 artex 主控程序,不会回滚 artex-gateway 与 artex-sandbox 镜像。如需整套回滚或切回单容器版,请执行 ./update.sh --rollback。",
"\n\nNote: In Sandbox edition, in-app rollback reverts only the artex control-plane binary, not artex-gateway or artex-sandbox images. Run ./update.sh --rollback for a full-stack rollback or to switch back to standalone.",
"settings.dockerRollbackWarning": [
"\n\n注意:Docker 页面回滚仅回退 artex 主控程序,不会回滚 artex-gateway 与 artex-sandbox 镜像。如需整套回滚,请执行 ./update.sh --rollback。",
"\n\nNote: In-app Docker rollback reverts only the artex control-plane binary, not artex-gateway or artex-sandbox images. Run ./update.sh --rollback for a full rollback.",
],
"settings.preparing": ["准备中…", "Preparing…"],
"settings.updateStartFailedPrefix": ["启动更新失败:", "Could not start update: "],
@@ -722,8 +720,6 @@ export const settingsMessages = {
],
"settings.currentVersion": ["当前版本", "Current version"],
"settings.standalone": ["独立程序", "Standalone"],
"settings.dockerSandboxEdition": ["Docker · 沙箱隔离版", "Docker · Sandbox"],
"settings.dockerStandaloneEdition": ["Docker · 单容器版", "Docker · Standalone"],
"settings.latestVersion": ["最新版本", "Latest version"],
"settings.changelog": ["更新日志", "Changelog"],
"settings.githubUnavailablePrefix": ["无法连接 GitHub:", "Unable to connect to GitHub: "],
@@ -741,23 +737,11 @@ export const settingsMessages = {
],
"settings.upToDateDetail": ["当前已是最新版本。", "You are using the latest version."],
"settings.dockerUpdateHelpStart": [
"Docker 下的更新只替换程序本身,不更新镜像里的 playwright / nmap 等工具链,且",
"Updates in Docker replace only ARTEX, not tools such as playwright / nmap in the image. Running ",
"Docker 下页面一键更新/回滚仅作用于 artex 主控程序,不会同步切换 artex-gateway 与 artex-sandbox 镜像;完整升级请执行",
"In Docker, in-app update/rollback affects only the artex control-plane binary, not artex-gateway or artex-sandbox images. For a full upgrade, run ",
],
"settings.dockerUpdateHelpMiddle": [
"重建容器后会退回镜像自带的版本。需要连镜像一起升级、迁移到沙箱隔离版或回滚,请执行",
" to recreate the container restores the version in the image. To upgrade images, migrate to Sandbox edition, or roll back, run ",
],
"settings.dockerUpdateHelpEnd": [
"(回滚执行 ./update.sh --rollback)。",
" (or ./update.sh --rollback to roll back).",
],
"settings.sandboxUpdateHelpStart": [
"沙箱隔离版下页面一键更新/回滚仅作用于 artex 主控程序,不会同步切换 artex-gateway 与 artex-sandbox 镜像;完整升级、切换单容器版请执行",
"In Sandbox edition, in-app update/rollback affects only the artex control-plane binary, not artex-gateway or artex-sandbox images. For full-stack upgrades or edition switching, run ",
],
"settings.sandboxUpdateHelpMiddle": [",整套回滚请执行", ", and for full-stack rollback run "],
"settings.sandboxUpdateHelpEnd": ["。", "."],
"settings.dockerUpdateHelpMiddle": [",整套回滚请执行", ", and for a full rollback run "],
"settings.dockerUpdateHelpEnd": ["。", "."],
"settings.restarting": [
"正在重启并应用新版本,请稍候(页面会自动刷新)…",
"Restarting and applying the new version. Please wait; the page will reload automatically…",
-2
View File
@@ -1797,8 +1797,6 @@ export interface UpdateCheck {
current: string;
/** 运行形态。docker 下换装只作用于容器可写层,重建容器会退回镜像版本。 */
mode: "docker" | "binary";
/** 部署架构:sandbox(多容器沙箱隔离版)或 standalone(单容器/独立程序版)。 */
deploy_edition?: "sandbox" | "standalone";
os: string;
arch: string;
repo: string;