diff --git a/.github/workflows/qualify.yml b/.github/workflows/qualify.yml index 94fee3c..2769519 100644 --- a/.github/workflows/qualify.yml +++ b/.github/workflows/qualify.yml @@ -25,6 +25,29 @@ jobs: git status --porcelain > evidence/status.txt go version > evidence/toolchain.txt go env -json GOOS GOARCH GOVERSION > evidence/platform.json + - name: Prepare required Docker fixtures + shell: bash + run: | + set -euo pipefail + docker_bin="$(command -v docker)" + if [ ! -x /usr/local/bin/docker ]; then + sudo ln -s "$docker_bin" /usr/local/bin/docker + fi + docker version > evidence/docker-version.txt + endpoint="$(docker context inspect --format '{{.Endpoints.docker.Host}}')" + case "$endpoint" in + unix://*) socket="${endpoint#unix://}" ;; + *) echo 'Qualification requires a local Unix Docker socket' >&2; exit 1 ;; + esac + docker pull alpine:3.22 > evidence/alpine-pull.txt + docker pull debian:bookworm-slim > evidence/debian-pull.txt + image="$(docker image inspect --format '{{.Id}}' alpine:3.22)" + bash_image="$(docker image inspect --format '{{.Id}}' debian:bookworm-slim)" + python3 scripts/prepare_container_fixtures.py --docker /usr/local/bin/docker \ + --socket "$socket" --image "$image" --bash-image "$bash_image" \ + --output "$RUNNER_TEMP/harness-fixtures" + cp "$RUNNER_TEMP/harness-fixtures/fixtures.json" evidence/fixtures.json + cat "$RUNNER_TEMP/harness-fixtures/fixtures.env" >> "$GITHUB_ENV" - name: Build and vet run: | go build ./... > evidence/build.txt 2>&1 diff --git a/.gitignore b/.gitignore index c1fec07..bea9fe2 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,6 @@ support-agent-audit.jsonl # Env .env .env.local + +# Keep native qualification setup with its runner. +!scripts/QUALIFICATION.md diff --git a/scripts/QUALIFICATION.md b/scripts/QUALIFICATION.md new file mode 100644 index 0000000..96375fe --- /dev/null +++ b/scripts/QUALIFICATION.md @@ -0,0 +1,28 @@ +# Native qualification fixtures + +Qualification requires a working local Docker daemon with a Unix socket and +permission for the runner user to use it. The workflow prepares fixtures before +running tests and fails if the daemon is unavailable. It does not start or +provision a daemon, and does not accept skipped container tests. + +Linux GitHub runners can use their installed Docker service. A macOS runner must +have a Docker-capable environment provisioned before this workflow can succeed. +Do not assume the standard hosted macOS image provides it. See GitHub's runner +limitations: https://docs.github.com/en/actions/reference/runners/larger-runners . +Local macOS qualification remains possible using the explicitly authorised local +daemon; retain exact commit, raw results and platform identity with that evidence. + +The workflow pulls the named fixture base versions, resolves platform-specific +immutable image IDs and records them in evidence/fixtures.json before tests. +These IDs freeze one run; tags are not cross-run immutable references. To reproduce +an earlier run, load its recorded image IDs and invoke the helper directly with +those IDs instead of resolving current tags. + +prepare_container_fixtures.py accepts only loaded immutable IDs, checks Linux and +matching image architectures, then creates a minimal implicit-volume negative +fixture with build networking disabled. It uses a private Docker configuration +and explicit socket. The generated fixtures.env is suitable for GITHUB_ENV; it +contains image IDs and a local socket path, never provider credentials. + +The helper retains images for the caller's test run and does not prune shared +Docker state. Native test cases own and remove their individual containers. diff --git a/scripts/prepare_container_fixtures.py b/scripts/prepare_container_fixtures.py new file mode 100644 index 0000000..62ce107 --- /dev/null +++ b/scripts/prepare_container_fixtures.py @@ -0,0 +1,60 @@ +"""Prepare explicit local Docker fixtures and record immutable test settings. + +Images must already be loaded. This script never pulls images or starts a daemon. +""" +import argparse +import hashlib +import json +from pathlib import Path +import re +import subprocess +import tempfile + + +def prepare(docker, socket, image, bash_image, output): + for path in (docker, socket, output): + if not Path(path).is_absolute(): + raise ValueError('absolute Docker, socket and output paths required') + if any(c in socket for c in ('\n', '\r', '\0')): + raise ValueError('socket path cannot contain environment delimiters') + for value in (image, bash_image): + if not re.fullmatch(r'sha256:[0-9a-f]{64}', value): + raise ValueError('loaded immutable image IDs required') + output=Path(output);output.mkdir(mode=0o700) + with tempfile.TemporaryDirectory(prefix='harness-fixtures-') as temporary: + root=Path(temporary);config=root/'config';config.mkdir() + prefix=[docker,'--config',str(config),'--host','unix://'+socket] + def run(args): + return subprocess.check_output(prefix+args,stderr=subprocess.PIPE,timeout=120) + inspected=[] + for identity in (image,bash_image): + info=json.loads(run(['image','inspect',identity]))[0] + if info['Id']!=identity or info['Os']!='linux': + raise ValueError('Linux image identity mismatch') + inspected.append(dict(id=identity,architecture=info['Architecture'])) + if inspected[0]['architecture']!=inspected[1]['architecture']: + raise ValueError('fixture image architectures differ') + dockerfile=('FROM '+image+'\nVOLUME /implicit-fixture-volume\n').encode() + (root/'Dockerfile').write_bytes(dockerfile) + # Untagged derived image is identified solely by its captured ID. + raw=run(['build','--pull=false','--network=none','--quiet',str(root)]) + volume=raw.decode().strip() + if not re.fullmatch(r'sha256:[0-9a-f]{64}',volume): + raise ValueError('derived image ID missing') + info=json.loads(run(['image','inspect',volume]))[0] + if '/implicit-fixture-volume' not in (info['Config'].get('Volumes') or {}): + raise ValueError('negative volume fixture missing implicit volume') + settings=dict(HARNESS_TEST_CONTAINER_IMAGE=image,HARNESS_TEST_BASH_IMAGE=bash_image, + HARNESS_TEST_VOLUME_IMAGE=volume,HARNESS_TEST_CONTAINER_SOCKET=socket) + report=dict(status='prepared',environment=settings,images=inspected, + volume_dockerfile_sha256=hashlib.sha256(dockerfile).hexdigest(), + note='Loaded images are retained; no tests or publication performed.') + (output/'fixtures.json').write_text(json.dumps(report,indent=2)+'\n') + (output/'fixtures.env').write_text(''.join(k+'='+v+'\n' for k,v in settings.items())) + return report + + +if __name__=='__main__': + p=argparse.ArgumentParser(description=__doc__) + for name in ('docker','socket','image','bash-image','output'):p.add_argument('--'+name,required=True) + a=p.parse_args();r=prepare(a.docker,a.socket,a.image,a.bash_image,a.output);print(json.dumps(r))