Add Synology CPUSet CI bootstrap for actual NAS capabilities
This commit is contained in:
@@ -55,6 +55,9 @@ GITEA_CI_V2_ENTRIES = (
|
||||
GITEA_CI_V3_ENTRIES = (
|
||||
"docker-compose.gitea-ci.yml", "runner.yaml", "deployment/bootstrap-v3.json",
|
||||
)
|
||||
GITEA_CI_V4_ENTRIES = (
|
||||
"docker-compose.gitea-ci.yml", "runner.yaml", "deployment/bootstrap-v4.json",
|
||||
)
|
||||
GITEA_CI_SOURCE_SHA256 = {
|
||||
"docker-compose.gitea-ci.yml": "851d22ae9823c30508a552ec6abb7f547ceda671f3ca77552fb7032bc807ae09",
|
||||
"runner.yaml": "8634e5427986423ccd8fe18e3bf5072c53addbf17f1efc1395b3a473671d78fe",
|
||||
@@ -63,6 +66,10 @@ GITEA_CI_V3_SOURCE_SHA256 = {
|
||||
"docker-compose.gitea-ci.yml": "775440b6a4d122793b8f1474a8a1a028ece98c4bebd54962e3418f0405c89c89",
|
||||
"runner.yaml": "c1e76972236b7610a167b2304967d401efdaabfd221229bdd55c63c98a34eea6",
|
||||
}
|
||||
GITEA_CI_V4_SOURCE_SHA256 = {
|
||||
"docker-compose.gitea-ci.yml": "dd218ef77a6505042484bbdb5cb329da043801a42e13af746fc8ba23c05e0f9c",
|
||||
"runner.yaml": "94d8e4d8345b2b5bc7c8923bff7c31ff59083ec7115d633af10152b93bcd9da6",
|
||||
}
|
||||
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"
|
||||
@@ -4932,7 +4939,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 + GITEA_CI_V3_ENTRIES or rel == "deployment":
|
||||
if rel in GITEA_CI_ENTRIES + GITEA_CI_V2_ENTRIES + GITEA_CI_V3_ENTRIES + GITEA_CI_V4_ENTRIES or rel == "deployment":
|
||||
return True
|
||||
die("Gitea CI accepts only its exact bootstrap contract")
|
||||
|
||||
@@ -31401,12 +31408,13 @@ 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
|
||||
v3 = tuple(entries) == GITEA_CI_V3_ENTRIES
|
||||
if tuple(entries) not in (GITEA_CI_ENTRIES, GITEA_CI_V2_ENTRIES, GITEA_CI_V3_ENTRIES):
|
||||
v4 = tuple(entries) == GITEA_CI_V4_ENTRIES
|
||||
if tuple(entries) not in (GITEA_CI_ENTRIES, GITEA_CI_V2_ENTRIES, GITEA_CI_V3_ENTRIES, GITEA_CI_V4_ENTRIES):
|
||||
die("Gitea CI bootstrap entry set mismatch")
|
||||
version = "v3" if v3 else "v2" if v2 else "v1"
|
||||
version = "v4" if v4 else "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")
|
||||
sources = GITEA_CI_V3_SOURCE_SHA256 if v3 else GITEA_CI_SOURCE_SHA256
|
||||
sources = GITEA_CI_V4_SOURCE_SHA256 if v4 else 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}")
|
||||
@@ -31422,10 +31430,12 @@ def validate_gitea_ci_payload(payload_dir, entries, release_id):
|
||||
"publishedPorts": [],
|
||||
"capacity": 1,
|
||||
}
|
||||
if v2 or v3:
|
||||
if v2 or v3 or v4:
|
||||
expected["enrollment"] = "import-dctouch-staging-to-root-private-runtime"
|
||||
if v3:
|
||||
expected["resourceProfile"] = "synology-cpu-shares-v1"
|
||||
if v4:
|
||||
expected["resourceProfile"] = "synology-cpuset-v1"
|
||||
if descriptor != expected:
|
||||
die("Gitea CI bootstrap descriptor mismatch")
|
||||
return descriptor
|
||||
@@ -31584,6 +31594,18 @@ def gitea_ci_inventory():
|
||||
return result
|
||||
|
||||
|
||||
def gitea_ci_check_affinity(pid, exact=False):
|
||||
if type(pid) is not int or pid < 0 or (exact and pid == 0):
|
||||
die("Gitea CI CPU affinity process identity is invalid")
|
||||
try:
|
||||
available = os.sched_getaffinity(pid)
|
||||
except (AttributeError, OSError):
|
||||
die("Gitea CI CPU affinity cannot be verified")
|
||||
valid = available == {7} if exact else 7 in available
|
||||
if not valid:
|
||||
die("Gitea CI requires logical CPU7 affinity")
|
||||
|
||||
|
||||
def gitea_ci_host_capabilities(entries):
|
||||
result = subprocess.run([str(DOCKER), "info", "--format", "{{json .}}"],
|
||||
capture_output=True, text=True, check=True, timeout=30)
|
||||
@@ -31599,16 +31621,23 @@ def gitea_ci_host_capabilities(entries):
|
||||
"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 = ["MemoryLimit"]
|
||||
if tuple(entries) == GITEA_CI_V4_ENTRIES:
|
||||
required += ["CPUShares", "CPUSet", "SwapLimit"]
|
||||
elif tuple(entries) == GITEA_CI_V3_ENTRIES:
|
||||
required.append("PidsLimit")
|
||||
required.append("CPUShares")
|
||||
else:
|
||||
required += ["CpuCfsPeriod", "CpuCfsQuota", "SwapLimit"]
|
||||
required += ["PidsLimit", "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")
|
||||
if tuple(entries) == GITEA_CI_V4_ENTRIES:
|
||||
if type(raw.get("NCPU")) is not int or raw["NCPU"] < 8:
|
||||
die("Gitea CI CPU7 profile requires at least eight logical CPUs")
|
||||
gitea_ci_check_affinity(0)
|
||||
return report
|
||||
|
||||
|
||||
@@ -31616,12 +31645,12 @@ 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 + GITEA_CI_V3_ENTRIES):
|
||||
if any((GITEA_CI_ROOT / rel).exists() for rel in GITEA_CI_ENTRIES + GITEA_CI_V2_ENTRIES + GITEA_CI_V3_ENTRIES + GITEA_CI_V4_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) in (GITEA_CI_V2_ENTRIES, GITEA_CI_V3_ENTRIES):
|
||||
if tuple(entries) in (GITEA_CI_V2_ENTRIES, GITEA_CI_V3_ENTRIES, GITEA_CI_V4_ENTRIES):
|
||||
preflight_gitea_ci_v2_enrollment()
|
||||
else:
|
||||
read_gitea_ci_enrollment()
|
||||
@@ -31638,7 +31667,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) in (GITEA_CI_V2_ENTRIES, GITEA_CI_V3_ENTRIES)
|
||||
token = (import_gitea_ci_v2_enrollment() if tuple(entries) in (GITEA_CI_V2_ENTRIES, GITEA_CI_V3_ENTRIES, GITEA_CI_V4_ENTRIES)
|
||||
else read_gitea_ci_enrollment())
|
||||
for directory in (GITEA_CI_ROOT / "data", GITEA_CI_ROOT / "secrets"):
|
||||
if directory.is_symlink():
|
||||
@@ -31685,14 +31714,22 @@ def accept_gitea_ci_container(info, entries=GITEA_CI_ENTRIES):
|
||||
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:
|
||||
v4 = tuple(entries) == GITEA_CI_V4_ENTRIES
|
||||
if v4 or 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
|
||||
valid_pids = host.get("PidsLimit") in (None, 0, -1) if v4 else host.get("PidsLimit") == 128
|
||||
if v4:
|
||||
valid_cpu = valid_cpu and host.get("CpusetCpus") == "7"
|
||||
if host.get("MemorySwap") != 512 * 1024 ** 2:
|
||||
die("Gitea CI daemon memory/swap limit mismatch")
|
||||
if (host.get("Memory") != 512 * 1024 ** 2
|
||||
or not valid_cpu or host.get("PidsLimit") != 128):
|
||||
or not valid_cpu or not valid_pids):
|
||||
die("Gitea CI daemon resource limit mismatch")
|
||||
if v4:
|
||||
gitea_ci_check_affinity(info.get("State", {}).get("Pid"), exact=True)
|
||||
expected_mounts = {
|
||||
"/config/runner.yaml": (str(GITEA_CI_ROOT / "runner.yaml"), False),
|
||||
"/data": (str(GITEA_CI_ROOT / "data"), True),
|
||||
@@ -32398,7 +32435,10 @@ 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")
|
||||
if tuple(entries) == GITEA_CI_V3_ENTRIES:
|
||||
if tuple(entries) == GITEA_CI_V4_ENTRIES:
|
||||
print("ci_cpu=cpuset:7;shared_by_daemon_and_job;relative_shares=64,128;capacity=1")
|
||||
print("ci_memory_and_swap=daemon:512MiB,job:2GiB;ci_pids=not-enforced-kernel-unsupported")
|
||||
elif 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:
|
||||
@@ -32406,7 +32446,7 @@ def plan_artifact(artifact):
|
||||
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) in (GITEA_CI_V2_ENTRIES, GITEA_CI_V3_ENTRIES):
|
||||
if tuple(entries) in (GITEA_CI_V2_ENTRIES, GITEA_CI_V3_ENTRIES, GITEA_CI_V4_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")
|
||||
|
||||
Reference in New Issue
Block a user