diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 80598740..f7c6fb91 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -208,7 +208,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install musl toolchain - run: apt-get update && apt-get install -y ca-certificates curl musl-tools cmake binutils python3-numpy systemd + run: apt-get update && apt-get install -y ca-certificates curl musl-tools cmake binutils python3-numpy - name: Install pinned Rust and target run: | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain none @@ -265,9 +265,7 @@ jobs: run: python3 scripts/smoke-mtp-pack.py target/x86_64-unknown-linux-musl/release/strata-next - name: Native runtime profile metadata admission run: python3 scripts/smoke-runtime-profile.py target/x86_64-unknown-linux-musl/release/strata-next - - name: Native systemd unit syntax and path safety - run: python3 scripts/smoke-service-unit.py target/x86_64-unknown-linux-musl/release/strata-next - - name: Native installer with actual isolated systemd user service + - name: Native systemd unit and lifecycle tests in isolated container run: | image="leleka-systemd-smoke:${GITHUB_RUN_ID}" container="leleka-systemd-smoke-${GITHUB_RUN_ID}" @@ -296,6 +294,11 @@ jobs: docker cp scripts/smoke-service-unit.py "$container:/tmp/smoke-service-unit.py" docker cp scripts/smoke-native-switch.py "$container:/tmp/smoke-native-switch.py" docker cp scripts/smoke-worker-cancel.py "$container:/tmp/smoke-worker-cancel.py" + docker exec --user "$uid" \ + --env HOME=/home/leleka \ + --env XDG_RUNTIME_DIR="/run/user/$uid" \ + --env DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$uid/bus" \ + "$container" python3 /tmp/smoke-service-unit.py /tmp/strata-next docker exec --user "$uid" \ --env HOME=/home/leleka \ --env XDG_RUNTIME_DIR="/run/user/$uid" \ diff --git a/scripts/smoke-cli-container.py b/scripts/smoke-cli-container.py index c0ed8e47..7fa79592 100644 --- a/scripts/smoke-cli-container.py +++ b/scripts/smoke-cli-container.py @@ -2,6 +2,7 @@ """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 @@ -17,18 +18,27 @@ def docker(*args, check=True): 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(port, route): + def get(address, route): try: - with opener.open(f'http://127.0.0.1:{port}{route}', timeout=2) as response: + 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 @@ -38,21 +48,40 @@ 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]) + 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: - assert get(port, '/health') == (200, {'status': 'ok'}) + status, health = get(address, '/health') + assert status == 200 and health == {'status': 'ok'}, (status, health) break - except (OSError, AssertionError): + except (OSError, urllib.error.URLError, AssertionError) as error: if time.monotonic() >= deadline: - raise + 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(port, '/ready') + 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) @@ -61,6 +90,10 @@ def main(image): '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__':