Add support for gpu-rent.vars and enhance git update functionality

- Updated .gitignore to include gpu-rent.vars.
- Modified env.example to introduce the UPDATE_GIT variable for controlling git updates during execution.
- Implemented Import-GpuRentVars function in gpu-rent.ps1 to load environment variables from gpu-rent.vars.
- Enhanced gpu-rent.sh to support loading variables from gpu-rent.vars and added logic for handling default and extra arguments.
- Updated CLI documentation to reflect the new gpu-rent.vars file and its usage in configuration.
- Improved bootstrap and provisioning logic to conditionally perform git updates based on the new configuration.
This commit is contained in:
Leonid Pershin
2026-08-21 05:01:53 +03:00
parent ec42830579
commit a9cf2e0f90
23 changed files with 515 additions and 39 deletions
+33 -11
View File
@@ -46,7 +46,7 @@ from gpu_rent.os_client import (
iter_volume_types,
)
from gpu_rent.ssh_keys import ensure_ed25519
from gpu_rent.ssh_ops import probe_ssh, wait_ssh
from gpu_rent.ssh_ops import probe_ssh, run_ssh, wait_ssh
from gpu_rent.state import SessionState, load_state, save_state, utc_now
Log = Callable[[str], None]
@@ -66,7 +66,15 @@ def _require_gpu_quota(conn) -> None:
)
def _bind_access(conn, server, state: SessionState, cfg: Config, log: Log) -> SessionState:
def _bind_access(
conn,
server,
state: SessionState,
cfg: Config,
log: Log,
*,
update: bool = True,
) -> SessionState:
ip, fip_id = ensure_floating_ip(
conn, server, state.floating_ip_id, state.floating_ip, log
)
@@ -76,8 +84,20 @@ def _bind_access(conn, server, state: SessionState, cfg: Config, log: Log) -> Se
save_state(state)
wait_ssh(cfg, ip)
log(f"SSH {cfg.ssh_user}@{ip}")
run_bootstrap(cfg, ip, log)
provision_vm(cfg, ip, log, conn=conn, server_id=getattr(server, "id", None) or state.server_id)
if update:
active = run_ssh(cfg, ip, "systemctl is-active swarmui 2>/dev/null || true", check=False).strip()
if active == "active":
log("systemctl stop swarmui перед git update")
run_ssh(cfg, ip, "sudo -n systemctl stop swarmui", timeout=120, check=False)
run_bootstrap(cfg, ip, log, update=update)
provision_vm(
cfg,
ip,
log,
conn=conn,
server_id=getattr(server, "id", None) or state.server_id,
update=update,
)
try:
wait_backend_idle(cfg, ip, log)
except CloudError as exc:
@@ -99,7 +119,7 @@ def _bind_access(conn, server, state: SessionState, cfg: Config, log: Log) -> Se
return state
def adopt_server(cfg: Config, log: Log = _log_default) -> SessionState:
def adopt_server(cfg: Config, log: Log = _log_default, *, update: bool = True) -> SessionState:
conn = connect(cfg)
server = pick_existing_server(conn)
if not server:
@@ -115,7 +135,7 @@ def adopt_server(cfg: Config, log: Log = _log_default) -> SessionState:
save_state(state)
log(f"подхватили {server.id} статус {server_status(server)}")
if server_status(server) == "ACTIVE":
_bind_access(conn, server, state, cfg, log)
_bind_access(conn, server, state, cfg, log, update=update)
return state
@@ -126,12 +146,14 @@ def cmd_up(
flavor: str | None = None,
yes: bool = False,
adopt: bool = False,
update: bool | None = None,
confirm: Callable[[str], bool] | None = None,
log: Log = _log_default,
) -> SessionState:
do_update = cfg.update_git if update is None else update
with SessionLock():
if adopt:
return adopt_server(cfg, log=log)
return adopt_server(cfg, log=log, update=do_update)
conn = connect(cfg)
_require_gpu_quota(conn)
state = load_state()
@@ -145,7 +167,7 @@ def cmd_up(
log("сервер уже ACTIVE — второй GPU не создаём")
state.phase = "ready_cloud"
save_state(state)
_bind_access(conn, existing, state, cfg, log)
_bind_access(conn, existing, state, cfg, log, update=do_update)
return state
# Bootstrap не завершён: почти всегда VM без authorized_keys.
@@ -167,7 +189,7 @@ def cmd_up(
log("сервер ACTIVE, SSH ок — продолжаем bootstrap")
state.phase = "ready_cloud"
save_state(state)
_bind_access(conn, existing, state, cfg, log)
_bind_access(conn, existing, state, cfg, log, update=do_update)
return state
log(
@@ -194,7 +216,7 @@ def cmd_up(
state.phase = "ready_cloud"
state.unshelved_at = utc_now()
save_state(state)
_bind_access(conn, existing, state, cfg, log)
_bind_access(conn, existing, state, cfg, log, update=do_update)
return state
if existing is not None:
raise CloudError(f"сервер gpu-rent в статусе {status} — разбери в панели")
@@ -321,7 +343,7 @@ def cmd_up(
state.unshelved_at = None
state.phase = "ready_cloud"
save_state(state)
_bind_access(conn, server, state, cfg, log)
_bind_access(conn, server, state, cfg, log, update=do_update)
return state