Bind the native server to the LAN so the phone client can reach it
The native install hardcoded -addr 127.0.0.1, so the server was unreachable from
the phone: the emulator worked because it proxies to the host loopback, but a
real device could not connect even though ntfy (bound to 0.0.0.0:8090) worked.
The bind address is now a manifest setting (server_address() in manage.py, with
older manifests still defaulting to loopback) and setup-native.py records it,
defaulting to 0.0.0.0 like the Docker install did and offering
--bind-address 127.0.0.1 for a loopback-only server. An invalid address is
rejected, and setup prints the phone client URL.
Verified: scripts test suite 116 tests OK, and after reinstalling the server
listens on *:8080 and answers {"healthy":true} on 127.0.0.1, 10.0.0.75,
10.0.0.249 and the tailnet address.
This commit is contained in:
+22
-1
@@ -13,6 +13,7 @@ invented here.
|
||||
"""
|
||||
import argparse
|
||||
import importlib.util
|
||||
import ipaddress
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
@@ -47,6 +48,11 @@ C_COMPILERS = ("cc", "clang", "gcc")
|
||||
NTFY_BUILD_TAGS = "sqlite_omit_load_extension,osusergo,netgo"
|
||||
DEFAULT_NTFY_PORT = 8090
|
||||
DEFAULT_SERVER_PORT = 8080
|
||||
# The phone client reaches the server over the LAN, matching the Docker install
|
||||
# (which published 0.0.0.0). Use --bind-address 127.0.0.1 for a loopback-only
|
||||
# server; the Pipelines API has no authentication, so keep it on a trusted
|
||||
# LAN/VPN either way.
|
||||
DEFAULT_BIND_ADDRESS = "0.0.0.0"
|
||||
|
||||
|
||||
class Setup:
|
||||
@@ -360,6 +366,10 @@ class Setup:
|
||||
raise ValueError("Invalid ntfy port; choose a value between 1024 and 65535")
|
||||
if args.ntfy_port == args.port:
|
||||
raise ValueError("The server and ntfy ports must differ")
|
||||
try:
|
||||
ipaddress.IPv4Address(args.bind_address)
|
||||
except ValueError:
|
||||
raise ValueError("Invalid bind address; use an IPv4 address such as 0.0.0.0 or 127.0.0.1") from None
|
||||
prefix = self.resolve_prefix()
|
||||
self.prepare_layout(prefix)
|
||||
harness = self.harness()
|
||||
@@ -372,7 +382,8 @@ class Setup:
|
||||
resolution = self.resolve_ntfy()
|
||||
self.build(prefix)
|
||||
self.install_skill(prefix)
|
||||
base_url = args.ntfy_url or f"http://{lan.detect_lan()}:{args.ntfy_port}"
|
||||
lan_ip = lan.detect_lan()
|
||||
base_url = args.ntfy_url or f"http://{lan_ip}:{args.ntfy_port}"
|
||||
config_path = self.write_ntfy_config(prefix, base_url, args.ntfy_port)
|
||||
self.build_ntfy(prefix, resolution)
|
||||
# Migrate existing Docker data before creating native ntfy accounts so a
|
||||
@@ -399,6 +410,7 @@ class Setup:
|
||||
"prefix": str(prefix),
|
||||
"python": python,
|
||||
"server_port": args.port,
|
||||
"bind_address": args.bind_address,
|
||||
"ntfy_port": args.ntfy_port,
|
||||
"opencode": harness["opencode"],
|
||||
"pi": harness["pi"],
|
||||
@@ -438,6 +450,12 @@ class Setup:
|
||||
f"'{prefix}/bin/pipelines start' to see the error. Check that ports "
|
||||
f"{args.port} and {args.ntfy_port} are free (a running Docker installation uses them).")
|
||||
print(f"ntfy is configured for {base_url} and both services are running.")
|
||||
if args.bind_address == "0.0.0.0":
|
||||
print(f"Phone client server URL: ws://{lan_ip}:{args.port}/connect "
|
||||
"(use a workspace path that exists on this server).")
|
||||
else:
|
||||
print(f"Server bound to {args.bind_address}:{args.port}; a phone on the LAN needs a LAN bind "
|
||||
"(re-run with --bind-address 0.0.0.0).")
|
||||
print("Create the phone account password if it is a new account, then subscribe to the pipelines topic.")
|
||||
|
||||
|
||||
@@ -447,6 +465,9 @@ def arguments(argv=None):
|
||||
parser.add_argument("--ntfy-url", help="Override the auto-detected LAN ntfy address")
|
||||
parser.add_argument("--timezone", help="Override the detected timezone (fallback: UTC)")
|
||||
parser.add_argument("--port", type=int, default=DEFAULT_SERVER_PORT, help="Pipelines server port")
|
||||
parser.add_argument("--bind-address", default=DEFAULT_BIND_ADDRESS,
|
||||
help="Server bind address (default 0.0.0.0, the LAN, so the phone client can reach it; "
|
||||
"use 127.0.0.1 for a loopback-only server)")
|
||||
parser.add_argument("--ntfy-port", type=int, default=DEFAULT_NTFY_PORT, help="ntfy listen port")
|
||||
parser.add_argument("--model", help="Record an explicit default model; otherwise host OpenCode configuration is reused")
|
||||
parser.add_argument("--replace-data", action="store_true",
|
||||
|
||||
Reference in New Issue
Block a user