feat(dobotai): containerize test runtime and admin bootstrap
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
container_dir="/opt/dobotai-test/container"
|
||||
compose_file="$container_dir/compose.yaml"
|
||||
runtime_env="$container_dir/runtime.env"
|
||||
legacy_service="dobotai-test.service"
|
||||
health_url="http://127.0.0.1:8090/healthz"
|
||||
|
||||
if [[ ! -r "$compose_file" || ! -r "$runtime_env" ]]; then
|
||||
echo "容器运行文件未安装。请先部署 dobotai-dingtalk。" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
legacy_was_active=false
|
||||
if systemctl is-active --quiet "$legacy_service"; then
|
||||
legacy_was_active=true
|
||||
systemctl stop "$legacy_service"
|
||||
fi
|
||||
|
||||
rollback() {
|
||||
docker compose --env-file "$runtime_env" -f "$compose_file" down --remove-orphans >/dev/null 2>&1 || true
|
||||
if [[ "$legacy_was_active" == "true" ]]; then
|
||||
systemctl start "$legacy_service" || true
|
||||
fi
|
||||
}
|
||||
trap rollback ERR
|
||||
|
||||
docker compose --env-file "$runtime_env" -f "$compose_file" up -d --no-build --force-recreate
|
||||
for _ in $(seq 1 30); do
|
||||
if curl --noproxy '*' --fail --silent --max-time 2 "$health_url" >/dev/null; then
|
||||
systemctl disable "$legacy_service" >/dev/null
|
||||
trap - ERR
|
||||
echo "DobotAI 容器已启动:dobotai-dingtalk"
|
||||
exit 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "DobotAI 容器健康检查失败,已回滚到原生服务。" >&2
|
||||
exit 1
|
||||
Reference in New Issue
Block a user