.f0rge/ci/steps/08_image.sh 5.3 KiB 140 lines Raw
1 #!/bin/sh2 # 08_image: the control image builds, then the generic per-bundle image3 # pipeline builds the mock bundle's own image and runs the container gate4 # against that final image.5 #6 # The CI runner is local because the container gates need the host Docker7 # socket. A host without docker fails: the step exists to catch a broken image,8 # and silently passing hides it.9 set -eu10 11 root=$(cd "$(dirname "$0")/../../.." && pwd)12 13 if ! command -v docker >/dev/null 2>&1; then14     echo "08_image: docker is required; install docker or run this step on a host that has it" >&215     exit 116 fi17 18 cd "$root"19 target=${CARGO_TARGET_DIR:-$root/target}20 case "$target" in21     /*) ;;22     *) target=$root/$target ;;23 esac24 25 # The staging boundary is tested before a real build: source and build files26 # under engine/ and src/model/ are accepted, including small ambiguous files27 # (.pth, .bin), while a large .bin weight must fail in prepare before any28 # Docker layer is written.29 weight=plugins/mock/x64-cpu/engine/weights.bin30 staging_engine='plugins/mock/x64-cpu/engine/staging-test.c plugins/mock/x64-cpu/engine/staging-test.cpp plugins/mock/x64-cpu/engine/CMakeLists.txt plugins/mock/x64-cpu/engine/staging-test.pth plugins/mock/x64-cpu/engine/staging-test.bin'31 staging_src=plugins/mock/x64-cpu/src/model/staging-test.rs32 staging_model=plugins/mock/x64-cpu/engine/model/staging-test.txt33 fake_docker=34 cleanup() {35     rm -f "$weight"36     for file in $staging_engine; do rm -f "$file"; done37     rm -f "$staging_src" "$staging_model"38     rmdir plugins/mock/x64-cpu/src/model plugins/mock/x64-cpu/engine/model 2>/dev/null || true39     [ -z "${fake_docker:-}" ] || rm -rf "$fake_docker"40 }41 trap cleanup EXIT HUP INT TERM42 for file in $staging_engine; do43     printf 'a staging test\n' >"$file"44 done45 mkdir -p "$(dirname "$staging_src")" "$(dirname "$staging_model")"46 printf 'a staging test\n' >"$staging_src"47 printf 'a staging test\n' >"$staging_model"48 if ! ./ops/images.sh build mock/x64-cpu >/tmp/inf3r-image-source-test.log 2>&1; then49     echo "08_image: a source or build file failed staging" >&250     cat /tmp/inf3r-image-source-test.log >&251     exit 152 fi53 for file in $staging_engine; do rm -f "$file"; done54 rm -f "$staging_src" "$staging_model"55 rmdir plugins/mock/x64-cpu/src/model plugins/mock/x64-cpu/engine/model 2>/dev/null || true56 57 dd if=/dev/zero of="$weight" bs=1M count=2 2>/dev/null58 if ./ops/images.sh build mock/x64-cpu >/tmp/inf3r-image-weight-test.log 2>&1; then59     echo "08_image: a .bin weight passed staging" >&260     exit 161 fi62 grep -q 'staged a weight file' /tmp/inf3r-image-weight-test.log || {63     echo "08_image: the .bin weight failed for the wrong reason" >&264     cat /tmp/inf3r-image-weight-test.log >&265     exit 166 }67 rm -f "$weight"68 69 if ! docker build -f docker/Containerfile -t inf3r:ci .; then70     echo "08_image: control image build failed" >&271     exit 172 fi73 74 # Record the resolved control bases and fail if the image does not carry the75 # digest-pinned references in docker/control.lock.76 mkdir -p "$target"77 control_lock=$target/control.lock78 : >"$control_lock"79 for base in rust debian uv; do80     ref=$(awk -F '\t' -v b="$base" '!/^#/ && $1 == b { print $2; exit }' docker/control.lock)81     label=$(docker image inspect --format "{{index .Config.Labels \"org.inf3r.control.base.$base\"}}" inf3r:ci)82     [ "$label" = "$ref" ] || {83         echo "08_image: control base $base is $label, not $ref" >&284         exit 185     }86     printf '%s\t%s\n' "$base" "$label" >>"$control_lock"87 done88 printf 'control bases\n'89 cat "$control_lock"90 91 # The generic pipeline stages one bundle plus the shared SDK workspace, then92 # runs the bundle's own Dockerfile. The plugin is compiled in the builder93 # container; no host cargo runs and no model/ directory is staged.94 if ! ./ops/images.sh build mock/x64-cpu; then95     echo "08_image: bundle image build failed" >&296     exit 197 fi98 if ! ./ops/images.sh check mock/x64-cpu; then99     echo "08_image: bundle image check failed" >&2100     exit 1101 fi102 bundle_image=$(./ops/images.sh tag mock/x64-cpu)103 104 # A failed docker run is not a clean scan. A wrapper that fails only `run`105 # proves that `check` refuses instead of swallowing the error.106 real_docker=$(command -v docker)107 fake_docker=$(mktemp -d "${TMPDIR:-/tmp}/inf3r-fake-docker.XXXXXX")108 cat >"$fake_docker/docker" <<EOF109 #!/bin/sh110 if [ "\$1" = run ]; then111     echo 'fake docker run failed' >&2112     exit 1113 fi114 exec "$real_docker" "\$@"115 EOF116 chmod +x "$fake_docker/docker"117 if PATH="$fake_docker:$PATH" ./ops/images.sh check mock/x64-cpu >/tmp/inf3r-image-docker-test.log 2>&1; then118     echo "08_image: a failed docker run passed the weight check" >&2119     exit 1120 fi121 grep -q 'weight scan failed' /tmp/inf3r-image-docker-test.log || {122     echo "08_image: the failed docker run gave the wrong result" >&2123     cat /tmp/inf3r-image-docker-test.log >&2124     exit 1125 }126 rm -rf "$fake_docker"127 fake_docker=128 129 # The image is not useful if the container gate cannot start it. The mock is130 # CPU-only, so this runs on a CPU-only host as well. The socket root is short131 # because a Unix socket path must fit SUN_LEN.132 cli=$target/debug/inf3r133 [ -x "$cli" ] || cli=$target/release/inf3r134 [ -x "$cli" ] || {135     echo "08_image: no inf3r cli at $target/{debug,release}/inf3r" >&2136     exit 1137 }138 rm -rf /tmp/inf3r-ci-gate139 "$cli" verify --container --deploy docker/config/gate.toml \140     --image "$bundle_image" --socket-dir /tmp/inf3r-ci-gate --budget 2m mock/x64-cpu