diff --git a/scripts/smoke-runtime-image.py b/scripts/smoke-runtime-image.py index d4ca1f25..8842653c 100644 --- a/scripts/smoke-runtime-image.py +++ b/scripts/smoke-runtime-image.py @@ -12,7 +12,12 @@ import uuid def docker(*args, check=True): - return subprocess.run(['docker', *map(str, args)], check=check, capture_output=True, text=True, timeout=30) + try: + return subprocess.run(['docker', *map(str, args)], check=check, + capture_output=True, text=True, timeout=30) + except subprocess.CalledProcessError as error: + detail = (error.stderr or '').strip()[-2048:] + raise RuntimeError(f'docker command failed ({error.returncode}): {detail}') from None def main(receipt): @@ -24,6 +29,9 @@ 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 + fixture_container = 'strata-runtime-fixture-' + uuid.uuid4().hex + fixture_volume = 'strata-runtime-fixture-' + uuid.uuid4().hex + base = proof['base'] opener = urllib.request.build_opener(urllib.request.ProxyHandler({})) with tempfile.TemporaryDirectory(prefix='strata-container-fixture-') as tmp: root = Path(tmp); root.chmod(0o755) @@ -33,11 +41,21 @@ def main(receipt): 'tokenizer_dir': '/fixture', 'startup_timeout_s': 5, 'max_restarts': 1}})) for path in root.iterdir(): path.chmod(0o644) try: + # The Docker daemon may be outside the job container. A job-local + # /tmp bind source is therefore not guaranteed to exist on it. + # `docker cp` streams this synthetic fixture through the CLI into + # a named volume; the tested image then mounts that volume read-only. + docker('volume', 'create', fixture_volume) + docker('create', '--name', fixture_container, '--platform', 'linux/amd64', + '--mount', f'type=volume,src={fixture_volume},dst=/fixture', + '--entrypoint', '/bin/sleep', base, '30') + docker('cp', f'{root}/.', f'{fixture_container}:/fixture/') + docker('rm', fixture_container) 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, + '--mount', f'type=volume,src={fixture_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): @@ -72,6 +90,8 @@ def main(receipt): print('Combined CPU OCI: Responses A exact, worker crash/restart A exact, nonroot/read-only, graceful stop. No GPU/model qualification.') finally: docker('rm','-f',name,check=False) + docker('rm','-f',fixture_container,check=False) + docker('volume','rm',fixture_volume,check=False) if __name__=='__main__': main(sys.argv[1])