chore(storage): bound build retention, caches and test resources
Track build ownership, qualified pins and bounded cache/log lifecycles. Move Vite fixtures to a job-owned server helper and preserve private outputs outside Git.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
No remote command, NAS configuration, provider credential or cache is changed.
|
||||
The user LaunchAgent reconnects independently of the Core process.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
@@ -19,6 +20,8 @@ import tempfile
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from k1link.launchd_logs import bounded_launchd_output
|
||||
|
||||
LABEL = "com.nodedc.mission-core.map-gateway-link"
|
||||
PORT = 18103
|
||||
|
||||
@@ -26,21 +29,47 @@ PORT = 18103
|
||||
def payload(target: str, runtime: Path) -> bytes:
|
||||
if not re.fullmatch(r"[a-zA-Z0-9_][a-zA-Z0-9_.-]*@[a-zA-Z0-9][a-zA-Z0-9.-]*", target):
|
||||
raise ValueError("SSH target must be an explicit user@host")
|
||||
return plistlib.dumps({
|
||||
"Label": LABEL,
|
||||
"ProgramArguments": [
|
||||
"/usr/bin/ssh", "-N", "-T", "-o", "BatchMode=yes",
|
||||
"-o", "StrictHostKeyChecking=yes", "-o", "ExitOnForwardFailure=yes",
|
||||
"-o", "ConnectTimeout=10", "-o", "ServerAliveInterval=15",
|
||||
"-o", "ServerAliveCountMax=3", "-o", "PermitLocalCommand=no",
|
||||
"-o", "ForwardAgent=no", "-o", "ForwardX11=no",
|
||||
"-L", f"127.0.0.1:{PORT}:127.0.0.1:{PORT}", target,
|
||||
],
|
||||
"RunAtLoad": True, "KeepAlive": True, "ThrottleInterval": 30,
|
||||
"ExitTimeOut": 10,
|
||||
"StandardOutPath": str(runtime / "stdout.log"),
|
||||
"StandardErrorPath": str(runtime / "stderr.log"),
|
||||
}, sort_keys=True)
|
||||
return plistlib.dumps(
|
||||
bounded_launchd_output(
|
||||
{
|
||||
"Label": LABEL,
|
||||
"ProgramArguments": [
|
||||
"/usr/bin/ssh",
|
||||
"-N",
|
||||
"-T",
|
||||
"-o",
|
||||
"BatchMode=yes",
|
||||
"-o",
|
||||
"StrictHostKeyChecking=yes",
|
||||
"-o",
|
||||
"ExitOnForwardFailure=yes",
|
||||
"-o",
|
||||
"ConnectTimeout=10",
|
||||
"-o",
|
||||
"ServerAliveInterval=15",
|
||||
"-o",
|
||||
"ServerAliveCountMax=3",
|
||||
"-o",
|
||||
"PermitLocalCommand=no",
|
||||
"-o",
|
||||
"ForwardAgent=no",
|
||||
"-o",
|
||||
"ForwardX11=no",
|
||||
"-L",
|
||||
f"127.0.0.1:{PORT}:127.0.0.1:{PORT}",
|
||||
target,
|
||||
],
|
||||
"RunAtLoad": True,
|
||||
"KeepAlive": True,
|
||||
"ThrottleInterval": 30,
|
||||
"ExitTimeOut": 10,
|
||||
"StandardOutPath": str(runtime / "stdout.log"),
|
||||
"StandardErrorPath": str(runtime / "stderr.log"),
|
||||
},
|
||||
Path(__file__).resolve().parents[1],
|
||||
),
|
||||
sort_keys=True,
|
||||
)
|
||||
|
||||
|
||||
def digest(value: bytes | None) -> str:
|
||||
@@ -50,9 +79,13 @@ def digest(value: bytes | None) -> str:
|
||||
def health() -> bool:
|
||||
connection = http.client.HTTPConnection("127.0.0.1", PORT, timeout=2)
|
||||
try:
|
||||
connection.request("GET", "/healthz", headers={
|
||||
"x-nodedc-user-id": "mission-core-loopback-operator",
|
||||
})
|
||||
connection.request(
|
||||
"GET",
|
||||
"/healthz",
|
||||
headers={
|
||||
"x-nodedc-user-id": "mission-core-loopback-operator",
|
||||
},
|
||||
)
|
||||
response = connection.getresponse()
|
||||
raw = response.read(65537)
|
||||
if response.status != 200 or len(raw) > 65536:
|
||||
@@ -66,18 +99,29 @@ def health() -> bool:
|
||||
|
||||
|
||||
def loaded() -> bool:
|
||||
return subprocess.run(["launchctl", "print", f"gui/{os.getuid()}/{LABEL}"],
|
||||
capture_output=True, timeout=5, check=False).returncode == 0
|
||||
return (
|
||||
subprocess.run(
|
||||
["launchctl", "print", f"gui/{os.getuid()}/{LABEL}"],
|
||||
capture_output=True,
|
||||
timeout=5,
|
||||
check=False,
|
||||
).returncode
|
||||
== 0
|
||||
)
|
||||
|
||||
|
||||
def unload() -> None:
|
||||
subprocess.run(["launchctl", "bootout", f"gui/{os.getuid()}/{LABEL}"],
|
||||
capture_output=True, timeout=20, check=False)
|
||||
subprocess.run(
|
||||
["launchctl", "bootout", f"gui/{os.getuid()}/{LABEL}"],
|
||||
capture_output=True,
|
||||
timeout=20,
|
||||
check=False,
|
||||
)
|
||||
deadline = time.monotonic() + 20
|
||||
while loaded():
|
||||
if time.monotonic() > deadline:
|
||||
raise RuntimeError("Map Gateway link did not finish unloading")
|
||||
time.sleep(.2)
|
||||
time.sleep(0.2)
|
||||
|
||||
|
||||
def write_atomic(path: Path, value: bytes) -> None:
|
||||
@@ -112,15 +156,22 @@ def main() -> None:
|
||||
if previous is not None and plistlib.loads(previous).get("Label") != LABEL:
|
||||
raise ValueError("Refusing a foreign LaunchAgent")
|
||||
desired = payload(args.target, runtime)
|
||||
plan = {"label": LABEL, "agent_path": str(agent), "target": args.target,
|
||||
"local_bind": f"127.0.0.1:{PORT}", "remote_bind": f"127.0.0.1:{PORT}",
|
||||
"current_sha256": digest(previous), "desired_sha256": digest(desired),
|
||||
"remote_mutation": False}
|
||||
plan = {
|
||||
"label": LABEL,
|
||||
"agent_path": str(agent),
|
||||
"target": args.target,
|
||||
"local_bind": f"127.0.0.1:{PORT}",
|
||||
"remote_bind": f"127.0.0.1:{PORT}",
|
||||
"current_sha256": digest(previous),
|
||||
"desired_sha256": digest(desired),
|
||||
"remote_mutation": False,
|
||||
}
|
||||
if args.action == "plan":
|
||||
print(json.dumps(plan, indent=2))
|
||||
return
|
||||
if (args.expected_current_sha256 != digest(previous)
|
||||
or args.expected_desired_sha256 != digest(desired)):
|
||||
if args.expected_current_sha256 != digest(previous) or args.expected_desired_sha256 != digest(
|
||||
desired
|
||||
):
|
||||
raise ValueError("Map Gateway link plan changed before apply")
|
||||
was_loaded = loaded()
|
||||
if previous == desired and was_loaded and health():
|
||||
@@ -137,20 +188,28 @@ def main() -> None:
|
||||
if was_loaded:
|
||||
unload()
|
||||
write_atomic(agent, desired)
|
||||
subprocess.run(["launchctl", "bootstrap", f"gui/{os.getuid()}", str(agent)],
|
||||
capture_output=True, timeout=20, check=True)
|
||||
subprocess.run(
|
||||
["launchctl", "bootstrap", f"gui/{os.getuid()}", str(agent)],
|
||||
capture_output=True,
|
||||
timeout=20,
|
||||
check=True,
|
||||
)
|
||||
deadline = time.monotonic() + 40
|
||||
while not health():
|
||||
if time.monotonic() > deadline:
|
||||
raise RuntimeError("Map Gateway link did not pass health acceptance")
|
||||
time.sleep(.5)
|
||||
time.sleep(0.5)
|
||||
except BaseException:
|
||||
unload()
|
||||
if previous is not None:
|
||||
write_atomic(agent, previous)
|
||||
if was_loaded:
|
||||
subprocess.run(["launchctl", "bootstrap", f"gui/{os.getuid()}", str(agent)],
|
||||
capture_output=True, timeout=20, check=True)
|
||||
subprocess.run(
|
||||
["launchctl", "bootstrap", f"gui/{os.getuid()}", str(agent)],
|
||||
capture_output=True,
|
||||
timeout=20,
|
||||
check=True,
|
||||
)
|
||||
else:
|
||||
agent.unlink(missing_ok=True)
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user