fix(ci): isolate Docker probes and workspace package provenance
This commit is contained in:
@@ -169,7 +169,7 @@ jobs:
|
||||
from pathlib import Path
|
||||
info=json.loads((Path(os.environ['CUDAToolkit_ROOT'])/'TOOLKIT-PROVENANCE.json').read_text())
|
||||
packages=subprocess.check_output(['docker','run','--rm','--platform','linux/amd64','--network','none',
|
||||
os.environ['CUDA_BUILDER_IMAGE'],'dpkg-query','-W','-f=${binary:Package}=${Version}\\n',
|
||||
os.environ['CUDA_BUILDER_IMAGE'],'dpkg-query','-W','-f=${binary:Package}=${Version}'+chr(10),
|
||||
'binutils','ca-certificates','cmake','gcc-13','g++-13','git','make','python3'],text=True).splitlines()
|
||||
gcc=subprocess.check_output(['docker','run','--rm','--platform','linux/amd64','--network','none',
|
||||
os.environ['CUDA_BUILDER_IMAGE'],'g++-13','--version'],text=True)
|
||||
|
||||
@@ -184,7 +184,7 @@ def assemble(args):
|
||||
provenance = {'schema_version': 1, 'kind': 'cpu-fixture' if args.cpu_fixture else 'static-cuda-preview',
|
||||
'source_revision': args.revision, 'target': TARGET, 'engine': info,
|
||||
'engine_elf_audit': audit, 'outer_elf_audit': outer,
|
||||
'cargo_lock_sha256': sha256(REPO / 'control-plane/Cargo.lock'),
|
||||
'cargo_lock_sha256': sha256(REPO / 'Cargo.lock'),
|
||||
'rustc': run(['rustc', '--version']), 'cargo': run(['cargo', '--version']),
|
||||
'gpu_tested': False, 'model_tested': False, 'clean_node_tested': False,
|
||||
'qualification': 'Exact payload identity, outer ELF and GPU-hidden loader help only; no inference.',
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
"""CPU-only Docker HTTP probe that also works with a remote Docker daemon."""
|
||||
import json
|
||||
import subprocess
|
||||
import uuid
|
||||
|
||||
|
||||
# Official Python 3.11.17 slim OCI index, including Linux amd64 and arm64.
|
||||
# Python belongs to this disposable test helper, never the serving image.
|
||||
PROBE_IMAGE = 'python@sha256:0dd364ba7e10242f07755449e3a3d0e35f9efd987952737b90def6709ab0c5ce'
|
||||
ISOLATION = ['--read-only', '--user', '65532:65532', '--cap-drop', 'ALL',
|
||||
'--security-opt', 'no-new-privileges', '-e', 'CUDA_VISIBLE_DEVICES=',
|
||||
'-e', 'NVIDIA_VISIBLE_DEVICES=void']
|
||||
PROBE = '''import json,sys,urllib.error,urllib.request
|
||||
route,payload=sys.argv[1:]
|
||||
body=None if payload == 'null' else json.dumps(json.loads(payload)).encode()
|
||||
request=urllib.request.Request('http://127.0.0.1:8081'+route,data=body,
|
||||
headers={'Content-Type':'application/json'})
|
||||
opener=urllib.request.build_opener(urllib.request.ProxyHandler({}))
|
||||
try:
|
||||
response=opener.open(request,timeout=5)
|
||||
except urllib.error.HTTPError as error:
|
||||
response=error
|
||||
with response:
|
||||
print(json.dumps({'status':response.status,'body':json.load(response)}))
|
||||
'''
|
||||
|
||||
|
||||
def docker(*args, check=True, timeout=30):
|
||||
return subprocess.run(['docker', *map(str, args)], check=check,
|
||||
capture_output=True, text=True, timeout=timeout)
|
||||
|
||||
|
||||
def prepare_probe():
|
||||
if docker('image', 'inspect', PROBE_IMAGE, check=False).returncode:
|
||||
docker('pull', PROBE_IMAGE, timeout=120)
|
||||
identity = docker('image', 'inspect', '--format', '{{.Id}}', PROBE_IMAGE).stdout.strip()
|
||||
print(f'Isolated HTTP probe: {PROBE_IMAGE}, local image {identity}', flush=True)
|
||||
|
||||
|
||||
def request(container, route, body=None):
|
||||
name = 'strata-http-probe-' + uuid.uuid4().hex
|
||||
try:
|
||||
result = docker('run', '--rm', '--name', name, *ISOLATION,
|
||||
'--network', f'container:{container}', '--entrypoint', 'python3',
|
||||
PROBE_IMAGE, '-c', PROBE, route, json.dumps(body))
|
||||
decoded = json.loads(result.stdout)
|
||||
return decoded['status'], decoded['body']
|
||||
finally:
|
||||
docker('rm', '-f', name, check=False)
|
||||
@@ -2,32 +2,18 @@
|
||||
"""Exercise the actual CLI-only scratch image; never starts an inference worker."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
import uuid
|
||||
|
||||
|
||||
def docker(*args, check=True):
|
||||
return subprocess.run(['docker', *args], check=check, capture_output=True,
|
||||
text=True, timeout=30)
|
||||
import subprocess
|
||||
from docker_smoke_http import ISOLATION, docker, prepare_probe, request
|
||||
|
||||
|
||||
def main(image):
|
||||
name = 'strata-cli-smoke-' + uuid.uuid4().hex
|
||||
common = ['--name', name, '--read-only', '--user', '65532:65532',
|
||||
'--cap-drop', 'ALL', '--security-opt', 'no-new-privileges']
|
||||
common = ['--name', name, *ISOLATION]
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
|
||||
|
||||
def get(port, route):
|
||||
try:
|
||||
with opener.open(f'http://127.0.0.1:{port}{route}', timeout=2) as response:
|
||||
return response.status, json.load(response)
|
||||
except urllib.error.HTTPError as error:
|
||||
return error.code, json.load(error)
|
||||
prepare_probe()
|
||||
|
||||
try:
|
||||
version = docker('run', '--rm', *common, '--network', 'none', image, '--version').stdout
|
||||
@@ -38,21 +24,18 @@ def main(image):
|
||||
info = json.loads(docker('run', '--rm', *common, '--network', 'none', image,
|
||||
'engine-info').stdout)
|
||||
assert info['embedded'] is False and info['model_bundled'] is False, info
|
||||
docker('run', '-d', *common, '-p', '127.0.0.1::8081',
|
||||
'-e', 'STRATA_BIND=0.0.0.0:8081', image, 'serve')
|
||||
binding = docker('port', name, '8081/tcp').stdout.strip()
|
||||
assert binding.startswith('127.0.0.1:'), binding
|
||||
port = int(binding.rsplit(':', 1)[1])
|
||||
docker('run', '-d', *common, '--network', 'none',
|
||||
'-e', 'STRATA_BIND=127.0.0.1:8081', image, 'serve')
|
||||
deadline = time.monotonic() + 15
|
||||
while True:
|
||||
try:
|
||||
assert get(port, '/health') == (200, {'status': 'ok'})
|
||||
assert request(name, '/health') == (200, {'status': 'ok'})
|
||||
break
|
||||
except (OSError, AssertionError):
|
||||
except (OSError, AssertionError, subprocess.CalledProcessError):
|
||||
if time.monotonic() >= deadline:
|
||||
raise
|
||||
time.sleep(0.1)
|
||||
status, ready = get(port, '/ready')
|
||||
status, ready = request(name, '/ready')
|
||||
assert status == 503 and ready['ready'] is False, (status, ready)
|
||||
docker('stop', '--time', '10', name)
|
||||
state = json.loads(docker('inspect', '--format', '{{json .State}}', name).stdout)
|
||||
|
||||
@@ -7,12 +7,8 @@ import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import urllib.request
|
||||
import uuid
|
||||
|
||||
|
||||
def docker(*args, check=True):
|
||||
return subprocess.run(['docker', *map(str, args)], check=check, capture_output=True, text=True, timeout=30)
|
||||
from docker_smoke_http import ISOLATION, PROBE_IMAGE, docker, prepare_probe, request as probe_request
|
||||
|
||||
|
||||
def main(receipt):
|
||||
@@ -24,32 +20,41 @@ def main(receipt):
|
||||
spec = importlib.util.spec_from_file_location('helper', Path(__file__).with_name('smoke-worker-cancel.py'))
|
||||
helper = importlib.util.module_from_spec(spec); spec.loader.exec_module(helper)
|
||||
name = 'strata-runtime-smoke-' + uuid.uuid4().hex
|
||||
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
|
||||
volume = name + '-fixture'
|
||||
staging = name + '-stage'
|
||||
prepare_probe()
|
||||
with tempfile.TemporaryDirectory(prefix='strata-container-fixture-') as tmp:
|
||||
root = Path(tmp); root.chmod(0o755)
|
||||
helper.tokenizer(root)
|
||||
(root/'config.json').write_text(json.dumps({'bind': '0.0.0.0:8081', 'model': 'embedded-fixture',
|
||||
(root/'config.json').write_text(json.dumps({'bind': '127.0.0.1:8081', 'model': 'embedded-fixture',
|
||||
'engine_probe': True, 'engine': {'executable': '@embedded', 'args': ['/tmp/worker.pid'],
|
||||
'tokenizer_dir': '/fixture', 'startup_timeout_s': 5, 'max_restarts': 1}}))
|
||||
for path in root.iterdir(): path.chmod(0o644)
|
||||
try:
|
||||
docker('volume', 'create', volume)
|
||||
docker('run', '-d', '--name', staging, *ISOLATION, '--network', 'none',
|
||||
'--mount', f'type=volume,src={volume},dst=/fixture',
|
||||
'--entrypoint', 'python3', PROBE_IMAGE, '-c', 'import time; time.sleep(120)')
|
||||
# Stream files through the Docker API; runner paths need not exist
|
||||
# on the daemon host. The serving container gets a read-only volume.
|
||||
docker('cp', str(root) + '/.', staging + ':/fixture')
|
||||
docker('rm', '-f', staging)
|
||||
docker('run', '-d', '--name', name, '--platform', 'linux/amd64', '--read-only',
|
||||
'--cap-drop', 'ALL', '--security-opt', 'no-new-privileges', '--user', '65532:65532',
|
||||
'--tmpfs', '/tmp:rw,nosuid,nodev,size=64m', '-e', 'CUDA_VISIBLE_DEVICES=',
|
||||
'-e', 'NVIDIA_VISIBLE_DEVICES=void', '-p', '127.0.0.1::8081',
|
||||
'--mount', f'type=bind,src={root},dst=/fixture,readonly', image,
|
||||
'-e', 'NVIDIA_VISIBLE_DEVICES=void', '--network', 'none',
|
||||
'--mount', f'type=volume,src={volume},dst=/fixture,readonly', image,
|
||||
'serve', '--config', '/fixture/config.json')
|
||||
port = int(docker('port', name, '8081/tcp').stdout.strip().rsplit(':', 1)[1])
|
||||
def request(route, body=None):
|
||||
req = urllib.request.Request(f'http://127.0.0.1:{port}{route}',
|
||||
data=json.dumps(body).encode() if body else None, headers={'Content-Type': 'application/json'})
|
||||
with opener.open(req, timeout=5) as response: return json.load(response)
|
||||
status, result = probe_request(name, route, body)
|
||||
assert status == 200, (status, result)
|
||||
return result
|
||||
def ready():
|
||||
deadline = time.monotonic()+15
|
||||
while time.monotonic()<deadline:
|
||||
try:
|
||||
if request('/status')['ready']: return
|
||||
except OSError: pass
|
||||
except (OSError, subprocess.CalledProcessError): pass
|
||||
time.sleep(.1)
|
||||
raise AssertionError('container worker did not become ready')
|
||||
def generate():
|
||||
@@ -70,8 +75,14 @@ def main(receipt):
|
||||
state = json.loads(docker('inspect','--format','{{json .State}}',name).stdout)
|
||||
assert state['ExitCode']==0 and not state['OOMKilled']
|
||||
print('Combined CPU OCI: Responses A exact, worker crash/restart A exact, nonroot/read-only, graceful stop. No GPU/model qualification.')
|
||||
except Exception:
|
||||
logs = docker('logs', name, check=False)
|
||||
print('Owned CPU fixture container logs:', logs.stdout, logs.stderr, file=sys.stderr)
|
||||
raise
|
||||
finally:
|
||||
docker('rm','-f',name,check=False)
|
||||
docker('rm','-f',staging,check=False)
|
||||
docker('volume','rm',volume,check=False)
|
||||
|
||||
|
||||
if __name__=='__main__': main(sys.argv[1])
|
||||
|
||||
@@ -50,7 +50,14 @@ def main():
|
||||
generated = run(str(binary), 'service-unit', '--config', str(config),
|
||||
'--working-dir', str(odd), '--env-file', str(env_file)).stdout
|
||||
unit.write_text(generated)
|
||||
verify = run('systemd-analyze', '--user', 'verify', str(unit), check=False)
|
||||
# Offline verification still initializes a user manager context. CI's
|
||||
# runner container has no login session or /run/user directory; provide
|
||||
# only this invocation with a private runtime directory, not a live bus.
|
||||
verify_runtime = root / 'verify-runtime'
|
||||
verify_runtime.mkdir(mode=0o700)
|
||||
verify_env = dict(os.environ, XDG_RUNTIME_DIR=str(verify_runtime))
|
||||
verify = run('systemd-analyze', '--user', 'verify', str(unit),
|
||||
check=False, env=verify_env)
|
||||
assert verify.returncode == 0, verify.stderr
|
||||
# The renderer must fail closed, before printing any installable unit.
|
||||
bad = run(str(binary), 'service-unit', '--config', 'relative.json',
|
||||
|
||||
@@ -139,6 +139,38 @@ class PackageTests(unittest.TestCase):
|
||||
build.assert_not_called()
|
||||
self.assertEqual((output / 'old').read_text(), 'keep')
|
||||
|
||||
def test_assembly_records_workspace_lock_digest(self):
|
||||
from types import SimpleNamespace
|
||||
engine = self.root / 'engine'
|
||||
engine.write_bytes(b'CPU package fixture')
|
||||
workspace_lock = self.root / 'Cargo.lock'
|
||||
workspace_lock.write_text('version = 4\n')
|
||||
target = self.root / 'target'
|
||||
binary = target / pkg.TARGET / 'release/strata-next'
|
||||
binary.parent.mkdir(parents=True)
|
||||
binary.write_bytes(b'outer executable fixture')
|
||||
args = SimpleNamespace(engine=engine, sha256=pkg.sha256(engine), revision='a' * 40,
|
||||
output=self.root / 'final', cargo_target_dir=target, cpu_fixture=True)
|
||||
info = {'embedded': True, 'sha256': args.sha256, 'declared_source_revision': args.revision,
|
||||
'bytes': engine.stat().st_size, 'target_os': 'linux', 'target_arch': 'x86_64'}
|
||||
published = {}
|
||||
|
||||
def capture_publication(source, output):
|
||||
published.update(json.loads((source / 'PROVENANCE.json').read_text()))
|
||||
|
||||
with (patch.object(pkg, 'REPO', self.root),
|
||||
patch.object(pkg.platform, 'system', return_value='Linux'),
|
||||
patch.object(pkg.platform, 'machine', return_value='x86_64'),
|
||||
patch.object(pkg, 'source_check'), patch.object(pkg.subprocess, 'run'),
|
||||
patch.object(pkg, 'static_outer', return_value={'fixture': True}),
|
||||
patch.object(pkg, 'run', side_effect=[json.dumps(info), '', 'rustc fixture', 'cargo fixture']),
|
||||
patch.object(pkg, 'publish', side_effect=capture_publication)):
|
||||
pkg.assemble(args)
|
||||
self.assertEqual(published['cargo_lock_sha256'], pkg.sha256(workspace_lock))
|
||||
self.assertFalse(published['gpu_tested'])
|
||||
self.assertFalse(published['model_tested'])
|
||||
self.assertFalse(list(self.root.glob('.final.stage-*')))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user