feat(install): pipelines update re-runs the recorded install from the source checkout; --fresh skips Docker migration
This commit is contained in:
@@ -14,8 +14,22 @@ cd pipelines
|
||||
./install --docker # explicit Docker server + ntfy
|
||||
./install --web # rebuild the web app (Docker) after app changes
|
||||
./install --apk # optional: build the Android app (Docker, slower)
|
||||
pipelines update # later: pull, reinstall the same way, restart
|
||||
```
|
||||
|
||||
## Updating
|
||||
|
||||
`pipelines update` brings an installation to the newest source. It waits while
|
||||
runs are executing, fast-forwards the checkout it was installed from
|
||||
(`git pull --ff-only`), re-runs `./install` with the options recorded at install
|
||||
time, restarts the server, web proxy and ntfy, and prints the startup report.
|
||||
Data, the web password, ntfy accounts and the Android signing key are kept; the
|
||||
web app and APK are rebuilt only when their sources changed. Phones pick up a
|
||||
new APK (after `./install --apk`) from Settings → App updates.
|
||||
|
||||
`./install --fresh` starts with empty data even when volumes from an earlier
|
||||
Docker installation exist (by default they are migrated).
|
||||
|
||||
## Native installation (default)
|
||||
|
||||
`./install`, `./install --native` and `./install native` run
|
||||
|
||||
+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":
|
||||
|
||||
+12
-2
@@ -722,7 +722,10 @@ class Setup:
|
||||
# Migrate existing Docker data before creating native ntfy accounts so a
|
||||
# migrated auth store (the phone's credentials) is preserved rather than
|
||||
# shadowed by a freshly bootstrapped one.
|
||||
self.migrate_docker(prefix, args.replace_data)
|
||||
if args.fresh:
|
||||
print("Starting empty (--fresh); existing Docker volumes are left untouched.")
|
||||
else:
|
||||
self.migrate_docker(prefix, args.replace_data)
|
||||
self.bootstrap_ntfy(prefix, config_path)
|
||||
timezone = args.timezone
|
||||
if not timezone:
|
||||
@@ -764,6 +767,9 @@ class Setup:
|
||||
"config": str(config_path), "base_url": base_url,
|
||||
"version": resolution.get("tag") or resolution.get("version")},
|
||||
"web": web,
|
||||
# `pipelines update` re-runs this installer from here, the same way.
|
||||
"source": str(self.directory),
|
||||
"install_args": list(getattr(args, "argv", [])),
|
||||
}
|
||||
self.register_service(service_path, manifest)
|
||||
self.write_manifest(prefix, manifest)
|
||||
@@ -820,9 +826,13 @@ def arguments(argv=None):
|
||||
help="Explicitly enable pipeline publication; fresh native installs default to enabled")
|
||||
role.add_argument("--no-authoring", dest="allow_authoring", action="store_false",
|
||||
help="Execution-only server; disable pipeline publication (reinstalls otherwise preserve the recorded role)")
|
||||
parser.add_argument("--fresh", action="store_true",
|
||||
help="Start with empty data even when an earlier Docker installation's volumes exist")
|
||||
parser.add_argument("--replace-data", action="store_true",
|
||||
help="Allow Docker migration to replace an existing native database/auth store")
|
||||
return parser.parse_args(argv)
|
||||
parsed = parser.parse_args(argv)
|
||||
parsed.argv = list(sys.argv[1:] if argv is None else argv)
|
||||
return parsed
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -177,6 +177,47 @@ class ManageNativeTests(unittest.TestCase):
|
||||
self.assertEqual(calls[0], ["launchctl", "enable", f"gui/{os.getuid()}/net.a-wan.pipelines"])
|
||||
self.assertIn(["launchctl", "kickstart", f"gui/{os.getuid()}/net.a-wan.pipelines"], calls)
|
||||
|
||||
def test_update_reinstalls_the_same_way_and_restarts(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
source = Path(directory) / "src"
|
||||
source.mkdir()
|
||||
(source / "install.sh").write_text("#!/bin/sh\n")
|
||||
config = self.config(Path(directory))
|
||||
config["source"] = str(source)
|
||||
config["install_args"] = ["--port", "18180"]
|
||||
calls = []
|
||||
done = subprocess.CompletedProcess([], 0)
|
||||
with patch.object(manage, "healthy", return_value=True), \
|
||||
patch.object(manage, "active_runs", return_value=[]), \
|
||||
patch.object(manage.subprocess, "run", side_effect=lambda cmd, **kw: calls.append(cmd) or done), \
|
||||
patch.object(manage, "load", return_value=config), \
|
||||
patch.object(manage, "stop") as stop, patch.object(manage, "start") as start, \
|
||||
patch.object(manage, "report") as report:
|
||||
manage.update(config)
|
||||
self.assertEqual(calls, [["sh", str(source / "install.sh"), "--port", "18180"]])
|
||||
stop.assert_called_once()
|
||||
start.assert_called_once()
|
||||
report.assert_called_once()
|
||||
|
||||
def test_update_waits_for_active_runs(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
source = Path(directory)
|
||||
(source / "install.sh").write_text("#!/bin/sh\n")
|
||||
config = self.config(Path(directory))
|
||||
config["source"] = str(source)
|
||||
with patch.object(manage, "healthy", return_value=True), \
|
||||
patch.object(manage, "active_runs", return_value=[{"id": 1}]), \
|
||||
patch.object(manage.subprocess, "run") as ran:
|
||||
with self.assertRaisesRegex(RuntimeError, "still executing"):
|
||||
manage.update(config)
|
||||
ran.assert_not_called()
|
||||
|
||||
def test_update_needs_a_recorded_source(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
config = self.config(Path(directory))
|
||||
with self.assertRaisesRegex(ValueError, "source checkout"):
|
||||
manage.update(config)
|
||||
|
||||
def test_report_prints_the_server_block_and_access(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
|
||||
@@ -236,6 +236,11 @@ class SetupNativeTests(unittest.TestCase):
|
||||
web = installer.configure_web(prefix, setup_native.arguments([]))
|
||||
self.assertEqual(json.loads(Path(web["auth_file"]).read_text())["password"], "typed-password")
|
||||
|
||||
def test_fresh_install_skips_docker_migration(self):
|
||||
args = setup_native.arguments(["--fresh"])
|
||||
self.assertTrue(args.fresh)
|
||||
self.assertFalse(setup_native.arguments([]).fresh)
|
||||
|
||||
def test_invalid_web_auth_is_retained(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
installer = self.installer(directory, Recorder())
|
||||
|
||||
Reference in New Issue
Block a user