#!/usr/bin/env bash # Smoke-tests an Urutau probe image: it is small (under 15 MB), runs as a # non-root user, ships CA certificates and zoneinfo, has a HEALTHCHECK, answers # --help, and refuses to start without a hub (a clear error, no panic). # The image is FROM scratch: there is no shell, so nothing runs through `sh`. # # scripts/smoke-probe.sh set -euo pipefail image=${1:?usage: smoke-probe.sh } max_bytes=$((15 * 1000 * 1000)) fail() { echo "smoke-probe: $*" >&2; exit 1; } # In the release the image was pushed by buildx, not loaded: pull it first. docker image inspect "$image" >/dev/null 2>&1 || docker pull -q "$image" >/dev/null size=$(docker image inspect -f '{{.Size}}' "$image") [ "$size" -lt "$max_bytes" ] || fail "image is $size bytes (limit $max_bytes)" out=$(docker run --rm "$image" --help 2>&1) || fail "'--help' failed: $out" [ -n "$out" ] || fail "'--help' printed nothing" grep -qi 'probe' <<<"$out" || fail "'--help' does not mention the probe: $out" [ "$(docker inspect -f '{{.Config.User}}' "$image")" = 10001:10001 ] || fail "the probe must run as 10001:10001" [ "$(docker inspect -f '{{if .Config.Healthcheck}}yes{{end}}' "$image")" = yes ] || fail "image has no HEALTHCHECK" [ -z "$(docker inspect -f '{{range $p, $_ := .Config.ExposedPorts}}{{$p}}{{end}}' "$image")" ] || fail "the probe must not expose a port" # CA certificates and zoneinfo are in the image (copy them out: no shell inside). cid=$(docker create "$image") trap 'docker rm -f "$cid" >/dev/null 2>&1 || true' EXIT docker cp "$cid:/etc/ssl/certs/ca-certificates.crt" - >/dev/null || fail "CA certificates missing" docker cp "$cid:/usr/share/zoneinfo/America/Sao_Paulo" - >/dev/null || fail "zoneinfo missing" # Without configuration the probe stops with a message that names the missing setting. if out=$(docker run --rm "$image" 2>&1); then fail "the probe must not start without URUTAU_HUB"; fi grep -qi 'hub' <<<"$out" || fail "the missing-hub error does not mention the hub: $out" echo "smoke-probe: $image ok ($((size / 1000)) kB)"