github.com/cilium/cilium@v1.16.2/images/scripts/get-image-digest.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright Authors of Cilium
     4  # SPDX-License-Identifier: Apache-2.0
     5  
     6  set -o errexit
     7  set -o pipefail
     8  set -o nounset
     9  
    10  if [ "$#" -ne 1 ] ; then
    11    echo "$0 supports exactly 1 argument"
    12    exit 1
    13  fi
    14  
    15  function getSHA() {
    16    if command -v sha256sum &> /dev/null; then
    17      sha256sum | cut -d " " -f 1
    18    elif command -v openssl &> /dev/null; then
    19      openssl sha256 | cut -d " " -f 2
    20    else
    21      echo "$0 requires sha256sum or openssl to be installed."
    22      exit 1
    23    fi
    24  }
    25  
    26  inspect=$(docker buildx imagetools inspect "${1}" --raw 2>/dev/null | awk 'NR>1 { print p } { p = $0 } END { printf("%s", $0) }' | getSHA )
    27  # shellcheck disable=SC2181
    28  if [ $? -eq 0 ]; then
    29    echo "sha256:${inspect}"
    30  else
    31    echo ""
    32  fi