Add Synology CPU shares CI profile and host capability preflight
This commit is contained in:
@@ -52,10 +52,17 @@ GITEA_CI_ENTRIES = (
|
||||
GITEA_CI_V2_ENTRIES = (
|
||||
"docker-compose.gitea-ci.yml", "runner.yaml", "deployment/bootstrap-v2.json",
|
||||
)
|
||||
GITEA_CI_V3_ENTRIES = (
|
||||
"docker-compose.gitea-ci.yml", "runner.yaml", "deployment/bootstrap-v3.json",
|
||||
)
|
||||
GITEA_CI_SOURCE_SHA256 = {
|
||||
"docker-compose.gitea-ci.yml": "851d22ae9823c30508a552ec6abb7f547ceda671f3ca77552fb7032bc807ae09",
|
||||
"runner.yaml": "8634e5427986423ccd8fe18e3bf5072c53addbf17f1efc1395b3a473671d78fe",
|
||||
}
|
||||
GITEA_CI_V3_SOURCE_SHA256 = {
|
||||
"docker-compose.gitea-ci.yml": "775440b6a4d122793b8f1474a8a1a028ece98c4bebd54962e3418f0405c89c89",
|
||||
"runner.yaml": "c1e76972236b7610a167b2304967d401efdaabfd221229bdd55c63c98a34eea6",
|
||||
}
|
||||
MAP_GATEWAY_SECRET_DIR = Path("/volume1/docker/nodedc-platform/secrets")
|
||||
MAP_GATEWAY_SECRET_FILE = MAP_GATEWAY_SECRET_DIR / "map-gateway-admin-secret"
|
||||
MAP_EGRESS_PROXY_SECRET_FILE = MAP_GATEWAY_SECRET_DIR / "map-egress-proxy-token"
|
||||
@@ -4925,7 +4932,7 @@ def allowed_payload_path(component, rel):
|
||||
die(f"path rejected: {rel}: {reason}")
|
||||
|
||||
if component == "gitea-ci":
|
||||
if rel in GITEA_CI_ENTRIES + GITEA_CI_V2_ENTRIES or rel == "deployment":
|
||||
if rel in GITEA_CI_ENTRIES + GITEA_CI_V2_ENTRIES + GITEA_CI_V3_ENTRIES or rel == "deployment":
|
||||
return True
|
||||
die("Gitea CI accepts only its exact bootstrap contract")
|
||||
|
||||
@@ -31393,12 +31400,14 @@ def rollback_map_access(root, backup_dir, entries, current_stamp):
|
||||
|
||||
def validate_gitea_ci_payload(payload_dir, entries, release_id):
|
||||
v2 = tuple(entries) == GITEA_CI_V2_ENTRIES
|
||||
if tuple(entries) not in (GITEA_CI_ENTRIES, GITEA_CI_V2_ENTRIES):
|
||||
v3 = tuple(entries) == GITEA_CI_V3_ENTRIES
|
||||
if tuple(entries) not in (GITEA_CI_ENTRIES, GITEA_CI_V2_ENTRIES, GITEA_CI_V3_ENTRIES):
|
||||
die("Gitea CI bootstrap entry set mismatch")
|
||||
version = "v2" if v2 else "v1"
|
||||
version = "v3" if v3 else "v2" if v2 else "v1"
|
||||
if not release_id.startswith("gitea-ci-bootstrap-" + version + "-"):
|
||||
die("Gitea CI bootstrap release identity mismatch")
|
||||
for rel, expected in GITEA_CI_SOURCE_SHA256.items():
|
||||
sources = GITEA_CI_V3_SOURCE_SHA256 if v3 else GITEA_CI_SOURCE_SHA256
|
||||
for rel, expected in sources.items():
|
||||
if sha256_file(payload_dir / rel) != expected:
|
||||
die(f"Gitea CI immutable configuration mismatch: {rel}")
|
||||
descriptor = read_strict_json(payload_dir / entries[2], "Gitea CI bootstrap")
|
||||
@@ -31413,8 +31422,10 @@ def validate_gitea_ci_payload(payload_dir, entries, release_id):
|
||||
"publishedPorts": [],
|
||||
"capacity": 1,
|
||||
}
|
||||
if v2:
|
||||
if v2 or v3:
|
||||
expected["enrollment"] = "import-dctouch-staging-to-root-private-runtime"
|
||||
if v3:
|
||||
expected["resourceProfile"] = "synology-cpu-shares-v1"
|
||||
if descriptor != expected:
|
||||
die("Gitea CI bootstrap descriptor mismatch")
|
||||
return descriptor
|
||||
@@ -31573,15 +31584,44 @@ def gitea_ci_inventory():
|
||||
return result
|
||||
|
||||
|
||||
def gitea_ci_host_capabilities(entries):
|
||||
result = subprocess.run([str(DOCKER), "info", "--format", "{{json .}}"],
|
||||
capture_output=True, text=True, check=True, timeout=30)
|
||||
try:
|
||||
raw = json.loads(result.stdout)
|
||||
if not isinstance(raw, dict):
|
||||
raise ValueError()
|
||||
except ValueError:
|
||||
die("Gitea CI Docker capability report is invalid")
|
||||
# Do not print registry/proxy configuration, host identity or Docker credentials.
|
||||
fields = ("ServerVersion", "KernelVersion", "OSType", "Architecture", "NCPU",
|
||||
"MemTotal", "MemoryLimit", "SwapLimit", "CpuCfsPeriod", "CpuCfsQuota",
|
||||
"CPUShares", "CPUSet", "PidsLimit", "CgroupVersion")
|
||||
report = {key: raw.get(key) for key in fields}
|
||||
print("ci_host=" + json.dumps(report, sort_keys=True, separators=(",", ":")))
|
||||
required = ["MemoryLimit", "PidsLimit"]
|
||||
if tuple(entries) == GITEA_CI_V3_ENTRIES:
|
||||
required.append("CPUShares")
|
||||
else:
|
||||
required += ["CpuCfsPeriod", "CpuCfsQuota", "SwapLimit"]
|
||||
missing = [name for name in required if raw.get(name) is not True]
|
||||
if missing:
|
||||
die("Gitea CI host lacks required resource controls: " + ",".join(missing))
|
||||
if raw.get("OSType") != "linux" or raw.get("Architecture") not in ("amd64", "x86_64"):
|
||||
die("Gitea CI pinned worker requires Linux amd64")
|
||||
return report
|
||||
|
||||
|
||||
def preflight_gitea_ci(entries=GITEA_CI_ENTRIES):
|
||||
for parent in (GITEA_CI_ROOT, *GITEA_CI_ROOT.parents):
|
||||
if parent.is_symlink():
|
||||
die("Gitea CI root contains a symlink")
|
||||
if any((GITEA_CI_ROOT / rel).exists() for rel in GITEA_CI_ENTRIES + GITEA_CI_V2_ENTRIES):
|
||||
if any((GITEA_CI_ROOT / rel).exists() for rel in GITEA_CI_ENTRIES + GITEA_CI_V2_ENTRIES + GITEA_CI_V3_ENTRIES):
|
||||
die("Gitea CI bootstrap requires no installed release; use a versioned upgrade")
|
||||
gitea_ci_host_capabilities(entries)
|
||||
if gitea_ci_container_ids(own=True):
|
||||
die("Gitea CI bootstrap requires no existing CI containers")
|
||||
if tuple(entries) == GITEA_CI_V2_ENTRIES:
|
||||
if tuple(entries) in (GITEA_CI_V2_ENTRIES, GITEA_CI_V3_ENTRIES):
|
||||
preflight_gitea_ci_v2_enrollment()
|
||||
else:
|
||||
read_gitea_ci_enrollment()
|
||||
@@ -31598,7 +31638,7 @@ def preflight_gitea_ci(entries=GITEA_CI_ENTRIES):
|
||||
|
||||
|
||||
def prepare_gitea_ci(entries=GITEA_CI_ENTRIES):
|
||||
token = (import_gitea_ci_v2_enrollment() if tuple(entries) == GITEA_CI_V2_ENTRIES
|
||||
token = (import_gitea_ci_v2_enrollment() if tuple(entries) in (GITEA_CI_V2_ENTRIES, GITEA_CI_V3_ENTRIES)
|
||||
else read_gitea_ci_enrollment())
|
||||
for directory in (GITEA_CI_ROOT / "data", GITEA_CI_ROOT / "secrets"):
|
||||
if directory.is_symlink():
|
||||
@@ -31625,7 +31665,7 @@ def prepare_gitea_ci(entries=GITEA_CI_ENTRIES):
|
||||
inspect_local_image(image, "Gitea CI pinned image")
|
||||
|
||||
|
||||
def accept_gitea_ci_container(info):
|
||||
def accept_gitea_ci_container(info, entries=GITEA_CI_ENTRIES):
|
||||
host = info.get("HostConfig", {})
|
||||
config = info.get("Config", {})
|
||||
if config.get("Image") != GITEA_CI_IMAGE or not info.get("State", {}).get("Running"):
|
||||
@@ -31645,9 +31685,13 @@ def accept_gitea_ci_container(info):
|
||||
die("Gitea CI runner host isolation mismatch")
|
||||
if any(value.startswith("GITEA_RUNNER_REGISTRATION_TOKEN=") for value in config.get("Env", [])):
|
||||
die("Gitea CI registration token must remain file-backed")
|
||||
if tuple(entries) == GITEA_CI_V3_ENTRIES:
|
||||
valid_cpu = (host.get("CpuShares") == 64 and not host.get("NanoCpus")
|
||||
and not host.get("CpuQuota") and not host.get("CpuPeriod"))
|
||||
else:
|
||||
valid_cpu = host.get("NanoCpus") == 500000000
|
||||
if (host.get("Memory") != 512 * 1024 ** 2
|
||||
or host.get("NanoCpus") != 500000000
|
||||
or host.get("PidsLimit") != 128):
|
||||
or not valid_cpu or host.get("PidsLimit") != 128):
|
||||
die("Gitea CI daemon resource limit mismatch")
|
||||
expected_mounts = {
|
||||
"/config/runner.yaml": (str(GITEA_CI_ROOT / "runner.yaml"), False),
|
||||
@@ -31663,7 +31707,7 @@ def accept_gitea_ci_container(info):
|
||||
die("Gitea CI daemon mount boundary mismatch")
|
||||
|
||||
|
||||
def accept_gitea_ci():
|
||||
def accept_gitea_ci(entries=GITEA_CI_ENTRIES):
|
||||
deadline = time.monotonic() + 60
|
||||
registration = GITEA_CI_ROOT / "data" / ".runner"
|
||||
expected_image = inspect_local_image(GITEA_CI_IMAGE, "Gitea CI running image")
|
||||
@@ -31673,7 +31717,7 @@ def accept_gitea_ci():
|
||||
if len(ids) != 1:
|
||||
die("Gitea CI requires exactly one build-runner container")
|
||||
info = inspect_container(ids[0])
|
||||
accept_gitea_ci_container(info)
|
||||
accept_gitea_ci_container(info, entries)
|
||||
if info.get("Image") != expected_image or info.get("RestartCount", 0) != 0:
|
||||
die("Gitea CI image identity or restart count mismatch")
|
||||
if registration.is_file() and not registration.is_symlink():
|
||||
@@ -32354,11 +32398,15 @@ def plan_artifact(artifact):
|
||||
if component == "gitea-ci":
|
||||
print("ci_transition=bootstrap-build-runner;production_deploy=false")
|
||||
print("ci_ports=none;cache=false;metrics=false;capacity=1")
|
||||
print("ci_runner_limit=cpu:0.5,memory:512MiB;job_limit=cpu:1,memory:2GiB")
|
||||
if tuple(entries) == GITEA_CI_V3_ENTRIES:
|
||||
print("ci_cpu=relative-shares;daemon:64,job:128;hard_cpu_quota=none")
|
||||
print("ci_memory=daemon:512MiB,job:2GiB;ci_pids=daemon:128,job:256;swap=host-default")
|
||||
else:
|
||||
print("ci_runner_limit=cpu:0.5,memory:512MiB;job_limit=cpu:1,memory:2GiB")
|
||||
print(f"ci_runner_image={GITEA_CI_IMAGE}")
|
||||
print(f"ci_job_image={GITEA_CI_JOB_IMAGE}")
|
||||
print("ci_pull=exact-digests-only;registration=separate-runtime-enrollment")
|
||||
if tuple(entries) == GITEA_CI_V2_ENTRIES:
|
||||
if tuple(entries) in (GITEA_CI_V2_ENTRIES, GITEA_CI_V3_ENTRIES):
|
||||
print("ci_enrollment=" + preflight_gitea_ci_v2_enrollment())
|
||||
print("ci_enrollment_apply=copy-to-root0600;private-directory0700;remove-staging-after-verification")
|
||||
print("ci_preserved=all-existing-containers,databases,volumes;rollback=bootstrap-source-and-runner-only")
|
||||
@@ -37899,7 +37947,7 @@ def run_healthchecks(component, entries=None, services=None):
|
||||
if component == "gitea-ci":
|
||||
if tuple(services or ()) != ("build-runner",):
|
||||
die("Gitea CI service set mismatch")
|
||||
accept_gitea_ci()
|
||||
accept_gitea_ci(entries)
|
||||
return
|
||||
if component == "mission-core-map-access":
|
||||
accept_map_access(component_root(component), entries)
|
||||
|
||||
Reference in New Issue
Block a user