build.sh 1.1 KB

1234567891011121314151617181920212223242526272829
  1. #!/bin/sh
  2. # Build unbound-sec and (optionally) sign with cosign in keyless mode.
  3. #
  4. # Usage:
  5. # ./build.sh # build only
  6. # COSIGN_SIGN=1 ./build.sh # build + cosign sign (needs keyless
  7. # # capability: GHCR via GITHUB_TOKEN,
  8. # # or local keyless via OIDC provider)
  9. set -eu
  10. IMAGE="${IMAGE:-unbound-sec:latest}"
  11. VERSION="${VERSION:-$(git describe --tags --always 2>/dev/null || echo dev)}"
  12. echo "==> building $IMAGE (version=$VERSION)"
  13. docker build \
  14. --build-arg "COMMIT=${GITHUB_SHA:-$(git rev-parse HEAD 2>/dev/null || echo none)}" \
  15. --label "org.opencontainers.image.version=$VERSION" \
  16. --label "org.opencontainers.image.source=https://github.com/ric/unbound-sec" \
  17. -t "$IMAGE" .
  18. if [ "${COSIGN_SIGN:-0}" = "1" ]; then
  19. echo "==> cosign keyless sign"
  20. cosign sign --yes \
  21. --certificate-identity-regexp "https://token.actions.githubusercontent.com" \
  22. --certificate-oidc-issuer-regexp "https://token.actions.githubusercontent.com" \
  23. "$IMAGE"
  24. fi
  25. echo "==> done: $IMAGE"