60 lines
2.8 KiB
Python
60 lines
2.8 KiB
Python
"""Read-only, non-secret runner/runtime checks. Run as root on The-Ocean."""
|
|
import json
|
|
import stat
|
|
import subprocess
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
|
|
|
|
def run(*args):
|
|
return subprocess.check_output(args, text=True).strip()
|
|
|
|
|
|
template = ('{"state":{{json .State}},"host":{{json .HostConfig}},'
|
|
'"mounts":{{json .Mounts}},"image":{{json .Config.Image}},'
|
|
'"restart_count":{{.RestartCount}}}')
|
|
|
|
|
|
def inspect(name):
|
|
# Fetch selected fields, never container environment variables.
|
|
info = json.loads(run('docker', 'inspect', '--format', template, name))
|
|
state, host = info['state'], info['host']
|
|
return {
|
|
'name': name, 'image': info['image'], 'running': state['Running'],
|
|
'oom_killed': state['OOMKilled'], 'memory_bytes': host['Memory'],
|
|
'restart_count': info['restart_count'],
|
|
'memory_swap_bytes': host['MemorySwap'], 'nano_cpus': host['NanoCpus'],
|
|
'restart_policy': host['RestartPolicy']['Name'],
|
|
'port_bindings': host['PortBindings'],
|
|
'mount_destinations': [mount['Destination'] for mount in info['mounts']],
|
|
}
|
|
|
|
|
|
root = Path(run('docker', 'volume', 'inspect', '--format', '{{.Mountpoint}}', 'ssw590-local-runner-data'))
|
|
identity = root / '.runner'
|
|
registration = json.loads(identity.read_text())
|
|
assert registration.get('name') == 'ssw590-vince-local'
|
|
assert registration.get('address', '').rstrip('/') == 'https://git.yebilly.me'
|
|
assert isinstance(registration.get('token'), str) and registration['token']
|
|
assert stat.S_IMODE(identity.stat().st_mode) == 0o600
|
|
# Registration is checked in memory only. Do not serialize any of its values.
|
|
report = {'observed_at': datetime.now(timezone.utc).isoformat(),
|
|
'registration_validated_without_output': True, 'identity_mode': '0600',
|
|
'runner': inspect('ssw590-manual-runner'), 'active_jobs': []}
|
|
assert report['runner']['running'] and not report['runner']['oom_killed']
|
|
for name in run('docker', 'ps', '--format', '{{.Names}}').splitlines():
|
|
if name.startswith('GITEA-ACTIONS-TASK-'):
|
|
job = inspect(name)
|
|
assert job['memory_bytes'] == 512 * 1024 * 1024
|
|
assert job['memory_swap_bytes'] == 768 * 1024 * 1024
|
|
assert job['nano_cpus'] == 500000000
|
|
assert '/var/run/docker.sock' not in job['mount_destinations']
|
|
report['active_jobs'].append(job)
|
|
report['admission_check'] = run('docker', 'exec', 'ssw590-manual-runner', 'sh', '-c', '/admission-check.sh && echo passed')
|
|
report['compiler_image_id'] = run('docker', 'image', 'inspect', '--format', '{{.Id}}', 'ssw590-manual-ci:20261007')
|
|
assert report['compiler_image_id'] == 'sha256:5d24657a4578977fc7709165b82fc869f09a654a58ab4a0c8defd9d2cd662d5d'
|
|
report['memory'] = run('free', '-m')
|
|
report['disk'] = run('df', '-h', '/')
|
|
report['result'] = 'passed'
|
|
print(json.dumps(report, indent=2))
|