feat: add cloud deploy fallback runtime

This commit is contained in:
Codex
2026-03-23 13:25:56 +08:00
parent 3ff757e22d
commit bc04c439fb
7 changed files with 120 additions and 6 deletions

View File

@@ -8,4 +8,4 @@ export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
export AG_SERVER_SKILL="${AG_SERVER_SKILL:-$CODEX_HOME/skills/ai-glasses-server-debug}"
export AG_SERVER="${AG_SERVER:-$AG_SERVER_SKILL/scripts/server_ssh.sh}"
"$AG_SERVER" exec "set -euo pipefail; cd $(printf '%q' "$remote_dir"); sudo docker compose -f compose.cloud.yaml -p boss logs --tail $(printf '%q' "$tail_lines")"
"$AG_SERVER" exec "set -euo pipefail; cd $(printf '%q' "$remote_dir"); if sudo docker ps --format '{{.Names}}' | grep -qx 'boss-control-plane'; then sudo docker compose -f compose.cloud.yaml -p boss logs --tail $(printf '%q' "$tail_lines"); else tail -n $(printf '%q' "$tail_lines") .boss-data/server.log; fi"

View File

@@ -7,4 +7,4 @@ export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
export AG_SERVER_SKILL="${AG_SERVER_SKILL:-$CODEX_HOME/skills/ai-glasses-server-debug}"
export AG_SERVER="${AG_SERVER:-$AG_SERVER_SKILL/scripts/server_ssh.sh}"
"$AG_SERVER" exec "set -euo pipefail; cd $(printf '%q' "$remote_dir"); sudo docker compose -f compose.cloud.yaml -p boss ps; echo '---'; curl -fsS http://127.0.0.1:43210/api/health"
"$AG_SERVER" exec "set -euo pipefail; cd $(printf '%q' "$remote_dir"); if sudo docker ps --format '{{.Names}}' | grep -qx 'boss-control-plane'; then sudo docker compose -f compose.cloud.yaml -p boss ps; echo '---'; curl -fsS http://127.0.0.1:43210/api/health; else ./scripts/server_status.sh; fi"

View File

@@ -4,6 +4,7 @@ set -euo pipefail
branch="${1:-main}"
remote_dir="${BOSS_REMOTE_DIR:-/home/ubuntu/boss}"
remote_repo="${BOSS_REMOTE_REPO:-https://git.hyzq.site/krisolo/boss.git}"
deploy_mode="${BOSS_CLOUD_DEPLOY_MODE:-auto}"
export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
export AG_SERVER_SKILL="${AG_SERVER_SKILL:-$CODEX_HOME/skills/ai-glasses-server-debug}"
@@ -20,6 +21,7 @@ set -euo pipefail
REMOTE_DIR=$(printf '%q' "$remote_dir")
REMOTE_REPO=$(printf '%q' "$remote_repo")
BRANCH=$(printf '%q' "$branch")
DEPLOY_MODE=$(printf '%q' "$deploy_mode")
mkdir -p "\$REMOTE_DIR"
@@ -33,12 +35,35 @@ git fetch origin "\$BRANCH"
git checkout "\$BRANCH"
git reset --hard "origin/\$BRANCH"
sudo docker compose -f compose.cloud.yaml -p boss up -d --build --remove-orphans
docker_ok=0
if [[ "\$DEPLOY_MODE" != "node" ]]; then
if sudo docker compose -f compose.cloud.yaml -p boss up -d --build --remove-orphans; then
docker_ok=1
elif [[ "\$DEPLOY_MODE" == "docker" ]]; then
exit 1
fi
fi
if [[ "\$docker_ok" -eq 1 ]]; then
echo "__BOSS_DEPLOY_OK__"
echo "mode=docker"
sudo docker compose -f compose.cloud.yaml -p boss ps
sleep 3
curl -fsS http://127.0.0.1:43210/api/health
exit 0
fi
if ! command -v node >/dev/null 2>&1 || ! command -v npm >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y nodejs npm
fi
npm install
npm run build
PORT=43210 BOSS_DATA_FILE=.boss-data/cloud-store.json ./scripts/server_start.sh
echo "__BOSS_DEPLOY_OK__"
sudo docker compose -f compose.cloud.yaml -p boss ps
sleep 3
curl -fsS http://127.0.0.1:43210/api/health
echo "mode=node"
./scripts/server_status.sh
EOF
)

39
scripts/server_start.sh Executable file
View File

@@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -euo pipefail
port="${PORT:-43210}"
data_dir="${BOSS_DATA_DIR:-.boss-data}"
data_file="${BOSS_DATA_FILE:-$data_dir/server-store.json}"
pid_file="${BOSS_PID_FILE:-$data_dir/server.pid}"
log_file="${BOSS_LOG_FILE:-$data_dir/server.log}"
mkdir -p "$data_dir"
if [[ -f "$pid_file" ]]; then
existing_pid="$(cat "$pid_file")"
if [[ -n "$existing_pid" ]] && kill -0 "$existing_pid" 2>/dev/null; then
kill "$existing_pid"
for _ in {1..20}; do
if ! kill -0 "$existing_pid" 2>/dev/null; then
break
fi
sleep 1
done
fi
rm -f "$pid_file"
fi
nohup env PORT="$port" BOSS_DATA_FILE="$data_file" node dist/server.js >>"$log_file" 2>&1 < /dev/null &
echo $! > "$pid_file"
for _ in {1..30}; do
if curl -fsS "http://127.0.0.1:${port}/api/health" >/dev/null 2>&1; then
echo "Boss server started on :${port}"
exit 0
fi
sleep 1
done
echo "Boss server failed to become healthy. Recent logs:" >&2
tail -n 80 "$log_file" >&2 || true
exit 1

24
scripts/server_status.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
port="${PORT:-43210}"
data_dir="${BOSS_DATA_DIR:-.boss-data}"
pid_file="${BOSS_PID_FILE:-$data_dir/server.pid}"
log_file="${BOSS_LOG_FILE:-$data_dir/server.log}"
if [[ -f "$pid_file" ]]; then
pid="$(cat "$pid_file")"
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
echo "Boss process running with PID $pid"
else
echo "Boss PID file exists but process is not running."
fi
else
echo "Boss process is not running."
fi
echo "---"
curl -fsS "http://127.0.0.1:${port}/api/health" || true
echo
echo "---"
tail -n 40 "$log_file" 2>/dev/null || true

24
scripts/server_stop.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
data_dir="${BOSS_DATA_DIR:-.boss-data}"
pid_file="${BOSS_PID_FILE:-$data_dir/server.pid}"
if [[ ! -f "$pid_file" ]]; then
echo "No Boss PID file found."
exit 0
fi
pid="$(cat "$pid_file")"
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
kill "$pid"
for _ in {1..20}; do
if ! kill -0 "$pid" 2>/dev/null; then
break
fi
sleep 1
done
fi
rm -f "$pid_file"
echo "Boss server stopped."