Skip to content

Commit

Permalink
Use digest if image ref has tag and digest
Browse files Browse the repository at this point in the history
The `sanity-inspect-image` Task is using `skopeo` that currently doesn't
support image references containing both tag and digest
(see containers/image#1736). The task has been
modified to check if the image reference contains both and in that case
the tag is removed and digest is used solely to reference the image.
  • Loading branch information
zregvart committed Nov 30, 2022
1 parent b3025e2 commit 46e71a2
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions task/sanity-inspect-image/0.1/sanity-inspect-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,18 @@ spec:
BASE_IMAGE_INSPECT=base_image_inspect.json
RAW_IMAGE_INSPECT=raw_image_inspect.json
echo "Inspecting manifest for source image $(params.IMAGE_URL)"
skopeo inspect --no-tags docker://$(params.IMAGE_URL) > $IMAGE_INSPECT
skopeo inspect --no-tags --raw docker://$(params.IMAGE_URL) > $RAW_IMAGE_INSPECT
IMAGE_URL="$(params.IMAGE_URL)"
# Given a tag and a the digest in the IMAGE_URL we opt to use the digest alone
# this is because containers/image currently doesn't support image references
# that contain both. See https://github.com/containers/image/issues/1736
if [[ "${IMAGE_URL}" == *":"*"@"* ]]; then
IMAGE_URL="${IMAGE_URL/:*@/@}"
fi
echo "Inspecting manifest for source image ${IMAGE_URL}"
skopeo inspect --no-tags docker://"${IMAGE_URL}" > $IMAGE_INSPECT
skopeo inspect --no-tags --raw docker://"${IMAGE_URL}" > $RAW_IMAGE_INSPECT
echo "Getting base image manifest for source image $(params.IMAGE_URL)"
echo "Getting base image manifest for source image ${IMAGE_URL}"
BASE_IMAGE_NAME="$(jq -r ".annotations.\"org.opencontainers.image.base.name\"" $RAW_IMAGE_INSPECT)"
BASE_IMAGE_DIGEST="$(jq -r ".annotations.\"org.opencontainers.image.base.digest\"" $RAW_IMAGE_INSPECT)"
if [ $BASE_IMAGE_NAME == 'null' ]; then
Expand All @@ -49,12 +56,12 @@ spec:
BASE_IMAGE_NAME="$(jq -r ".Labels.\"org.opencontainers.image.base.name\"" $IMAGE_INSPECT)"
BASE_IMAGE_DIGEST="$(jq -r ".annotations.\"org.opencontainers.image.base.digest\"" $IMAGE_INSPECT)"
if [ "$BASE_IMAGE_NAME" == 'null' ]; then
echo "Cannot get base image info from 'Labels', please check the source image $(params.IMAGE_URL)"
echo "Cannot get base image info from 'Labels', please check the source image ${IMAGE_URL}"
exit 0
fi
fi
if [ -z "$BASE_IMAGE_NAME" ]; then
echo "Source image $(params.IMAGE_URL) is built from scratch, so there is no base image"
echo "Source image ${IMAGE_URL} is built from scratch, so there is no base image"
exit 0
fi
BASE_IMAGE="${BASE_IMAGE_NAME%:*}@$BASE_IMAGE_DIGEST"
Expand Down

0 comments on commit 46e71a2

Please sign in to comment.