-
Notifications
You must be signed in to change notification settings - Fork 0
/
digest_to_tag.sh
executable file
·35 lines (25 loc) · 1.3 KB
/
digest_to_tag.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
export HYDRA_API="https://access.redhat.com/hydra/rest/securitydata"
export CATALOG_API="https://catalog.redhat.com/api/containers/v1/repositories/registry/registry.access.redhat.com/repository"
image_name="${1}"
# Example for mapping
#image_name="registry.redhat.io/openshift-logging/elasticsearch6-rhel8@sha256:fd46c47dca6d84f0fd403e481b28cafd614e2e9ed7c63f3965e66485bb26d20c"
if [[ "${image_name}" =~ "@" ]]; then
image_repo=$(echo "${image_name}" | awk -F\@ '{print $1}' | awk '{sub(/\//," ");$1=$1;print $2}')
image_tag=$(echo "${image_name}" | awk -F\@ '{print $NF}')
else
echo "Image does not appear to contain digest"
exit 1
fi
image=$(echo "${image_repo}" | awk -F\/ '{print $NF}')
image_metadata_file="metadata/$(echo ${image_repo} | sed 's|/|_|g')_images.json"
#echo "image: ${image}"
#echo "image_repo: ${image_repo}"
#echo "image_tag: ${image_tag}"
#echo "metadata file: ${image_metadata_file}"
# pull all past images if we don't have the file already
if [ ! -e "${image_metadata_file}" ]; then
curl -s "${CATALOG_API}/${image_repo}/images?page_size=500&page=0" > "${image_metadata_file}"
fi
jq -r -c ".data[] | select((.repositories[0].manifest_list_digest == \"${image_tag}\") and .parsed_data.architecture == \"amd64\") | .repositories[].tags[0].name" "${image_metadata_file}"
exit 0