Keep web Material styling and preserve visible installer access URLs

This commit is contained in:
2026-10-26 18:37:13 +00:00
parent 48c29fd1ff
commit 41a3be8715
13 changed files with 176 additions and 15 deletions
+22
View File
@@ -212,6 +212,26 @@ def build_apk(prefix, server_url=None, notes="", runner=subprocess.run, log=prin
return target / "pipelines.apk"
def print_web_urls(manifest, lan_host=None):
"""Keep browser access details as the final installer output."""
web = manifest.get("web") or {}
if not web.get("port"):
return
host = web.get("host", "0.0.0.0")
local = "localhost" if host in ("0.0.0.0", "127.0.0.1") else host
urls = [f"http://{local}:{web['port']}/"]
if host == "0.0.0.0":
lan_host = lan_host or urlsplit(manifest.get("public_url", "")).hostname
if lan_host and lan_host not in ("localhost", "127.0.0.1", "0.0.0.0"):
urls.append(f"http://{lan_host}:{web['port']}/")
public = manifest.get("opencode_env", {}).get("PIPELINES_WEB_PUBLIC_URL")
if public:
urls.append(public.rstrip("/") + "/")
print("\nOpen Pipelines in your browser:")
for url in dict.fromkeys(urls):
print(" " + url)
def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("kind", choices=("web", "apk"))
@@ -223,6 +243,7 @@ def main(argv=None):
raise RuntimeError("Docker is required to build the app; start Docker and retry")
if args.kind == "apk":
build_apk(args.prefix, args.server_url, args.notes)
print_web_urls(load_manifest(args.prefix))
return
manifest = load_manifest(args.prefix)
web = manifest.get("web") or {}
@@ -230,6 +251,7 @@ def main(argv=None):
raise ValueError("This installation does not serve the app; rerun ./install")
install_tree(build("web"), Path(web["root"]))
print(f"Web app installed at {web['root']}; reload the page.")
print_web_urls(manifest)
if __name__ == "__main__":
+21 -1
View File
@@ -293,6 +293,24 @@ class Setup:
raise ValueError("Invalid existing authoring role; no permission changes were made")
return existing.get("allow_authoring", False)
def preserve_network_settings(self, prefix, args):
"""A plain reinstall keeps the installed addresses; flags override them."""
path = prefix / MARKER
if not path.exists() and not path.is_symlink():
return
if path.is_symlink() or not path.is_file():
raise ValueError("Refusing to read network settings from a non-regular installation manifest")
existing = json.loads(path.read_text())
web = existing.get("web") or {}
saved = {"port": existing.get("server_port"),
"ntfy_port": existing.get("ntfy_port"),
"bind_address": existing.get("bind_address"),
"web_port": web.get("port"), "web_host": web.get("host")}
supplied = {argument.split("=", 1)[0] for argument in args.argv}
for name, value in saved.items():
if value is not None and "--" + name.replace("_", "-") not in supplied:
setattr(args, name, value)
# --- prefix layout ---------------------------------------------------
def prepare_layout(self, prefix):
@@ -704,6 +722,8 @@ class Setup:
python = self.require_tools()
if args.prefix:
self.prefix_argument = args.prefix
prefix = self.resolve_prefix()
self.preserve_network_settings(prefix, args)
if not 1024 <= args.port <= 65535:
raise ValueError("Invalid server port; choose a value between 1024 and 65535")
if not 1024 <= args.ntfy_port <= 65535:
@@ -717,7 +737,6 @@ class Setup:
ipaddress.IPv4Address(args.web_host)
except ValueError:
raise ValueError("Invalid API/web bind address; use an IPv4 address such as 0.0.0.0 or 127.0.0.1") from None
prefix = self.resolve_prefix()
allow_authoring = self.authoring_role(prefix, args.allow_authoring)
web_public_url = self.environ.get("PIPELINES_WEB_PUBLIC_URL", "")
previous = prefix / MARKER
@@ -843,6 +862,7 @@ class Setup:
"(use a workspace path that exists on this server).")
else:
print(f"Unauthenticated API bound to {args.bind_address}:{args.port}; use the authenticated web URL.")
app_build.print_web_urls(manifest, lan_host=lan_ip)
def arguments(argv=None):
+21
View File
@@ -1,5 +1,7 @@
import importlib.util
import io
import json
from contextlib import redirect_stdout
from pathlib import Path
import subprocess
import tempfile
@@ -24,6 +26,25 @@ class Runner:
class AppBuildTests(unittest.TestCase):
def test_web_urls_include_saved_port_lan_and_public_origin(self):
manifest = {"web": {"host": "0.0.0.0", "port": 8096},
"public_url": "http://192.168.1.20:8090",
"opencode_env": {"PIPELINES_WEB_PUBLIC_URL": "https://pipelines.example.com"}}
with redirect_stdout(io.StringIO()) as output:
app_build.print_web_urls(manifest)
self.assertEqual(output.getvalue().splitlines()[-3:], [
" http://localhost:8096/", " http://192.168.1.20:8096/",
" https://pipelines.example.com/"])
def test_web_install_ends_with_access_urls(self):
manifest = {"web": {"host": "127.0.0.1", "port": 8083, "root": "/unused"}}
with patch.object(app_build, "docker_available", return_value=True), \
patch.object(app_build, "load_manifest", return_value=manifest), \
patch.object(app_build, "build"), patch.object(app_build, "install_tree"), \
redirect_stdout(io.StringIO()) as output:
app_build.main(["web"])
self.assertEqual(output.getvalue().splitlines()[-1], " http://localhost:8083/")
def setUp(self):
self.home = tempfile.TemporaryDirectory()
self.addCleanup(self.home.cleanup)
+27 -2
View File
@@ -150,6 +150,27 @@ class SetupNativeTests(unittest.TestCase):
mapping["cc"] = cc
return lambda name: mapping.get(name)
def test_reinstall_preserves_network_settings_and_explicit_flags_override(self):
with tempfile.TemporaryDirectory() as directory:
installer = self.installer(directory, Recorder())
prefix = installer.resolve_prefix()
prefix.mkdir()
manifest = {"server_port": 8090, "ntfy_port": 8091,
"bind_address": "127.0.0.2",
"web": {"port": 8096, "host": "127.0.0.1"}}
(prefix / setup_native.MARKER).write_text(json.dumps(manifest))
args = setup_native.arguments([])
installer.preserve_network_settings(prefix, args)
self.assertEqual((args.port, args.ntfy_port, args.web_port), (8090, 8091, 8096))
self.assertEqual((args.bind_address, args.web_host), ("127.0.0.2", "127.0.0.1"))
args = setup_native.arguments(["--web-port=8082", "--port", "8080"])
installer.preserve_network_settings(prefix, args)
self.assertEqual((args.port, args.ntfy_port, args.web_port), (8080, 8091, 8082))
(prefix / setup_native.MARKER).unlink()
args = setup_native.arguments([])
installer.preserve_network_settings(prefix, args)
self.assertEqual(args.web_port, 8082)
def test_require_tools_reports_each_missing_tool_without_installing(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder()
@@ -435,7 +456,7 @@ class SetupNativeTests(unittest.TestCase):
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \
patch.object(setup_native.lan, "detect_lan", return_value="192.168.1.20"), \
patch.object(setup_native.configure, "host_timezone", return_value="Europe/London"):
installer.run(setup_native.arguments([]))
installer.run(setup_native.arguments(["--web-port", "8096"]))
before = (prefix / "secrets/publisher-token").read_text()
def refuse_resolution():
@@ -443,8 +464,12 @@ class SetupNativeTests(unittest.TestCase):
installer.resolver = refuse_resolution
recorder.calls.clear()
installer.run(setup_native.arguments([]))
with redirect_stdout(io.StringIO()) as output:
installer.run(setup_native.arguments([]))
self.assertEqual((prefix / "secrets/publisher-token").read_text(), before)
self.assertEqual(manage.load(prefix)["web"]["port"], 8096)
self.assertEqual(output.getvalue().splitlines()[-2:], [
" http://localhost:8096/", " http://192.168.1.20:8096/"])
self.assertFalse(any("token" in call for call in recorder.calls), "reinstall re-created the token")
def test_ntfy_is_built_from_the_pinned_module(self):