diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index ae45337c..4bc2a7ec 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -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) diff --git a/scripts/build-linux-package.py b/scripts/build-linux-package.py index 7a23774e..4ad5f4c1 100644 --- a/scripts/build-linux-package.py +++ b/scripts/build-linux-package.py @@ -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.', diff --git a/scripts/docker_smoke_http.py b/scripts/docker_smoke_http.py new file mode 100644 index 00000000..e593aa94 --- /dev/null +++ b/scripts/docker_smoke_http.py @@ -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) diff --git a/scripts/smoke-cli-container.py b/scripts/smoke-cli-container.py index c0ed8e47..5b51aaf1 100644 --- a/scripts/smoke-cli-container.py +++ b/scripts/smoke-cli-container.py @@ -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) diff --git a/scripts/smoke-runtime-image.py b/scripts/smoke-runtime-image.py index d4ca1f25..9ecce45c 100644 --- a/scripts/smoke-runtime-image.py +++ b/scripts/smoke-runtime-image.py @@ -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()