Add Synology CPUSet CI bootstrap for actual NAS capabilities
This commit is contained in:
+23
-12
@@ -17,13 +17,15 @@ been accepted. Later repositories receive explicit registrations/policies.
|
||||
- Runner and Node images use official Linux amd64 manifest digests (not mutable
|
||||
tags), resolved from Docker Hub on 2026-09-29. The deploy runner pulls exactly
|
||||
these two digests. No repository-provided image names or commands.
|
||||
- Current Synology v3 profile: daemon CPU shares 64, 512 MiB RAM, 128 PIDs,
|
||||
readonly root filesystem. Build jobs: one at a time, CPU shares 128,
|
||||
2 GiB RAM, 256 PIDs, no privileged mode, no host bind
|
||||
- Current Synology v4 profile: daemon and the single job share logical CPU7
|
||||
through CPUSet. Their combined CPU ceiling is one logical CPU. Daemon:
|
||||
CPU shares64, 512 MiB RAM+swap, readonly root filesystem. Job: CPU shares128,
|
||||
2 GiB RAM+swap, no privileged mode, no host bind
|
||||
mounts, no host execution label and no Docker socket in job containers.
|
||||
- CPU shares give low relative priority during contention, not a hard CPU
|
||||
quota. Job swap uses the Docker/host default. The v1/v2 historical profiles
|
||||
retain their exact 0.5/1 NanoCPU quotas and original immutable config hashes.
|
||||
- CPU shares also give low relative priority during contention. The NAS kernel
|
||||
lacks a PIDs controller, so v4 does not set or claim a process-count limit.
|
||||
V1/v2 retain their exact 0.5/1 NanoCPU quotas; v3 retains its shares-only/PIDs
|
||||
profile. Historical configuration hashes are not changed.
|
||||
- No published ports or host networking. Runner cache and metrics listeners
|
||||
are disabled. Communication uses outbound HTTPS to the existing Gitea.
|
||||
- Only the trusted runner daemon mounts the Docker socket. That daemon is
|
||||
@@ -61,11 +63,13 @@ file is part of the artifact, source backup, journal or diagnostic output.
|
||||
|
||||
The bootstrap accepts no existing installed CI descriptor or CI container.
|
||||
Preflight reads Docker's actual resource capabilities before any runtime
|
||||
mutation, and reports only allowlisted version/kernel/resource fields. V3
|
||||
requires Linux amd64 plus CPU shares, memory and PIDs controls. V1/v2 additionally
|
||||
require CFS period/quota and swap accounting. Missing or non-boolean capability
|
||||
values do not pass. Preflight also checks at least 8 GiB free disk and 3 GiB
|
||||
currently available memory.
|
||||
mutation, and reports only allowlisted version/kernel/resource fields. V4
|
||||
requires Linux amd64, CPUSet, CPU shares, memory/swap controls, at least eight
|
||||
logical CPUs and CPU7 available in the installer's affinity. Acceptance also
|
||||
verifies the actual daemon affinity is exactly CPU7. V3 requires a PIDs
|
||||
controller; V1/v2 additionally require CFS period/quota. Missing or non-boolean
|
||||
required capability values do not pass. Preflight also checks at least 8 GiB
|
||||
free disk and 3 GiB currently available memory.
|
||||
|
||||
The v2 apply on 2026-09-29 imported the private token successfully and pulled
|
||||
the pinned images, but Docker rejected `NanoCPUs`: this NAS kernel does not
|
||||
@@ -75,13 +79,20 @@ Artifact `gitea-ci-bootstrap-v2-20260929-002` is terminal failed and must not be
|
||||
restaged or retried. V3 uses separate reviewed `synology-v3/` configurations and
|
||||
`bootstrap-v3.json`; historical payloads remain byte-for-byte reproducible.
|
||||
|
||||
The subsequent v3 plan established the actual host matrix: Docker24.0.2,
|
||||
kernel4.4.302+, cgroupv1, x86_64, eight logical CPUs, MemTotal16743616512.
|
||||
CPUSet/CPUShares/MemoryLimit/SwapLimit=true; CFS period/quota and PidsLimit=false.
|
||||
It stopped before apply. V4 uses this verified matrix, with separate
|
||||
`synology-v4/` templates and `bootstrap-v4.json`. The private token from the
|
||||
rolled-back v2 attempt is reused. Neither v2 nor v3 is the next install target.
|
||||
|
||||
## Build and install
|
||||
|
||||
From a clean Platform commit:
|
||||
|
||||
```sh
|
||||
python3 -m unittest discover -s infra/gitea-ci -p 'test_*.py'
|
||||
python3 infra/gitea-ci/build_artifact.py --patch-id gitea-ci-bootstrap-v3-<unique-id> --source-commit <full-sha> --output-dir <output-dir>
|
||||
python3 infra/gitea-ci/build_artifact.py --patch-id gitea-ci-bootstrap-v4-<unique-id> --source-commit <full-sha> --output-dir <output-dir>
|
||||
```
|
||||
|
||||
The first use requires promotion of the reviewed root runner through the
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"schemaVersion": "nodedc.gitea-ci.bootstrap.v4",
|
||||
"releaseId": "__PATCH_ID__",
|
||||
"action": "bootstrap-build-runner",
|
||||
"repository": "SILVER/NODEDC_DEVICE_CORE",
|
||||
"instance": "https://git.dcserve.ru",
|
||||
"runnerName": "synology-device-core-build",
|
||||
"productionDeployEnabled": false,
|
||||
"publishedPorts": [],
|
||||
"capacity": 1,
|
||||
"enrollment": "import-dctouch-staging-to-root-private-runtime",
|
||||
"resourceProfile": "synology-cpuset-v1"
|
||||
}
|
||||
@@ -16,11 +16,14 @@ SOURCE = Path(__file__).resolve().parent
|
||||
ENTRIES = ("docker-compose.gitea-ci.yml", "runner.yaml", "deployment/bootstrap-v1.json")
|
||||
V2_ENTRIES = ("docker-compose.gitea-ci.yml", "runner.yaml", "deployment/bootstrap-v2.json")
|
||||
V3_ENTRIES = ("docker-compose.gitea-ci.yml", "runner.yaml", "deployment/bootstrap-v3.json")
|
||||
V4_ENTRIES = ("docker-compose.gitea-ci.yml", "runner.yaml", "deployment/bootstrap-v4.json")
|
||||
|
||||
|
||||
def entries_for(patch_id):
|
||||
if not re.fullmatch(r"gitea-ci-bootstrap-v[123]-[a-zA-Z0-9._-]{1,65}", patch_id):
|
||||
if not re.fullmatch(r"gitea-ci-bootstrap-v[1234]-[a-zA-Z0-9._-]{1,65}", patch_id):
|
||||
raise ValueError("invalid_bootstrap_identity")
|
||||
if patch_id.startswith("gitea-ci-bootstrap-v4-"):
|
||||
return V4_ENTRIES
|
||||
if patch_id.startswith("gitea-ci-bootstrap-v3-"):
|
||||
return V3_ENTRIES
|
||||
return V2_ENTRIES if patch_id.startswith("gitea-ci-bootstrap-v2-") else ENTRIES
|
||||
@@ -28,7 +31,7 @@ def entries_for(patch_id):
|
||||
|
||||
def bundle(patch_id, source=SOURCE):
|
||||
entries = entries_for(patch_id)
|
||||
config_source = source / "synology-v3" if entries == V3_ENTRIES else source
|
||||
config_source = source / "synology-v4" if entries == V4_ENTRIES else source / "synology-v3" if entries == V3_ENTRIES else source
|
||||
descriptor = json.loads((source / Path(entries[2]).name).read_text())
|
||||
if descriptor["releaseId"] != "__PATCH_ID__":
|
||||
raise ValueError("bootstrap_template_identity_mismatch")
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
services:
|
||||
build-runner:
|
||||
image: docker.io/gitea/runner@sha256:05e100d9c2268fb300f929cab014e9930591a2d66822454e175c1099d1464b14
|
||||
platform: linux/amd64
|
||||
pull_policy: never
|
||||
restart: unless-stopped
|
||||
read_only: true
|
||||
cpu_shares: 64
|
||||
cpuset: "7"
|
||||
mem_limit: 512m
|
||||
memswap_limit: 512m
|
||||
cap_drop: [ALL]
|
||||
security_opt: [no-new-privileges:true]
|
||||
tmpfs:
|
||||
- /tmp:rw,nosuid,nodev,size=134217728
|
||||
environment:
|
||||
HOME: /data
|
||||
XDG_CACHE_HOME: /data/.cache
|
||||
CONFIG_FILE: /config/runner.yaml
|
||||
GITEA_INSTANCE_URL: https://git.dcserve.ru
|
||||
GITEA_RUNNER_NAME: synology-device-core-build
|
||||
GITEA_RUNNER_REGISTRATION_TOKEN_FILE: /run/secrets/registration-token
|
||||
volumes:
|
||||
- type: bind
|
||||
source: /volume1/docker/nodedc-gitea-ci/runner.yaml
|
||||
target: /config/runner.yaml
|
||||
read_only: true
|
||||
bind: {create_host_path: false}
|
||||
- type: bind
|
||||
source: /volume1/docker/nodedc-gitea-ci/data
|
||||
target: /data
|
||||
bind: {create_host_path: false}
|
||||
- type: bind
|
||||
source: /volume1/docker/nodedc-gitea-ci/secrets/registration-token
|
||||
target: /run/secrets/registration-token
|
||||
read_only: true
|
||||
bind: {create_host_path: false}
|
||||
- type: bind
|
||||
source: /var/run/docker.sock
|
||||
target: /var/run/docker.sock
|
||||
read_only: true
|
||||
bind: {create_host_path: false}
|
||||
@@ -0,0 +1,26 @@
|
||||
log:
|
||||
level: info
|
||||
runner:
|
||||
file: /data/.runner
|
||||
capacity: 1
|
||||
timeout: 1h
|
||||
shutdown_timeout: 45m
|
||||
insecure: false
|
||||
fetch_interval: 5s
|
||||
env_file: ""
|
||||
envs:
|
||||
NODE_OPTIONS: --max-old-space-size=1536
|
||||
labels:
|
||||
- nodedc-node22-build:docker://docker.io/library/node@sha256:9887ee8a5e5aa4fb02e09f03cdf81ef1b52184665549836fe3943eb0c2eaefdb
|
||||
cache:
|
||||
enabled: false
|
||||
container:
|
||||
network: ""
|
||||
privileged: false
|
||||
options: --cpuset-cpus=7 --cpu-shares=128 --memory=2g --memory-swap=2g --cap-drop=ALL --security-opt=no-new-privileges
|
||||
valid_volumes: []
|
||||
docker_host: "-"
|
||||
force_pull: false
|
||||
bind_workdir: false
|
||||
metrics:
|
||||
enabled: false
|
||||
@@ -159,8 +159,8 @@ class BootstrapTests(unittest.TestCase):
|
||||
|
||||
def apply_in_synthetic_host(self, fail_health=False, version="v1"):
|
||||
expected_entries = RUNNER.GITEA_CI_ENTRIES
|
||||
if version in ("v2", "v3"):
|
||||
expected_entries = RUNNER.GITEA_CI_V3_ENTRIES if version == "v3" else RUNNER.GITEA_CI_V2_ENTRIES
|
||||
if version in ("v2", "v3", "v4"):
|
||||
expected_entries = getattr(RUNNER, "GITEA_CI_" + version.upper() + "_ENTRIES")
|
||||
self.artifact.write_bytes(build_artifact.bundle("gitea-ci-bootstrap-" + version + "-test-001"))
|
||||
host = self.root / "host"
|
||||
host.mkdir()
|
||||
@@ -256,6 +256,18 @@ class BootstrapTests(unittest.TestCase):
|
||||
self.assertEqual((app / "data/registration-marker").read_text(), "preserve-on-rollback")
|
||||
self.assertEqual(json.loads(paths["FAILED_STATE_FILE"].read_text())["rollback_status"], "ok:gitea-ci-bootstrap")
|
||||
|
||||
def test_v4_apply_and_receipt(self):
|
||||
paths, app, candidate, output = self.apply_in_synthetic_host(version="v4")
|
||||
self.assertTrue((app / "deployment/bootstrap-v4.json").is_file())
|
||||
self.assertEqual(json.loads(paths["STATE_FILE"].read_text())["status"], "ok")
|
||||
self.assertIn("deploy-ok patch=gitea-ci-bootstrap-v4-test-001", output)
|
||||
|
||||
def test_v4_rollback_preserves_identity(self):
|
||||
paths, app, candidate, output = self.apply_in_synthetic_host(fail_health=True, version="v4")
|
||||
self.assertFalse((app / "deployment/bootstrap-v4.json").exists())
|
||||
self.assertEqual((app / "data/registration-marker").read_text(), "preserve-on-rollback")
|
||||
self.assertEqual(json.loads(paths["FAILED_STATE_FILE"].read_text())["rollback_status"], "ok:gitea-ci-bootstrap")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -101,6 +101,7 @@ class SynologyV3Tests(unittest.TestCase):
|
||||
for patch, sha in (
|
||||
("gitea-ci-bootstrap-v1-20260929-001", "ba942839c5815d09ac8f3c8dc23acdcf53ad9ef098a74c26b14c8b81afcf6a20"),
|
||||
("gitea-ci-bootstrap-v2-20260929-002", "f9381e1ca59372f75277b6a6207ac9e35acaf29fd8ffa5dcf6afafa2daf80630"),
|
||||
("gitea-ci-bootstrap-v3-20260929-003", "9df6c741e2432c0cac9fe2f2c7d90348a61d75b28098146018467050ef21ab9a"),
|
||||
):
|
||||
self.assertEqual(hashlib.sha256(build_artifact.bundle(patch)).hexdigest(), sha)
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import io
|
||||
import json
|
||||
from contextlib import redirect_stdout
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
from types import SimpleNamespace
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import build_artifact
|
||||
from test_bootstrap import RUNNER, container_info
|
||||
|
||||
|
||||
def nas_capabilities():
|
||||
return {"Architecture": "x86_64", "CPUSet": True, "CPUShares": True,
|
||||
"CgroupVersion": "1", "CpuCfsPeriod": False, "CpuCfsQuota": False,
|
||||
"KernelVersion": "4.4.302+", "MemTotal": 16743616512,
|
||||
"MemoryLimit": True, "NCPU": 8, "OSType": "linux",
|
||||
"PidsLimit": False, "ServerVersion": "24.0.2", "SwapLimit": True}
|
||||
|
||||
|
||||
def v4_container():
|
||||
info = container_info()
|
||||
info["State"]["Pid"] = 1234
|
||||
info["HostConfig"].update({"NanoCpus": 0, "CpuShares": 64, "CpusetCpus": "7",
|
||||
"PidsLimit": None, "MemorySwap": 512 * 1024 ** 2})
|
||||
return info
|
||||
|
||||
|
||||
class SynologyV4Tests(unittest.TestCase):
|
||||
def query(self, info, affinity=None):
|
||||
with mock.patch.object(RUNNER.subprocess, "run", return_value=SimpleNamespace(stdout=json.dumps(info))):
|
||||
with mock.patch.object(RUNNER.os, "sched_getaffinity", create=True, return_value=set(range(8)) if affinity is None else affinity):
|
||||
with redirect_stdout(io.StringIO()):
|
||||
return RUNNER.gitea_ci_host_capabilities(RUNNER.GITEA_CI_V4_ENTRIES)
|
||||
|
||||
def test_actual_nas_capability_matrix_passes_without_cfs_or_pids(self):
|
||||
report = self.query(nas_capabilities())
|
||||
self.assertFalse(report["PidsLimit"])
|
||||
self.assertFalse(report["CpuCfsQuota"])
|
||||
self.assertTrue(report["CPUSet"])
|
||||
|
||||
def test_required_supported_controls_are_not_optional(self):
|
||||
for key in ("CPUSet", "CPUShares", "MemoryLimit", "SwapLimit"):
|
||||
info = nas_capabilities()
|
||||
info[key] = False
|
||||
with self.subTest(key=key), self.assertRaisesRegex(RUNNER.DeployError, key):
|
||||
self.query(info)
|
||||
|
||||
def test_cpu7_must_exist_and_be_available(self):
|
||||
info = nas_capabilities()
|
||||
info["NCPU"] = 4
|
||||
with self.assertRaisesRegex(RUNNER.DeployError, "eight logical"):
|
||||
self.query(info)
|
||||
with self.assertRaisesRegex(RUNNER.DeployError, "CPU7 affinity"):
|
||||
self.query(nas_capabilities(), affinity={0, 1})
|
||||
|
||||
def test_exact_runtime_cpu_affinity_memory_swap_and_no_pids_contract(self):
|
||||
with mock.patch.object(RUNNER.os, "sched_getaffinity", create=True, return_value={7}) as affinity:
|
||||
RUNNER.accept_gitea_ci_container(v4_container(), RUNNER.GITEA_CI_V4_ENTRIES)
|
||||
affinity.assert_called_once_with(1234)
|
||||
|
||||
def test_broad_affinity_unbounded_swap_or_reintroduced_unsupported_limit_rejected(self):
|
||||
for field, value in (("CpusetCpus", "0-7"), ("MemorySwap", -1), ("Memory", 0),
|
||||
("NanoCpus", 500000000), ("PidsLimit", 128), ("CpuShares", 0)):
|
||||
info = v4_container()
|
||||
info["HostConfig"][field] = value
|
||||
with mock.patch.object(RUNNER.os, "sched_getaffinity", create=True, return_value={7}):
|
||||
with self.subTest(field=field), self.assertRaises(RUNNER.DeployError):
|
||||
RUNNER.accept_gitea_ci_container(info, RUNNER.GITEA_CI_V4_ENTRIES)
|
||||
with mock.patch.object(RUNNER.os, "sched_getaffinity", create=True, return_value={0, 7}):
|
||||
with self.assertRaisesRegex(RUNNER.DeployError, "CPU7 affinity"):
|
||||
RUNNER.accept_gitea_ci_container(v4_container(), RUNNER.GITEA_CI_V4_ENTRIES)
|
||||
|
||||
def test_affinity_requires_a_positive_numeric_runtime_pid(self):
|
||||
for pid in (None, 0, -1, True, "1234"):
|
||||
with self.subTest(pid=pid), self.assertRaisesRegex(RUNNER.DeployError, "process identity"):
|
||||
RUNNER.gitea_ci_check_affinity(pid, exact=True)
|
||||
|
||||
def test_v4_bundle_pins_same_single_cpu_for_daemon_and_job(self):
|
||||
patch = "gitea-ci-bootstrap-v4-test-001"
|
||||
data = build_artifact.bundle(patch)
|
||||
self.assertEqual(data, build_artifact.bundle(patch))
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
artifact = root / "test.tgz"
|
||||
artifact.write_bytes(data)
|
||||
target = root / "unpacked"
|
||||
target.mkdir()
|
||||
_, entries, payload = RUNNER.load_artifact(artifact, target)
|
||||
self.assertEqual(tuple(entries), RUNNER.GITEA_CI_V4_ENTRIES)
|
||||
compose = (payload / "docker-compose.gitea-ci.yml").read_text()
|
||||
runner = (payload / "runner.yaml").read_text()
|
||||
self.assertIn('cpuset: "7"', compose)
|
||||
self.assertIn('memswap_limit: 512m', compose)
|
||||
self.assertNotIn('pids_limit:', compose)
|
||||
self.assertIn('--cpuset-cpus=7', runner)
|
||||
self.assertIn('--memory=2g --memory-swap=2g', runner)
|
||||
self.assertNotIn('--pids-limit', runner)
|
||||
(payload / "runner.yaml").write_text(runner.replace('--cpuset-cpus=7', '--cpuset-cpus=0-7'))
|
||||
with self.assertRaisesRegex(RUNNER.DeployError, "immutable configuration"):
|
||||
RUNNER.validate_gitea_ci_payload(payload, entries, patch)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user