feat(install): build the Flutter web app in Docker, optional ./install --apk, chosen web password, startup report
This commit is contained in:
+45
-2
@@ -17,6 +17,7 @@ import ipaddress
|
||||
import json
|
||||
import os
|
||||
import platform
|
||||
import getpass
|
||||
import plistlib
|
||||
import secrets
|
||||
import shlex
|
||||
@@ -41,6 +42,7 @@ configure = module("configure_compose", "configure-compose.py")
|
||||
lan = module("lan_address", "lan-address.py")
|
||||
release_lookup = module("resolve_releases", "resolve-releases.py")
|
||||
tokens = module("save_ntfy_token", "save-ntfy-token.py")
|
||||
app_build = module("app_build", "app_build.py")
|
||||
|
||||
DEFAULT_PREFIX = Path.home() / ".local/share/pipelines"
|
||||
MARKER = "pipelines-install.json"
|
||||
@@ -325,14 +327,53 @@ class Setup:
|
||||
if auth.stat().st_mode & 0o077:
|
||||
raise ValueError(f"Web auth file must be private (chmod 600): {auth}")
|
||||
else:
|
||||
password = self.choose_password()
|
||||
auth.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||
self._write_atomic(auth, (json.dumps({"password": secrets.token_urlsafe(18),
|
||||
self._write_atomic(auth, (json.dumps({"password": password,
|
||||
"secret": secrets.token_urlsafe(48)}) + "\n").encode(), 0o600)
|
||||
target = prefix / "lib/web"
|
||||
shutil.copytree(Path(__file__).resolve().parents[1] / "web", target, dirs_exist_ok=True,
|
||||
ignore=shutil.ignore_patterns("test", "node_modules", ".DS_Store"))
|
||||
updates = prefix / "lib/app-updates"
|
||||
updates.mkdir(parents=True, exist_ok=True)
|
||||
return {"node": node, "script": str(target / "serve.mjs"),
|
||||
"auth_file": str(auth), "host": args.web_host, "port": args.web_port}
|
||||
"auth_file": str(auth), "host": args.web_host, "port": args.web_port,
|
||||
"root": self.install_app_web(prefix, args), "updates": str(updates)}
|
||||
|
||||
def choose_password(self):
|
||||
"""The web sign-in password for a new computer, chosen by the operator.
|
||||
|
||||
PIPELINES_WEB_PASSWORD answers it without a terminal (automation)."""
|
||||
given = self.environ.get("PIPELINES_WEB_PASSWORD")
|
||||
if given is not None:
|
||||
if len(given) < 8:
|
||||
raise ValueError("PIPELINES_WEB_PASSWORD must be at least 8 characters")
|
||||
return given
|
||||
if not sys.stdin.isatty():
|
||||
raise ValueError("Choose the web sign-in password: rerun ./install in a terminal, "
|
||||
"or set PIPELINES_WEB_PASSWORD (at least 8 characters)")
|
||||
print("This computer has no web sign-in yet. Choose the password for the web app and phone.")
|
||||
while True:
|
||||
first = getpass.getpass("Web password (at least 8 characters): ")
|
||||
if len(first) < 8:
|
||||
print("Too short; use at least 8 characters.")
|
||||
continue
|
||||
if getpass.getpass("Repeat the password: ") != first:
|
||||
print("The passwords did not match; try again.")
|
||||
continue
|
||||
return first
|
||||
|
||||
def install_app_web(self, prefix, args):
|
||||
"""Builds the Flutter web app in Docker (reused while its sources are
|
||||
unchanged) and installs it for the web proxy. Without Docker the web
|
||||
page explains how to build it later (./install --web)."""
|
||||
target = prefix / "lib/app-web"
|
||||
if not app_build.docker_available(self.runner):
|
||||
print("WARNING: Docker is not running, so the web app was not built. "
|
||||
"Start Docker, then run ./install --web.")
|
||||
return str(target)
|
||||
app_build.install_tree(app_build.build("web", runner=self.runner), target)
|
||||
return str(target)
|
||||
|
||||
# --- build and skill -------------------------------------------------
|
||||
|
||||
@@ -750,6 +791,8 @@ class Setup:
|
||||
f"(sign-in password in {web['auth_file']}; existing credentials retained).")
|
||||
print("Login autostart is already enabled. To enable/start it again, run:\n "
|
||||
+ shlex.join([str(prefix / "bin/pipelines"), "service", "enable"]))
|
||||
print("Android app (optional, slower): ./install --apk builds it in Docker and offers it at "
|
||||
f"{opencode_env['PIPELINES_WEB_PUBLIC_URL']}/updates/.")
|
||||
print("Configured server role: " + ("single-user authoring enabled (web pipeline creation/publication allowed)."
|
||||
if allow_authoring else "execution-only (pipeline publication disabled)."))
|
||||
if args.bind_address == "0.0.0.0":
|
||||
|
||||
Reference in New Issue
Block a user