Files
ai_academy/.gitea/workflows/deploy-hxtesting.yml
T

62 lines
2.3 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# hxtesting 测试服自动部署
# 触发:push 到 main(同事更新代码后自动构建部署),也支持手动触发
# 执行:hxtesting 宿主上的 gitea-runner(label=deploy-host,host 模式)
# 说明:构建 app/frontend 镜像并顶替同名 latest tag,docreader/sandbox 等沿用官方镜像;
# 每次构建额外打 sha-<短提交> tag 便于回滚。
name: deploy-hxtesting
on:
push:
branches: [main]
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: deploy-host
timeout-minutes: 40
env:
DEPLOY_DIR: /home/lisq/services/ai_academy
steps:
- name: 同步代码
run: |
set -e
cd "$DEPLOY_DIR"
git fetch origin main
git reset --hard origin/main
echo "GIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_ENV"
echo "当前部署提交: $(git log --oneline -1)"
- name: 构建镜像(app + frontend,ARM64 原生)
run: |
set -e
cd "$DEPLOY_DIR"
# WITH_ANYDOC=0:跳过 anydoc 解析引擎(Rust 工具链需外网,hxtesting 不可达;
# 文档解析由 docreader 容器承担,测试环境不受影响)
WITH_ANYDOC=0 bash scripts/build_images.sh -p
WITH_ANYDOC=0 bash scripts/build_images.sh -f
docker tag wechatopenai/weknora-app:latest wechatopenai/weknora-app:sha-${GIT_SHA}
docker tag wechatopenai/weknora-ui:latest wechatopenai/weknora-ui:sha-${GIT_SHA}
# 仅清理本项目旧版本镜像(保留最近 5 个 sha-* 备回滚),不影响服务器上其他项目
for repo in wechatopenai/weknora-app wechatopenai/weknora-ui; do
docker images --format '{{.Tag}}' "$repo" | grep '^sha-' | tail -n +6 \
| xargs -r -I{} docker rmi "$repo:{}" >/dev/null 2>&1 || true
done
- name: 部署(compose up)
run: |
set -e
cd "$DEPLOY_DIR"
docker compose up -d --remove-orphans
- name: 健康检查
run: |
set -e
sleep 20
if curl -fsS -o /dev/null --max-time 10 http://127.0.0.1/; then
echo "WEB_OK: http://hxtesting/ 已可访问 (sha-${GIT_SHA})"
else
echo "健康检查失败,容器状态:"
cd "$DEPLOY_DIR" && docker compose ps
exit 1
fi