Add curl|bash manage.sh with deploy/uninstall/update menu.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
DEPLOY_PASS 服务器密码
|
||||
DEPLOY_ROOT 默认 /opt/eth_hedge_sim
|
||||
REPO_URL 默认 https://git.bz121.com/dekun/eth_hedge_sim.git
|
||||
DEPLOY_MODE update|bootstrap 默认 update(跑 pull_and_restart)
|
||||
bootstrap 时执行 manage 非交互更新路径
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -19,6 +21,7 @@ USER = os.environ.get("DEPLOY_USER", "root")
|
||||
PASSWORD = os.environ.get("DEPLOY_PASS", "")
|
||||
ROOT = os.environ.get("DEPLOY_ROOT", "/opt/eth_hedge_sim")
|
||||
REPO = os.environ.get("REPO_URL", "https://git.bz121.com/dekun/eth_hedge_sim.git")
|
||||
MODE = os.environ.get("DEPLOY_MODE", "update").strip().lower()
|
||||
|
||||
|
||||
def main() -> int:
|
||||
@@ -31,28 +34,33 @@ def main() -> int:
|
||||
print("pip install paramiko", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
remote = f"""
|
||||
if MODE == "bootstrap":
|
||||
remote = f"""
|
||||
set -euo pipefail
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
if ! command -v git >/dev/null; then apt-get update -y && apt-get install -y git; fi
|
||||
if ! command -v python3 >/dev/null; then apt-get update -y && apt-get install -y python3 python3-venv python3-pip; fi
|
||||
if ! command -v node >/dev/null; then
|
||||
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
||||
apt-get install -y nodejs
|
||||
fi
|
||||
if [[ ! -d '{ROOT}/.git' ]]; then
|
||||
mkdir -p /opt
|
||||
git clone '{REPO}' '{ROOT}'
|
||||
fi
|
||||
bash '{ROOT}/deploy/pull_and_restart.sh'
|
||||
curl -fsS http://127.0.0.1:5155/health || true
|
||||
"""
|
||||
else:
|
||||
remote = f"""
|
||||
set -euo pipefail
|
||||
if [[ ! -d '{ROOT}/.git' ]]; then
|
||||
mkdir -p /opt
|
||||
git clone '{REPO}' '{ROOT}'
|
||||
fi
|
||||
bash '{ROOT}/deploy/lib/update.sh'
|
||||
curl -fsS http://127.0.0.1:5155/health || true
|
||||
"""
|
||||
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
print(f"connecting {USER}@{HOST} ...")
|
||||
client.connect(HOST, username=USER, password=PASSWORD, timeout=30)
|
||||
print("running remote bootstrap/pull ...")
|
||||
print("running remote pull/update ...")
|
||||
stdin, stdout, stderr = client.exec_command(remote, get_pty=True)
|
||||
while True:
|
||||
chunk = stdout.read(1024)
|
||||
|
||||
Reference in New Issue
Block a user