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)
|
||||
|
||||
@@ -17,9 +17,13 @@ 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.
|
||||
- Runner: 0.5 CPU, 512 MiB RAM, 128 PIDs, readonly root filesystem. Build jobs:
|
||||
one at a time, 1 CPU, 2 GiB RAM, 256 PIDs, no privileged mode, no host bind
|
||||
- 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
|
||||
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.
|
||||
- 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
|
||||
@@ -56,9 +60,20 @@ creates the persistent `/data/.runner` identity on first start. Neither private
|
||||
file is part of the artifact, source backup, journal or diagnostic output.
|
||||
|
||||
The bootstrap accepts no existing installed CI descriptor or CI container.
|
||||
Preflight also checks at least 8 GiB free disk and 3 GiB currently available
|
||||
memory. If that capacity is unavailable, review smaller fixed limits or another
|
||||
worker placement; do not bypass the preflight.
|
||||
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.
|
||||
|
||||
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
|
||||
provide the needed CFS bandwidth control. Canonical rollback completed with
|
||||
`ok:gitea-ci-bootstrap`; the private enrollment is retained for v3 reuse.
|
||||
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.
|
||||
|
||||
## Build and install
|
||||
|
||||
@@ -66,7 +81,7 @@ 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-v2-<unique-id> --source-commit <full-sha> --output-dir <output-dir>
|
||||
python3 infra/gitea-ci/build_artifact.py --patch-id gitea-ci-bootstrap-v3-<unique-id> --source-commit <full-sha> --output-dir <output-dir>
|
||||
```
|
||||
|
||||
The first use requires promotion of the reviewed root runner through the
|
||||
@@ -107,4 +122,6 @@ registration retained. Existing Platform/Device/Gitea regression suites are
|
||||
also required before promotion.
|
||||
|
||||
References: [official runner configuration](https://docs.gitea.com/runner/configuration/),
|
||||
[Docker installation](https://docs.gitea.com/runner/installation/docker/).
|
||||
[Docker installation](https://docs.gitea.com/runner/installation/docker/),
|
||||
[Docker resource constraints](https://docs.docker.com/engine/containers/resource_constraints/),
|
||||
[Docker capabilities API](https://docs.docker.com/reference/api/engine/version/v1.40/).
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"schemaVersion": "nodedc.gitea-ci.bootstrap.v3",
|
||||
"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-cpu-shares-v1"
|
||||
}
|
||||
@@ -15,12 +15,20 @@ ROOT = Path(__file__).resolve().parents[2]
|
||||
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")
|
||||
|
||||
|
||||
def entries_for(patch_id):
|
||||
if not re.fullmatch(r"gitea-ci-bootstrap-v[123]-[a-zA-Z0-9._-]{1,65}", patch_id):
|
||||
raise ValueError("invalid_bootstrap_identity")
|
||||
if patch_id.startswith("gitea-ci-bootstrap-v3-"):
|
||||
return V3_ENTRIES
|
||||
return V2_ENTRIES if patch_id.startswith("gitea-ci-bootstrap-v2-") else ENTRIES
|
||||
|
||||
|
||||
def bundle(patch_id, source=SOURCE):
|
||||
if not re.fullmatch(r"gitea-ci-bootstrap-v[12]-[a-zA-Z0-9._-]{1,65}", patch_id):
|
||||
raise ValueError("invalid_bootstrap_identity")
|
||||
entries = V2_ENTRIES if patch_id.startswith("gitea-ci-bootstrap-v2-") else ENTRIES
|
||||
entries = entries_for(patch_id)
|
||||
config_source = 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")
|
||||
@@ -28,8 +36,8 @@ def bundle(patch_id, source=SOURCE):
|
||||
files = {
|
||||
"manifest.env": ("id=" + patch_id + "\ncomponent=gitea-ci\ntype=app-overlay\n").encode(),
|
||||
"files.txt": ("\n".join(entries) + "\n").encode(),
|
||||
"payload/docker-compose.gitea-ci.yml": (source / ENTRIES[0]).read_bytes(),
|
||||
"payload/runner.yaml": (source / ENTRIES[1]).read_bytes(),
|
||||
"payload/docker-compose.gitea-ci.yml": (config_source / ENTRIES[0]).read_bytes(),
|
||||
"payload/runner.yaml": (config_source / ENTRIES[1]).read_bytes(),
|
||||
"payload/" + entries[2]: (json.dumps(descriptor, indent=2) + "\n").encode(),
|
||||
}
|
||||
result = io.BytesIO()
|
||||
@@ -65,7 +73,7 @@ def main():
|
||||
"artifact": str(path.resolve()), "patchId": args.patch_id,
|
||||
"component": "gitea-ci", "sourceCommit": actual,
|
||||
"sha256": hashlib.sha256(data).hexdigest(),
|
||||
"entries": V2_ENTRIES if args.patch_id.startswith("gitea-ci-bootstrap-v2-") else ENTRIES,
|
||||
"entries": entries_for(args.patch_id),
|
||||
"services": ["build-runner"], "publishedPorts": [],
|
||||
"productionDeployEnabled": False,
|
||||
}))
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
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
|
||||
mem_limit: 512m
|
||||
pids_limit: 128
|
||||
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: --cpu-shares=128 --memory=2g --pids-limit=256 --cap-drop=ALL --security-opt=no-new-privileges
|
||||
valid_volumes: []
|
||||
docker_host: "-"
|
||||
force_pull: false
|
||||
bind_workdir: false
|
||||
metrics:
|
||||
enabled: false
|
||||
@@ -159,9 +159,9 @@ class BootstrapTests(unittest.TestCase):
|
||||
|
||||
def apply_in_synthetic_host(self, fail_health=False, version="v1"):
|
||||
expected_entries = RUNNER.GITEA_CI_ENTRIES
|
||||
if version == "v2":
|
||||
expected_entries = RUNNER.GITEA_CI_V2_ENTRIES
|
||||
self.artifact.write_bytes(build_artifact.bundle("gitea-ci-bootstrap-v2-test-001"))
|
||||
if version in ("v2", "v3"):
|
||||
expected_entries = RUNNER.GITEA_CI_V3_ENTRIES if version == "v3" else RUNNER.GITEA_CI_V2_ENTRIES
|
||||
self.artifact.write_bytes(build_artifact.bundle("gitea-ci-bootstrap-" + version + "-test-001"))
|
||||
host = self.root / "host"
|
||||
host.mkdir()
|
||||
names = {name: host / name.lower() for name in (
|
||||
@@ -244,6 +244,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_v3_apply_and_receipt(self):
|
||||
paths, app, candidate, output = self.apply_in_synthetic_host(version="v3")
|
||||
self.assertTrue((app / "deployment/bootstrap-v3.json").is_file())
|
||||
self.assertEqual(json.loads(paths["STATE_FILE"].read_text())["status"], "ok")
|
||||
self.assertIn("deploy-ok patch=gitea-ci-bootstrap-v3-test-001", output)
|
||||
|
||||
def test_v3_rollback_preserves_identity(self):
|
||||
paths, app, candidate, output = self.apply_in_synthetic_host(fail_health=True, version="v3")
|
||||
self.assertFalse((app / "deployment/bootstrap-v3.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()
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import copy
|
||||
import hashlib
|
||||
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 capabilities():
|
||||
return {"OSType": "linux", "Architecture": "x86_64", "NCPU": 8,
|
||||
"MemoryLimit": True, "SwapLimit": False, "PidsLimit": True,
|
||||
"CPUShares": True, "CPUSet": True, "CpuCfsQuota": False,
|
||||
"CpuCfsPeriod": False, "KernelVersion": "fixture-kernel",
|
||||
"RegistryConfig": {"do-not-log": "fixture-secret"},
|
||||
"HttpProxy": "fixture-private-proxy"}
|
||||
|
||||
|
||||
class SynologyV3Tests(unittest.TestCase):
|
||||
def query(self, info, entries=RUNNER.GITEA_CI_V3_ENTRIES):
|
||||
result = SimpleNamespace(stdout=json.dumps(info))
|
||||
output = io.StringIO()
|
||||
with mock.patch.object(RUNNER.subprocess, "run", return_value=result) as run:
|
||||
with redirect_stdout(output):
|
||||
report = RUNNER.gitea_ci_host_capabilities(entries)
|
||||
run.assert_called_once_with([str(RUNNER.DOCKER), "info", "--format", "{{json .}}"],
|
||||
capture_output=True, text=True, check=True, timeout=30)
|
||||
return report, output.getvalue()
|
||||
|
||||
def test_v3_supports_no_cfs_no_swap_without_claiming_cpu_quota(self):
|
||||
report, output = self.query(capabilities())
|
||||
self.assertFalse(report["CpuCfsQuota"])
|
||||
self.assertTrue(report["CPUShares"])
|
||||
self.assertNotIn("fixture-secret", output)
|
||||
self.assertNotIn("fixture-private-proxy", output)
|
||||
|
||||
def test_missing_memory_pids_or_shares_is_rejected_before_container_creation(self):
|
||||
for key in ("MemoryLimit", "PidsLimit", "CPUShares"):
|
||||
for value in (False, None, "true"):
|
||||
info = capabilities()
|
||||
info[key] = value
|
||||
with self.subTest(key=key, value=value), self.assertRaisesRegex(RUNNER.DeployError, key):
|
||||
self.query(info)
|
||||
|
||||
def test_cfs_profile_remains_rejected_on_incompatible_kernel(self):
|
||||
for entries in (RUNNER.GITEA_CI_ENTRIES, RUNNER.GITEA_CI_V2_ENTRIES):
|
||||
with self.assertRaisesRegex(RUNNER.DeployError, "CpuCfsPeriod,CpuCfsQuota,SwapLimit"):
|
||||
self.query(capabilities(), entries)
|
||||
|
||||
def test_wrong_architecture_is_rejected(self):
|
||||
info = capabilities()
|
||||
info["Architecture"] = "aarch64"
|
||||
with self.assertRaisesRegex(RUNNER.DeployError, "Linux amd64"):
|
||||
self.query(info)
|
||||
|
||||
def test_runtime_accepts_only_exact_cpu_shares_profile(self):
|
||||
info = container_info()
|
||||
info["HostConfig"].update({"NanoCpus": 0, "CpuShares": 64, "CpuQuota": 0, "CpuPeriod": 0})
|
||||
RUNNER.accept_gitea_ci_container(info, RUNNER.GITEA_CI_V3_ENTRIES)
|
||||
for field, value in (("CpuShares", 0), ("CpuShares", 1024), ("NanoCpus", 500000000),
|
||||
("CpuQuota", 50000), ("Memory", 0), ("PidsLimit", 0)):
|
||||
candidate = copy.deepcopy(info)
|
||||
candidate["HostConfig"][field] = value
|
||||
with self.subTest(field=field), self.assertRaisesRegex(RUNNER.DeployError, "resource limit"):
|
||||
RUNNER.accept_gitea_ci_container(candidate, RUNNER.GITEA_CI_V3_ENTRIES)
|
||||
with self.assertRaisesRegex(RUNNER.DeployError, "resource limit"):
|
||||
RUNNER.accept_gitea_ci_container(info, RUNNER.GITEA_CI_V2_ENTRIES)
|
||||
|
||||
def test_v3_artifact_pins_both_daemon_and_job_configuration(self):
|
||||
patch = "gitea-ci-bootstrap-v3-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_V3_ENTRIES)
|
||||
self.assertEqual(RUNNER.component_services("gitea-ci", entries), ("build-runner",))
|
||||
compose = (payload / "docker-compose.gitea-ci.yml").read_text()
|
||||
runner = (payload / "runner.yaml").read_text()
|
||||
self.assertIn("cpu_shares: 64", compose)
|
||||
self.assertNotIn("cpus:", compose)
|
||||
self.assertIn("--cpu-shares=128", runner)
|
||||
self.assertNotIn("--cpus=", runner)
|
||||
self.assertNotIn("--memory-swap", runner)
|
||||
self.assertIn("--memory=2g --pids-limit=256", runner)
|
||||
(payload / "runner.yaml").write_text(runner.replace("--cpu-shares=128", "--cpu-shares=1024"))
|
||||
with self.assertRaisesRegex(RUNNER.DeployError, "immutable configuration"):
|
||||
RUNNER.validate_gitea_ci_payload(payload, entries, patch)
|
||||
|
||||
def test_historical_artifact_bytes_remain_reproducible(self):
|
||||
for patch, sha in (
|
||||
("gitea-ci-bootstrap-v1-20260929-001", "ba942839c5815d09ac8f3c8dc23acdcf53ad9ef098a74c26b14c8b81afcf6a20"),
|
||||
("gitea-ci-bootstrap-v2-20260929-002", "f9381e1ca59372f75277b6a6207ac9e35acaf29fd8ffa5dcf6afafa2daf80630"),
|
||||
):
|
||||
self.assertEqual(hashlib.sha256(build_artifact.bundle(patch)).hexdigest(), sha)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user