feat(install): pipelines update re-runs the recorded install from the source checkout; --fresh skips Docker migration
This commit is contained in:
+44
-1
@@ -309,6 +309,47 @@ def report(config):
|
||||
print("==")
|
||||
|
||||
|
||||
def active_runs(config):
|
||||
"""Runs the server is still executing; an update waits for them."""
|
||||
binary = str(Path(config["prefix"]) / "bin/pipelines")
|
||||
result = run([binary, "--url", f"ws://127.0.0.1:{config['server_port']}/connect", "runs", "--json"],
|
||||
quiet=True, check=False, timeout=60)
|
||||
if result.returncode:
|
||||
return None
|
||||
try:
|
||||
data = json.loads(result.stdout)
|
||||
except ValueError:
|
||||
return None
|
||||
runs = data.get("runs", []) if isinstance(data, dict) else data
|
||||
return [item for item in runs if isinstance(item, dict) and item.get("executing")]
|
||||
|
||||
|
||||
def update(config):
|
||||
"""Brings this installation to the newest source: pull, reinstall the same
|
||||
way it was installed (data and credentials kept), restart, report."""
|
||||
source = Path(config.get("source") or "")
|
||||
if not (source / "install.sh").is_file():
|
||||
raise ValueError("This installation does not record its source checkout; "
|
||||
"run ./install from your Pipelines checkout to update it")
|
||||
if healthy(f"http://127.0.0.1:{config['server_port']}/healthz"):
|
||||
active = active_runs(config)
|
||||
if active is None:
|
||||
raise RuntimeError("Could not read the server's runs; update after checking `pipelines runs`")
|
||||
if active:
|
||||
raise RuntimeError(f"{len(active)} run(s) are still executing; update after they finish")
|
||||
if (source / ".git").exists():
|
||||
pulled = subprocess.run(["git", "-C", str(source), "pull", "--ff-only"], text=True)
|
||||
if pulled.returncode:
|
||||
raise RuntimeError("git pull --ff-only failed; resolve the checkout, then rerun `pipelines update`")
|
||||
installed = subprocess.run(["sh", str(source / "install.sh"), *config.get("install_args", [])])
|
||||
if installed.returncode:
|
||||
raise RuntimeError("The installer failed; the previous version keeps running")
|
||||
config = load(config["prefix"])
|
||||
stop(config)
|
||||
start(config)
|
||||
report(config)
|
||||
|
||||
|
||||
def supervise(config):
|
||||
root = Path(config["prefix"])
|
||||
with (root / "supervisor.lock").open("a") as lock:
|
||||
@@ -434,7 +475,7 @@ def uninstall(config, purge=False, yes=False):
|
||||
|
||||
|
||||
def main():
|
||||
lifecycle = ("start", "stop", "restart", "status", "doctor", "logs", "supervise", "uninstall")
|
||||
lifecycle = ("start", "stop", "restart", "status", "doctor", "logs", "supervise", "uninstall", "update")
|
||||
# Strip only the launcher's installation selector. All application arguments
|
||||
# belong to the shared Go CLI (including global flags before the command).
|
||||
selector = argparse.ArgumentParser(add_help=False)
|
||||
@@ -478,6 +519,8 @@ def main():
|
||||
print("Host OpenCode API: responding (model execution is a separate check)")
|
||||
elif args.action == "logs":
|
||||
os.execvp("tail", ["tail", "-n", "100", "-f", str(Path(config["prefix"]) / "logs/server.log")])
|
||||
elif args.action == "update":
|
||||
update(config)
|
||||
elif args.action == "supervise":
|
||||
supervise(config)
|
||||
elif args.action == "uninstall":
|
||||
|
||||
Reference in New Issue
Block a user