#!/usr/bin/env python3 """Actual combined CPU image proof. Never use with a model/CUDA image.""" import importlib.util import json from pathlib import Path import subprocess import sys import tempfile import time import uuid from docker_smoke_http import ISOLATION, PROBE_IMAGE, docker, prepare_probe, request as probe_request def main(receipt): proof = json.loads(Path(receipt).read_text()) assert proof['kind'] == 'cpu-fixture' and proof['gpu_tested'] is False image = proof['image'] label = docker('inspect', '--format', '{{index .Config.Labels "io.strata.package-kind"}}', image).stdout.strip() assert label == 'cpu-fixture' 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 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': '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', '--network', 'none', '--mount', f'type=volume,src={volume},dst=/fixture,readonly', image, 'serve', '--config', '/fixture/config.json') def request(route, body=None): status, result = probe_request(name, route, body) assert status == 200, (status, result) return result def ready(): deadline = time.monotonic()+15 while time.monotonic()