Files
leleka/scripts/smoke-cli-container.py
T
Pavlo Ratushnyi 982f4ce326
Linux / verify (pull_request) Successful in 3m50s
Linux / keyless-cuda (pull_request) Skipped
Linux / static-cuda-package (pull_request) Skipped
Linux / hosted-cuda-package (pull_request) Skipped
Linux / linux-cli-container (pull_request) Successful in 24s
Linux / linux-static-cli (pull_request) Failing after 2m41s
Linux / release-cli (pull_request) Skipped
ci: probe container on isolated runner network
2026-10-05 22:32:26 +02:00

101 lines
4.6 KiB
Python

#!/usr/bin/env python3
"""Exercise the actual CLI-only scratch image; never starts an inference worker."""
import json
from pathlib import Path
import socket
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)
def main(image):
name = 'strata-cli-smoke-' + uuid.uuid4().hex
network = 'strata-cli-smoke-' + uuid.uuid4().hex
job_container = socket.gethostname()
common = ['--name', name, '--read-only', '--user', '65532:65532',
'--cap-drop', 'ALL', '--security-opt', 'no-new-privileges']
root = Path(__file__).resolve().parents[1]
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
def get(address, route):
try:
with opener.open(f'{address}{route}', timeout=2) as response:
return response.status, json.load(response)
except urllib.error.HTTPError as error:
return error.code, json.load(error)
inspected_job = docker('inspect', '--format', '{{.Id}}', job_container, check=False)
attached_to_runner_container = inspected_job.returncode == 0 and bool(inspected_job.stdout.strip())
if attached_to_runner_container:
job_container = inspected_job.stdout.strip()
network_created = False
network_connected = False
try:
version = docker('run', '--rm', *common, '--network', 'none', image, '--version').stdout
assert version.startswith('strata-next '), version
license_text = docker('run', '--rm', *common, '--network', 'none', image,
'--engine-license').stdout
assert license_text == (root / 'engine/strata/LICENSE').read_text()
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
if attached_to_runner_container:
# In Gitea, the Actions job itself is a sibling container on gitea-net;
# its 127.0.0.1 is not the Docker host where -p publishes ports. Use a
# private per-test network and join only this job plus the smoke image.
docker('network', 'create', '--internal', network)
network_created = True
docker('network', 'connect', network, job_container)
network_connected = True
docker('run', '-d', *common, '--network', network,
'--network-alias', name, '-e', 'STRATA_BIND=0.0.0.0:8081', image, 'serve')
address = f'http://{name}:8081'
else:
# Native VM runners can reach host-loopback port publication.
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
address = f'http://{binding}'
deadline = time.monotonic() + 15
while True:
try:
status, health = get(address, '/health')
assert status == 200 and health == {'status': 'ok'}, (status, health)
break
except (OSError, urllib.error.URLError, AssertionError) as error:
if time.monotonic() >= deadline:
state = docker('inspect', '--format', '{{json .State}}', name,
check=False).stdout
logs = docker('logs', name, check=False).stdout
raise AssertionError(
f'CLI service did not become healthy; state={state}; logs={logs}'
) from error
time.sleep(0.1)
status, ready = get(address, '/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)
assert state['ExitCode'] == 0 and not state['OOMKilled'], state
print('CLI OCI passed: actual image, exact upstream license, no embedded engine/model, '
'non-root read-only health200/ready503, graceful stop. No GPU inference qualified.')
finally:
docker('rm', '-f', name, check=False)
if network_connected:
docker('network', 'disconnect', network, job_container, check=False)
if network_created:
docker('network', 'rm', network, check=False)
if __name__ == '__main__':
main(sys.argv[1])