feat(observatory): install local M49 worker path

This commit is contained in:
DCCONSTRUCTIONS
2026-08-31 16:51:10 +03:00
parent 2f6e45bc96
commit 9c69d81296
19 changed files with 2252 additions and 212 deletions
+71
View File
@@ -12,6 +12,16 @@ from typing import Final, cast
MISSION_CORE_LAUNCH_AGENT_LABEL: Final = "com.nodedc.mission-core.local"
MISSION_CORE_LAUNCH_AGENT_SCHEMA: Final = "missioncore.local-launch-agent-plan/v1"
OBSERVATORY_LOCAL_WORKER_ENABLED_ENV: Final = (
"MISSIONCORE_OBSERVATORY_WORKER_LOCAL_ENABLED"
)
OBSERVATORY_SOURCE_CAS_ROOT_ENV: Final = (
"MISSIONCORE_OBSERVATORY_WORKER_SOURCE_CAS_ROOT"
)
OBSERVATORY_RESULT_STAGING_ROOT_ENV: Final = (
"MISSIONCORE_OBSERVATORY_WORKER_RESULT_STAGING_ROOT"
)
ARTIFACT_STORE_ROOT_ENV: Final = "MISSIONCORE_ARTIFACT_STORE_ROOT"
class MissionCoreLaunchAgentError(RuntimeError):
@@ -28,6 +38,7 @@ class MissionCoreLaunchAgentPlan:
preserved_data_directory: Path | None
current_program_arguments: tuple[str, ...]
desired_program_arguments: tuple[str, ...]
local_observatory_worker_enabled: bool
desired_payload: bytes
def to_dict(self) -> dict[str, object]:
@@ -61,6 +72,9 @@ class MissionCoreLaunchAgentPlan:
"bounded_launchd_exit_timeout_seconds": 20,
"keep_alive": True,
"process_group_owned": True,
"local_observatory_worker_enabled": (
self.local_observatory_worker_enabled
),
},
}
@@ -70,6 +84,7 @@ def plan_mission_core_launch_agent(
repository_root: Path,
agent_path: Path,
expected_current_repository_root: Path | None = None,
enable_local_observatory_worker: bool = False,
) -> MissionCoreLaunchAgentPlan:
repository = repository_root.expanduser().resolve(strict=True)
expected_current_repository = (
@@ -131,6 +146,28 @@ def plan_mission_core_launch_agent(
desired_environment["MISSIONCORE_SERVICE_WATCHDOG"] = "1"
if preserved_data_directory is not None:
desired_environment["MISSIONCORE_DATA_DIR"] = str(preserved_data_directory)
if enable_local_observatory_worker:
data_directory = _local_observatory_data_directory(
repository=repository,
environment=desired_environment,
)
artifact_store = _private_local_worker_directory(
data_directory / "observatory-artifact-store",
"local Observatory artifact store",
)
source_cas = _private_local_worker_directory(
data_directory / "observatory-worker-source-cas",
"local Observatory source CAS",
)
result_staging = _private_local_worker_directory(
data_directory / "observatory-worker-result-staging",
"local Observatory result staging",
)
desired_environment["MISSIONCORE_DATA_DIR"] = str(data_directory)
desired_environment[ARTIFACT_STORE_ROOT_ENV] = str(artifact_store)
desired_environment[OBSERVATORY_SOURCE_CAS_ROOT_ENV] = str(source_cas)
desired_environment[OBSERVATORY_RESULT_STAGING_ROOT_ENV] = str(result_staging)
desired_environment[OBSERVATORY_LOCAL_WORKER_ENABLED_ENV] = "1"
log_path = repository / ".runtime/mission-core/k1link-serve-launchd.log"
desired_program_arguments = (
str(uv_entrypoint),
@@ -163,10 +200,44 @@ def plan_mission_core_launch_agent(
preserved_data_directory=preserved_data_directory,
current_program_arguments=current_arguments,
desired_program_arguments=desired_program_arguments,
local_observatory_worker_enabled=enable_local_observatory_worker,
desired_payload=desired_payload,
)
def _local_observatory_data_directory(
*,
repository: Path,
environment: dict[str, str],
) -> Path:
configured = environment.get("MISSIONCORE_DATA_DIR", "").strip()
candidate = Path(configured) if configured else repository / ".runtime" / "mission-core"
return _private_local_worker_directory(
candidate,
"Mission Core data directory",
)
def _private_local_worker_directory(path: Path, label: str) -> Path:
if not path.is_absolute():
raise MissionCoreLaunchAgentError(f"{label} is not an absolute directory")
try:
metadata = path.lstat()
resolved = path.resolve(strict=True)
except OSError as exc:
raise MissionCoreLaunchAgentError(f"{label} is unavailable") from exc
if (
resolved != path
or not stat.S_ISDIR(metadata.st_mode)
or stat.S_IMODE(metadata.st_mode) != 0o700
or metadata.st_uid != os.getuid()
):
raise MissionCoreLaunchAgentError(
f"{label} is not a private canonical directory"
)
return resolved
def _program_arguments(document: dict[str, object]) -> tuple[str, ...]:
value = document.get("ProgramArguments")
if not isinstance(value, list) or not value or any(not isinstance(item, str) for item in value):