Install and start the server only together with the web app
./install builds the web app and the server before replacing either, and fails without Docker or on a failed build, leaving the old pair in place. The supervisor and start refuse to run the server when the web app is not installed.
This commit is contained in:
+41
-14
@@ -327,7 +327,7 @@ class Setup:
|
||||
os.chmod(target, 0o700)
|
||||
return target
|
||||
|
||||
def configure_web(self, prefix, args):
|
||||
def configure_web(self, prefix, args, web_build=None):
|
||||
node = str(Path(shutil.which("node")).resolve())
|
||||
version = self.runner([node, "--version"], capture_output=True, text=True)
|
||||
try:
|
||||
@@ -359,7 +359,7 @@ class Setup:
|
||||
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,
|
||||
"root": self.install_app_web(prefix, args), "updates": str(updates)}
|
||||
"root": self.install_app_web(prefix, args, web_build), "updates": str(updates)}
|
||||
|
||||
def choose_password(self):
|
||||
"""The web sign-in password for a new computer, chosen by the operator.
|
||||
@@ -384,27 +384,50 @@ class Setup:
|
||||
continue
|
||||
return first
|
||||
|
||||
def install_app_web(self, prefix, args):
|
||||
def build_app_web(self):
|
||||
"""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"
|
||||
unchanged). The web app ships with the server: the install stops here,
|
||||
before anything is replaced, when it cannot be built."""
|
||||
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)
|
||||
raise ValueError("Docker is not running, so the web app cannot be built. The server is never "
|
||||
"installed without it; start Docker and rerun ./install.")
|
||||
try:
|
||||
built = app_build.build("web", runner=self.runner)
|
||||
except RuntimeError as error:
|
||||
raise ValueError(f"The web app build failed ({error}); nothing was installed") from None
|
||||
if not (Path(built) / "index.html").is_file():
|
||||
raise ValueError(f"The web app build in {built} has no index.html; nothing was installed")
|
||||
return built
|
||||
|
||||
def install_app_web(self, prefix, args, built=None):
|
||||
"""Installs the built web app for the web proxy."""
|
||||
target = prefix / "lib/app-web"
|
||||
app_build.install_tree(built or self.build_app_web(), target)
|
||||
return str(target)
|
||||
|
||||
# --- build and skill -------------------------------------------------
|
||||
|
||||
COMMANDS = ("pipelines-server", "pipelines")
|
||||
|
||||
def build(self, prefix):
|
||||
for command in ("pipelines-server", "pipelines"):
|
||||
"""Builds the server and CLI into bin/.next; install_binaries moves
|
||||
them into place once the web app is installed too."""
|
||||
staging = prefix / "bin/.next"
|
||||
shutil.rmtree(staging, ignore_errors=True)
|
||||
staging.mkdir(parents=True)
|
||||
for command in self.COMMANDS:
|
||||
result = self.runner(
|
||||
["go", "build", "-trimpath", "-o", str(prefix / "bin" / command), "./cmd/" + command],
|
||||
["go", "build", "-trimpath", "-o", str(staging / command), "./cmd/" + command],
|
||||
cwd=str(self.directory))
|
||||
if result.returncode:
|
||||
raise ValueError(f"go build failed for ./cmd/{command}; the native install is incomplete")
|
||||
shutil.rmtree(staging, ignore_errors=True)
|
||||
raise ValueError(f"go build failed for ./cmd/{command}; nothing was installed")
|
||||
|
||||
def install_binaries(self, prefix):
|
||||
staging = prefix / "bin/.next"
|
||||
for command in self.COMMANDS:
|
||||
os.replace(staging / command, prefix / "bin" / command)
|
||||
shutil.rmtree(staging, ignore_errors=True)
|
||||
|
||||
# --- stale-CLI-on-PATH guard -----------------------------------------
|
||||
|
||||
@@ -758,9 +781,13 @@ class Setup:
|
||||
else:
|
||||
self.require_compiler()
|
||||
resolution = self.resolve_ntfy()
|
||||
# All or nothing: the web app and the server are both built before
|
||||
# either is installed, and a failed build leaves the old pair running.
|
||||
web_build = self.build_app_web()
|
||||
self.prepare_layout(prefix)
|
||||
web = self.configure_web(prefix, args)
|
||||
self.build(prefix)
|
||||
web = self.configure_web(prefix, args, web_build)
|
||||
self.install_binaries(prefix)
|
||||
self.check_path_shadow(prefix)
|
||||
self.install_skill(prefix)
|
||||
# The native install launches host harnesses, so write host profiles for
|
||||
|
||||
Reference in New Issue
Block a user