fix: stabilize device debugging and cloud deploy
This commit is contained in:
@@ -9,12 +9,25 @@ 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}"
|
||||
export AG_SERVER="${AG_SERVER:-$AG_SERVER_SKILL/scripts/server_ssh.sh}"
|
||||
KEYCHAIN_SERVICE="${AI_GLASSES_KEYCHAIN_SERVICE:-ai-glasses-debug-ssh}"
|
||||
|
||||
resolve_server_password() {
|
||||
if [[ -n "${AI_GLASSES_SERVER_PASS:-}" ]]; then
|
||||
printf '%s' "${AI_GLASSES_SERVER_PASS}"
|
||||
return 0
|
||||
fi
|
||||
if command -v security >/dev/null 2>&1; then
|
||||
security find-generic-password -a "${AI_GLASSES_SERVER_USER:-ubuntu}" -s "${KEYCHAIN_SERVICE}" -w 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ ! -x "$AG_SERVER" ]]; then
|
||||
echo "AI Glasses server wrapper not found: $AG_SERVER" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
server_pass="$(resolve_server_password)"
|
||||
|
||||
remote_script=$(cat <<EOF
|
||||
set -euo pipefail
|
||||
|
||||
@@ -22,6 +35,15 @@ REMOTE_DIR=$(printf '%q' "$remote_dir")
|
||||
REMOTE_REPO=$(printf '%q' "$remote_repo")
|
||||
BRANCH=$(printf '%q' "$branch")
|
||||
DEPLOY_MODE=$(printf '%q' "$deploy_mode")
|
||||
SUDO_PASS=$(printf '%q' "$server_pass")
|
||||
|
||||
run_sudo() {
|
||||
if [[ -n "\$SUDO_PASS" ]]; then
|
||||
printf '%s\n' "\$SUDO_PASS" | sudo -S "\$@"
|
||||
else
|
||||
sudo "\$@"
|
||||
fi
|
||||
}
|
||||
|
||||
mkdir -p "\$REMOTE_DIR"
|
||||
|
||||
@@ -37,7 +59,7 @@ git reset --hard "origin/\$BRANCH"
|
||||
|
||||
docker_ok=0
|
||||
if [[ "\$DEPLOY_MODE" != "node" ]]; then
|
||||
if sudo docker compose -f compose.cloud.yaml -p boss up -d --build --remove-orphans; then
|
||||
if run_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
|
||||
@@ -45,6 +67,110 @@ if [[ "\$DEPLOY_MODE" != "node" ]]; then
|
||||
fi
|
||||
|
||||
if [[ "\$docker_ok" -eq 1 ]]; then
|
||||
if [[ -n "\$SUDO_PASS" ]]; then
|
||||
printf '%s\n' "\$SUDO_PASS" | sudo -S python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
path = Path("/etc/nginx/sites-enabled/hybrid_updates.conf")
|
||||
text = path.read_text()
|
||||
if "location /boss/" not in text:
|
||||
block = """
|
||||
location = /boss {
|
||||
return 302 /boss/;
|
||||
}
|
||||
|
||||
location /boss/ {
|
||||
proxy_pass http://127.0.0.1:43210;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host \$host;
|
||||
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_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
proxy_buffering off;
|
||||
}
|
||||
|
||||
"""
|
||||
marker = " location / {\n"
|
||||
text = text.replace(marker, block + marker, 1)
|
||||
path.write_text(text)
|
||||
PY
|
||||
else
|
||||
sudo python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
path = Path("/etc/nginx/sites-enabled/hybrid_updates.conf")
|
||||
text = path.read_text()
|
||||
if "location /boss/" not in text:
|
||||
block = """
|
||||
location = /boss {
|
||||
return 302 /boss/;
|
||||
}
|
||||
|
||||
location /boss/ {
|
||||
proxy_pass http://127.0.0.1:43210;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host \$host;
|
||||
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_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
proxy_buffering off;
|
||||
}
|
||||
|
||||
"""
|
||||
marker = " location / {\n"
|
||||
text = text.replace(marker, block + marker, 1)
|
||||
path.write_text(text)
|
||||
PY
|
||||
fi
|
||||
run_sudo nginx -t
|
||||
run_sudo systemctl reload nginx
|
||||
echo "__BOSS_DEPLOY_OK__"
|
||||
echo "mode=docker"
|
||||
run_sudo docker compose -f compose.cloud.yaml -p boss ps
|
||||
sleep 3
|
||||
curl -fsS http://127.0.0.1:43210/boss/api/health
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ! command -v node >/dev/null 2>&1 || ! command -v npm >/dev/null 2>&1; then
|
||||
run_sudo apt-get update
|
||||
run_sudo apt-get install -y nodejs npm
|
||||
fi
|
||||
|
||||
npm install
|
||||
npm run build
|
||||
PORT=43210 BOSS_DATA_FILE=.boss-data/cloud-store.json BOSS_BASE_PATH=/boss ./scripts/server_start.sh
|
||||
if [[ -n "\$SUDO_PASS" ]]; then
|
||||
printf '%s\n' "\$SUDO_PASS" | sudo -S python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
path = Path("/etc/nginx/sites-enabled/hybrid_updates.conf")
|
||||
text = path.read_text()
|
||||
if "location /boss/" not in text:
|
||||
block = """
|
||||
location = /boss {
|
||||
return 302 /boss/;
|
||||
}
|
||||
|
||||
location /boss/ {
|
||||
proxy_pass http://127.0.0.1:43210;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host \$host;
|
||||
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_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
proxy_buffering off;
|
||||
}
|
||||
|
||||
"""
|
||||
marker = " location / {\n"
|
||||
text = text.replace(marker, block + marker, 1)
|
||||
path.write_text(text)
|
||||
PY
|
||||
else
|
||||
sudo python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
path = Path("/etc/nginx/sites-enabled/hybrid_updates.conf")
|
||||
@@ -72,53 +198,9 @@ if "location /boss/" not in text:
|
||||
text = text.replace(marker, block + marker, 1)
|
||||
path.write_text(text)
|
||||
PY
|
||||
sudo nginx -t
|
||||
sudo systemctl reload nginx
|
||||
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/boss/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 BOSS_BASE_PATH=/boss ./scripts/server_start.sh
|
||||
sudo python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
path = Path("/etc/nginx/sites-enabled/hybrid_updates.conf")
|
||||
text = path.read_text()
|
||||
if "location /boss/" not in text:
|
||||
block = """
|
||||
location = /boss {
|
||||
return 302 /boss/;
|
||||
}
|
||||
|
||||
location /boss/ {
|
||||
proxy_pass http://127.0.0.1:43210;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host \$host;
|
||||
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_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
proxy_buffering off;
|
||||
}
|
||||
|
||||
"""
|
||||
marker = " location / {\n"
|
||||
text = text.replace(marker, block + marker, 1)
|
||||
path.write_text(text)
|
||||
PY
|
||||
sudo nginx -t
|
||||
sudo systemctl reload nginx
|
||||
run_sudo nginx -t
|
||||
run_sudo systemctl reload nginx
|
||||
echo "__BOSS_DEPLOY_OK__"
|
||||
echo "mode=node"
|
||||
BOSS_BASE_PATH=/boss ./scripts/server_status.sh
|
||||
|
||||
Reference in New Issue
Block a user