Serve one web app: route the tailnet address to the installed proxy
./install retires the pre-native standalone web agent (net.awan.pipelines.web, kept as .disabled) and, when the public web URL is a tailnet HTTPS address, points tailscale serve at the installed web proxy, failing the install if it cannot.
This commit is contained in:
@@ -405,6 +405,42 @@ class Setup:
|
|||||||
app_build.install_tree(built or self.build_app_web(), target)
|
app_build.install_tree(built or self.build_app_web(), target)
|
||||||
return str(target)
|
return str(target)
|
||||||
|
|
||||||
|
# --- one web app ---------------------------------------------------
|
||||||
|
|
||||||
|
# A standalone web proxy agent from before the native install. It served
|
||||||
|
# a second copy of the web app, so the tailnet address showed an old build.
|
||||||
|
LEGACY_WEB_LABEL = "net.awan.pipelines.web"
|
||||||
|
|
||||||
|
def retire_legacy_web(self):
|
||||||
|
"""Stops the pre-native standalone web agent; its plist is kept as
|
||||||
|
.disabled. The installed web proxy is the only web app."""
|
||||||
|
if platform.system() != "Darwin":
|
||||||
|
return
|
||||||
|
plist = Path.home() / f"Library/LaunchAgents/{self.LEGACY_WEB_LABEL}.plist"
|
||||||
|
if not plist.is_file():
|
||||||
|
return
|
||||||
|
self.runner(["launchctl", "bootout", f"gui/{os.getuid()}/{self.LEGACY_WEB_LABEL}"],
|
||||||
|
capture_output=True, text=True)
|
||||||
|
plist.rename(plist.with_name(plist.name + ".disabled"))
|
||||||
|
print(f"Retired the old standalone web agent {self.LEGACY_WEB_LABEL} (kept as {plist.name}.disabled).")
|
||||||
|
|
||||||
|
def serve_on_tailnet(self, public_url, web_port):
|
||||||
|
"""Points the tailnet HTTPS address recorded as the public web URL at
|
||||||
|
the installed web proxy, so every address serves the same web app."""
|
||||||
|
parsed = urlsplit(public_url)
|
||||||
|
if parsed.scheme != "https" or not (parsed.hostname or "").endswith(".ts.net"):
|
||||||
|
return
|
||||||
|
tailscale = shutil.which("tailscale")
|
||||||
|
if not tailscale:
|
||||||
|
raise ValueError(f"The public web URL {public_url} is a tailnet address but tailscale is not on PATH")
|
||||||
|
port = parsed.port or 443
|
||||||
|
result = self.runner([tailscale, "serve", "--bg", f"--https={port}", f"http://127.0.0.1:{web_port}"],
|
||||||
|
capture_output=True, text=True)
|
||||||
|
if result.returncode:
|
||||||
|
raise ValueError(f"tailscale serve could not point {public_url} at the web app: "
|
||||||
|
+ ((result.stderr or "").strip().splitlines() or ["failed"])[-1])
|
||||||
|
print(f"Tailnet: {public_url} serves the installed web app (port {web_port}).")
|
||||||
|
|
||||||
# --- build and skill -------------------------------------------------
|
# --- build and skill -------------------------------------------------
|
||||||
|
|
||||||
COMMANDS = ("pipelines-server", "pipelines")
|
COMMANDS = ("pipelines-server", "pipelines")
|
||||||
@@ -874,6 +910,8 @@ class Setup:
|
|||||||
f"'PIPELINES_PREFIX={prefix} {prefix}/bin/pipelines start' to see the error. "
|
f"'PIPELINES_PREFIX={prefix} {prefix}/bin/pipelines start' to see the error. "
|
||||||
"Check your login service manager and that ports "
|
"Check your login service manager and that ports "
|
||||||
f"{args.port}, {args.ntfy_port} and {args.web_port} are free (a running Docker installation may use them).")
|
f"{args.port}, {args.ntfy_port} and {args.web_port} are free (a running Docker installation may use them).")
|
||||||
|
self.retire_legacy_web()
|
||||||
|
self.serve_on_tailnet(opencode_env["PIPELINES_WEB_PUBLIC_URL"], args.web_port)
|
||||||
print(f"ntfy is configured for {base_url}; server, web proxy and ntfy have login autostart ({service_path}).")
|
print(f"ntfy is configured for {base_url}; server, web proxy and ntfy have login autostart ({service_path}).")
|
||||||
print("Phone notifications: subscribe to the 'pipelines' topic as phone-reader with the web password.")
|
print("Phone notifications: subscribe to the 'pipelines' topic as phone-reader with the web password.")
|
||||||
print(f"Web: http://{lan_ip if args.web_host == '0.0.0.0' else args.web_host}:{args.web_port}/ "
|
print(f"Web: http://{lan_ip if args.web_host == '0.0.0.0' else args.web_host}:{args.web_port}/ "
|
||||||
|
|||||||
@@ -733,6 +733,41 @@ class SetupNativeTests(unittest.TestCase):
|
|||||||
self.assertFalse(any("start" in call for call in recorder.calls))
|
self.assertFalse(any("start" in call for call in recorder.calls))
|
||||||
self.assertNotIn("Native Pipelines installed", output.getvalue())
|
self.assertNotIn("Native Pipelines installed", output.getvalue())
|
||||||
|
|
||||||
|
def test_legacy_standalone_web_agent_is_retired(self):
|
||||||
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
|
recorder = Recorder()
|
||||||
|
installer = self.installer(directory, recorder)
|
||||||
|
agents = Path(self.home.name) / "Library/LaunchAgents"
|
||||||
|
agents.mkdir(parents=True)
|
||||||
|
legacy = agents / "net.awan.pipelines.web.plist"
|
||||||
|
legacy.write_text("legacy")
|
||||||
|
with patch.object(setup_native.platform, "system", return_value="Darwin"), \
|
||||||
|
redirect_stdout(io.StringIO()):
|
||||||
|
installer.retire_legacy_web()
|
||||||
|
installer.retire_legacy_web()
|
||||||
|
self.assertFalse(legacy.exists())
|
||||||
|
self.assertEqual((agents / "net.awan.pipelines.web.plist.disabled").read_text(), "legacy")
|
||||||
|
self.assertEqual(sum(call[:2] == ["launchctl", "bootout"] for call in recorder.calls), 1)
|
||||||
|
|
||||||
|
def test_tailnet_public_url_serves_the_installed_web_app(self):
|
||||||
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
|
recorder = Recorder()
|
||||||
|
installer = self.installer(directory, recorder)
|
||||||
|
with patch.object(setup_native.shutil, "which", return_value="/usr/bin/tailscale"), \
|
||||||
|
redirect_stdout(io.StringIO()):
|
||||||
|
installer.serve_on_tailnet("https://box.tail1.ts.net:8443", 8083)
|
||||||
|
installer.serve_on_tailnet("http://10.0.0.5:8083", 8083)
|
||||||
|
self.assertEqual([call for call in recorder.calls if "serve" in call],
|
||||||
|
[["/usr/bin/tailscale", "serve", "--bg", "--https=8443", "http://127.0.0.1:8083"]])
|
||||||
|
|
||||||
|
def refusing(command, **kwargs):
|
||||||
|
return subprocess.CompletedProcess(command, 1, stdout="", stderr="serve: access denied")
|
||||||
|
|
||||||
|
installer = self.installer(directory, refusing)
|
||||||
|
with patch.object(setup_native.shutil, "which", return_value="/usr/bin/tailscale"):
|
||||||
|
with self.assertRaisesRegex(ValueError, "access denied"):
|
||||||
|
installer.serve_on_tailnet("https://box.tail1.ts.net", 8083)
|
||||||
|
|
||||||
def test_install_is_all_or_nothing_with_the_web_app(self):
|
def test_install_is_all_or_nothing_with_the_web_app(self):
|
||||||
cases = {"no docker": dict(docker=False), "web build fails": dict(fail_web=True),
|
cases = {"no docker": dict(docker=False), "web build fails": dict(fail_web=True),
|
||||||
"server build fails": dict(fail_build=True)}
|
"server build fails": dict(fail_build=True)}
|
||||||
|
|||||||
Reference in New Issue
Block a user