Update diff-image.sh

This commit is contained in:
Shiming Zhang
2021-09-17 13:52:24 +08:00
parent 3812bf3a1f
commit a3d20184c0

View File

@@ -4,11 +4,14 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
# Output more information that is out of sync
DEBUG="${DEBUG:-}"
IMAGE1="${1:-}" IMAGE1="${1:-}"
IMAGE2="${2:-}" IMAGE2="${2:-}"
# Output more information that is out of sync SKOPEO="${SKOPEO:-skopeo}"
DEBUG="${DEBUG:-}" JQ="${JQ:-jq}"
# Allow image2 to have more tags than image1 # Allow image2 to have more tags than image1
INCREMENTAL="${INCREMENTAL:-}" INCREMENTAL="${INCREMENTAL:-}"
@@ -31,6 +34,8 @@ if [[ "${DEBUG}" == "true" ]]; then
echo "DEBUG: ${DEBUG}" echo "DEBUG: ${DEBUG}"
echo "IMAGE1: ${IMAGE1}" echo "IMAGE1: ${IMAGE1}"
echo "IMAGE2: ${IMAGE2}" echo "IMAGE2: ${IMAGE2}"
echo "SKOPEO: ${SKOPEO}"
echo "JQ: ${JQ}"
echo "INCREMENTAL: ${INCREMENTAL}" echo "INCREMENTAL: ${INCREMENTAL}"
echo "QUICKLY: ${QUICKLY}" echo "QUICKLY: ${QUICKLY}"
echo "FOCUS: ${FOCUS}" echo "FOCUS: ${FOCUS}"
@@ -77,34 +82,34 @@ function check() {
function inspect() { function inspect() {
local image="${1:-}" local image="${1:-}"
local raw=$(skopeo inspect --raw --tls-verify=false "docker://${image}") local raw=$(${SKOPEO} inspect --raw --tls-verify=false "docker://${image}")
if [[ "${raw}" == "" ]]; then if [[ "${raw}" == "" ]]; then
echo "skopeo inspect --raw --tls-verify=false docker://${image}" >&2 echo "skopeo inspect --raw --tls-verify=false docker://${image}" >&2
echo "ERROR: Failed to inspect ${image}" >&2 echo "ERROR: Failed to inspect ${image}" >&2
return 1 return 1
fi fi
local schemaVersion=$(echo "${raw}" | jq -r '.schemaVersion') local schemaVersion=$(echo "${raw}" | ${JQ} -r '.schemaVersion')
case "${schemaVersion}" in case "${schemaVersion}" in
1) 1)
echo "${raw}" | jq -r '.fsLayers[].blobSum' echo "${raw}" | ${JQ} -r '.fsLayers[].blobSum'
;; ;;
2) 2)
local mediaType=$(echo "${raw}" | jq -r '.mediaType // "" ') local mediaType=$(echo "${raw}" | ${JQ} -r '.mediaType // "" ')
if [[ "${mediaType}" == "" ]]; then if [[ "${mediaType}" == "" ]]; then
if [[ "$(echo "${raw}" | jq -r '.layers | length')" -gt 0 ]]; then if [[ "$(echo "${raw}" | ${JQ} -r '.layers | length')" -gt 0 ]]; then
mediaType="layers" mediaType="layers"
elif [[ "$(echo "${raw}" | jq -r '.manifests | length')" -gt 0 ]]; then elif [[ "$(echo "${raw}" | ${JQ} -r '.manifests | length')" -gt 0 ]]; then
mediaType="manifests" mediaType="manifests"
fi fi
fi fi
case "${mediaType}" in case "${mediaType}" in
"layers" | "application/vnd.docker.distribution.manifest.v2+json") "layers" | "application/vnd.docker.distribution.manifest.v2+json")
echo "${raw}" | jq -r '.layers[].digest' echo "${raw}" | ${JQ} -r '.layers[].digest'
;; ;;
"manifests" | "application/vnd.docker.distribution.manifest.list.v2+json") "manifests" | "application/vnd.docker.distribution.manifest.list.v2+json")
echo "${raw}" | jq -j '.manifests[] | .platform.architecture , " " , .platform.os , " " , .digest , "\n"' | sort echo "${raw}" | ${JQ} -j '.manifests[] | .platform.architecture , " " , .platform.os , " " , .digest , "\n"' | sort
;; ;;
*) *)
echo "skopeo inspect --raw --tls-verify=false docker://${image}" >&2 echo "skopeo inspect --raw --tls-verify=false docker://${image}" >&2
@@ -129,7 +134,7 @@ function inspect() {
function list-tags() { function list-tags() {
local image="${1:-}" local image="${1:-}"
local raw="$(skopeo list-tags --tls-verify=false "docker://${image}" | jq -r '.Tags[]' | sort)" local raw="$(${SKOPEO} list-tags --tls-verify=false "docker://${image}" | ${JQ} -r '.Tags[]' | sort)"
if [[ "${FOCUS}" != "" ]]; then if [[ "${FOCUS}" != "" ]]; then
raw="$(echo "${raw}" | grep -E "${FOCUS}" || :)" raw="$(echo "${raw}" | grep -E "${FOCUS}" || :)"