Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
CRW-653 support optional extra processing to check backup registries (#…
Browse files Browse the repository at this point in the history
…430)

* CRW-653 support optional extra processing to check backup registries; tweak console output to report digest and source image when passing, and which image failed if skipping

Change-Id: Ieee4cca1344b2dd4f86c10b9e4ceae2eb02dcdd8
Signed-off-by: nickboldt <nboldt@redhat.com>

* disable shellcheck SC1091

Change-Id: I1f0a4139ae2aad3359f3fc9c30fa08dc328d893a
Signed-off-by: nickboldt <nboldt@redhat.com>

* shellcheck disable SC1090 too

Change-Id: I798d8146e67bdb1619242f1c1d2c803b05dde3ee
Signed-off-by: nickboldt <nboldt@redhat.com>

* externalize SCRIPT_DIR and make shellcheck happy too

Change-Id: I3e8cfb96e79de1b8dd441075a6f56e8fa9a604fc
Signed-off-by: nickboldt <nboldt@redhat.com>
  • Loading branch information
nickboldt authored Mar 31, 2020
1 parent 670e639 commit a59804b
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions build/scripts/write_image_digests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,36 @@
# SPDX-License-Identifier: EPL-2.0
#

SCRIPT_DIR=$(cd "$(dirname "$0")" || exit; pwd)
LOG_FILE="/tmp/image_digests.log"

function handle_error() {
echo " Could not read image metadata through skopeo inspect; skipping"
the_image="$1"
echo " Could not read image metadata through skopeo inspect; skip $the_image"
echo -n " Reason: "
sed 's|^| |g' $LOG_FILE
}

readarray -d '' metas < <(find "$1" -name 'meta.yaml' -print0)
for image in $(yq -r '.spec | .containers[]?,.initContainers[]? | .image' "${metas[@]}" | sort | uniq); do
echo "Rewriting image $image"
# Need to look before we leap in case image is not accessible
if ! image_data=$(skopeo inspect "docker://${image}" 2>"$LOG_FILE"); then
handle_error
digest="$(skopeo inspect "docker://${image}" 2>"$LOG_FILE" | jq -r '.Digest')"
if [[ ${digest} ]]; then
echo " $digest # ${image}"
else
# for other build methods or for falling back to other registries when not found, can apply transforms here
if [[ -x "${SCRIPT_DIR}/write_image_digests_alternate_urls.sh" ]]; then
# since extension file may not exist, disable this check
# shellcheck disable=SC1090
source "${SCRIPT_DIR}/write_image_digests_alternate_urls.sh"
fi
fi

# don't rewrite if we couldn't get a digest from either the basic image or the alternative image
if [[ ! ${digest} ]]; then
handle_error "$image"
continue
fi
# Grab digest from image metadata json
digest=$(echo "$image_data" | jq -r '.Digest')

echo " to use digest $digest"
digest_image="${image%:*}@${digest}"

# Rewrite images to use sha-256 digests
Expand Down

0 comments on commit a59804b

Please sign in to comment.