| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #!/bin/sh
- # Build unbound-sec and (optionally) push + sign with cosign in keyless mode.
- #
- # COSIGN_SIGN=1 requires a REGISTRY_IMAGE (a registry reference, e.g.
- # ghcr.io/ric/unbound-sec:latest). The image is pushed first, then the exact
- # digest that was pushed is signed — so the signature is bound to the built
- # image, not to a (possibly pre-existing) registry tag.
- #
- # Verification (identity conditions live on the VERIFY side, not sign):
- # cosign verify --certificate-identity-regexp 'ric@.*' \
- # --certificate-oidc-issuer-regexp 'accounts\.google\.com' \
- # "$REGISTRY_IMAGE@sha256:<digest>"
- set -eu
- IMAGE="${IMAGE:-unbound-sec:latest}"
- # Version from the latest git tag (vX.Y.Z) if available, else "dev".
- VERSION="$(git describe --tags --always 2>/dev/null | sed 's/^v//' || echo dev)"
- # A unique cache-buster per run is NOT used here on purpose: reproducible
- # builds rely on layer caching. The test suite passes --build-arg CACHEBUST
- # when it needs a forced rebuild.
- docker build \
- --pull \
- -t "$IMAGE" \
- -t "unbound-sec:v${VERSION}" \
- .
- if [ "${COSIGN_SIGN:-0}" = "1" ]; then
- REG="${REGISTRY_IMAGE:-}"
- if [ -z "$REG" ]; then
- echo "COSIGN_SIGN=1 requires REGISTRY_IMAGE (registry reference)" >&2
- exit 1
- fi
- case "$REG" in
- */*) : ;; # has a registry/host component
- *) echo "REGISTRY_IMAGE must be a registry reference (host/repo:tag)" >&2; exit 1 ;;
- esac
- echo "==> pushing $REG"
- docker tag "$IMAGE" "$REG"
- docker push "$REG"
- # Sign the exact digest that was just pushed (not a mutable tag).
- FULL="$(docker inspect --format='{{index .RepoDigests 0}}' "$REG")"
- DG="${FULL##*@}" # sha256:...
- echo "==> cosign keyless sign $REG@${DG}"
- cosign sign --yes "$REG@${DG}"
- echo "==> done. Verify with:"
- echo " cosign verify --certificate-identity-regexp '<you>@.*' \\"
- echo " --certificate-oidc-issuer-regexp 'accounts\\.google\\.com' \\"
- echo " $REG@${DG}"
- fi
|