Bind both Docker services to 0.0.0.0 by default
This commit is contained in:
@@ -60,7 +60,7 @@ def configure(directory, ntfy_url, bind_address, timezone=None, port=8081):
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--ntfy-url", required=True)
|
||||
parser.add_argument("--bind-address", default="127.0.0.1")
|
||||
parser.add_argument("--bind-address", default="0.0.0.0")
|
||||
parser.add_argument("--timezone")
|
||||
parser.add_argument("--port", type=int, default=8081)
|
||||
args = parser.parse_args()
|
||||
|
||||
+17
-4
@@ -2,6 +2,7 @@
|
||||
"""Configure, authenticate and verify the full Docker installation."""
|
||||
import argparse
|
||||
import importlib.util
|
||||
import ipaddress
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
@@ -35,14 +36,26 @@ class Setup:
|
||||
|
||||
def settings(self, args):
|
||||
settings = self.directory / ".env"
|
||||
bind = str(ipaddress.IPv4Address(args.bind_address or "0.0.0.0"))
|
||||
if settings.is_symlink():
|
||||
raise ValueError("Refusing to modify a symlinked .env")
|
||||
if settings.exists():
|
||||
if any((args.ntfy_url, args.bind_address, args.timezone, args.port)):
|
||||
if any((args.ntfy_url, args.timezone, args.port)):
|
||||
raise ValueError(".env already exists; edit it explicitly rather than replace existing configuration")
|
||||
print("Keeping existing .env and credentials.")
|
||||
text = settings.read_text()
|
||||
for key, value in (("NTFY_BIND_ADDRESS", bind),
|
||||
("PIPELINES_BIND_ADDRESS", "0.0.0.0")):
|
||||
if any(line.startswith(key + "=") for line in text.splitlines()):
|
||||
text = "".join(key + "=" + value + "\n" if line.startswith(key + "=") else line
|
||||
for line in text.splitlines(keepends=True))
|
||||
else:
|
||||
text = text.rstrip("\n") + "\n" + key + "=" + value + "\n"
|
||||
if text != settings.read_text():
|
||||
settings.write_text(text)
|
||||
print(f"Docker binds: ntfy {bind}, Pipelines 0.0.0.0; existing URLs, timezone, ports and credentials retained.")
|
||||
return
|
||||
address = lan.detect_lan() if not args.ntfy_url else None
|
||||
url = args.ntfy_url or f"http://{address}:8090"
|
||||
bind = args.bind_address or address or "127.0.0.1"
|
||||
timezone = args.timezone
|
||||
if not timezone:
|
||||
try:
|
||||
@@ -132,7 +145,7 @@ printf 'header = "Authorization: Bearer %s"\\n' "$(cat "$PIPELINES_NTFY_TOKEN_FI
|
||||
def arguments(argv=None):
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--ntfy-url", help="Override the auto-detected LAN ntfy address")
|
||||
parser.add_argument("--bind-address", help="Override the detected LAN bind IP")
|
||||
parser.add_argument("--bind-address", help="Override ntfy's default 0.0.0.0 bind address")
|
||||
parser.add_argument("--timezone", help="Override the detected timezone (fallback: UTC)")
|
||||
parser.add_argument("--port", type=int)
|
||||
parser.add_argument("--relogin", action="store_true", help="open OpenCode provider login again without deleting accounts")
|
||||
|
||||
@@ -53,7 +53,7 @@ class DockerSetupTests(unittest.TestCase):
|
||||
setup.Setup(directory).settings(setup.arguments([]))
|
||||
text=Path(directory,".env").read_text()
|
||||
self.assertIn("NTFY_BASE_URL=http://192.168.1.25:8090\n",text)
|
||||
self.assertIn("NTFY_BIND_ADDRESS=192.168.1.25\n",text)
|
||||
self.assertIn("NTFY_BIND_ADDRESS=0.0.0.0\n",text)
|
||||
self.assertIn("TZ=Europe/London\n",text)
|
||||
|
||||
def test_timezone_fallback_does_not_prompt(self):
|
||||
@@ -118,7 +118,11 @@ class DockerSetupTests(unittest.TestCase):
|
||||
before = [p.read_bytes() for p in files]
|
||||
calls, _ = self.exercise(directory, existing=True)
|
||||
self.assertFalse(any("login" in c or "token" in c for c in calls))
|
||||
self.assertEqual(before, [p.read_bytes() for p in files])
|
||||
self.assertEqual(before[1],files[1].read_bytes())
|
||||
self.assertEqual(files[0].read_bytes(),before[0].replace(b"NTFY_BIND_ADDRESS=192.168.1.20",b"NTFY_BIND_ADDRESS=0.0.0.0")+b"PIPELINES_BIND_ADDRESS=0.0.0.0\n")
|
||||
normalized=files[0].read_bytes()
|
||||
self.exercise(directory,existing=True)
|
||||
self.assertEqual(normalized,files[0].read_bytes())
|
||||
|
||||
def test_login_failure_or_cancel_does_not_mark_complete_or_start_server(self):
|
||||
for fail, confirm in [("login", "yes"), (None, "no")]:
|
||||
@@ -141,6 +145,21 @@ class DockerSetupTests(unittest.TestCase):
|
||||
setup.Setup(directory).settings(setup.arguments(["--ntfy-url", "https://example.com"]))
|
||||
self.assertEqual(path.read_text(), "existing settings")
|
||||
|
||||
def test_existing_env_rejects_unsafe_bind_override(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
path=Path(directory,".env");path.write_text("NTFY_BIND_ADDRESS=127.0.0.1\n")
|
||||
with self.assertRaises(ValueError):
|
||||
setup.Setup(directory).settings(setup.arguments(["--bind-address","0.0.0.0\nOTHER=bad"]))
|
||||
self.assertEqual(path.read_text(),"NTFY_BIND_ADDRESS=127.0.0.1\n")
|
||||
|
||||
def test_existing_env_symlink_is_not_modified(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
target=Path(directory,"custom.env");target.write_text("keep")
|
||||
Path(directory,".env").symlink_to(target)
|
||||
with self.assertRaises(ValueError):
|
||||
setup.Setup(directory).settings(setup.arguments([]))
|
||||
self.assertEqual(target.read_text(),"keep")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user