#!/usr/bin/env bash set -euo pipefail IMAGE="" ARCHIVE="" usage() { cat <<'USAGE' Usage: scripts/docker/verify_image.sh --image [--archive ] USAGE } while [[ "$#" -gt 0 ]]; do case "$1" in --image) IMAGE="$2" shift 2 ;; --archive) ARCHIVE="$2" shift 2 ;; -h|--help) usage exit 0 ;; *) echo "unknown option: $1" >&2 usage >&2 exit 2 ;; esac done [[ -n "$IMAGE" ]] || { echo "--image is required" >&2; usage >&2; exit 2; } command -v docker >/dev/null 2>&1 || { echo "missing required command: docker" >&2; exit 2; } expect_status() { local expected="$1" shift local actual=0 "$@" >/dev/null 2>&1 || actual=$? if [[ "$actual" -ne "$expected" ]]; then echo "unexpected exit status: expected=$expected actual=$actual command=$*" >&2 return 1 fi } docker image inspect "$IMAGE" >/dev/null IMAGE_ARCH="$(docker image inspect --format '{{.Architecture}}' "$IMAGE")" case "$IMAGE_ARCH" in amd64|arm64) IMAGE_PLATFORM="linux/$IMAGE_ARCH" ;; *) echo "unsupported image architecture: $IMAGE_ARCH" >&2; exit 2 ;; esac expect_status 2 docker run --rm --platform "$IMAGE_PLATFORM" --entrypoint /opt/panda-rpki-validator/bin/panda-rpki-validator "$IMAGE" --help expect_status 0 docker run --rm --platform "$IMAGE_PLATFORM" --entrypoint /opt/panda-rpki-validator/bin/panda-rpki-validator-daemon "$IMAGE" --help expect_status 2 docker run --rm --platform "$IMAGE_PLATFORM" --entrypoint /opt/panda-rpki-validator/entrypoint.sh "$IMAGE" --help expect_status 0 docker run --rm --platform "$IMAGE_PLATFORM" "$IMAGE" run --help docker run --rm --platform "$IMAGE_PLATFORM" --entrypoint /bin/bash "$IMAGE" -ceu \ 'test -x /opt/panda-rpki-validator/run_validator.sh; \ test -s /opt/panda-rpki-validator/fixtures/manifest.toml; \ test -s /opt/panda-rpki-validator/fixtures/tal/afrinic.tal; \ test -s /opt/panda-rpki-validator/fixtures/ta/afrinic-ta.cer' if [[ -n "$ARCHIVE" ]]; then [[ -f "$ARCHIVE" ]] || { echo "missing image archive: $ARCHIVE" >&2; exit 2; } gzip -t "$ARCHIVE" gunzip -c "$ARCHIVE" | docker load >/dev/null fi echo "image smoke passed: $IMAGE"