#!/bin/bash set -e source ./library # Entry point of the script. # If makes sure that the user supplied the right # amount of arguments (image_name and image_tag) # and then performs the main workflow: # 1. retrieve the image digest # 2. retrieve the size of layers for # that image. main() { check_args "$@" local image=$1 local tag=$2 local manifests=$(get_image_tag_layers $image $tag) formatOutput "$image" "$tag" "$manifests" totalSize "$image" "$tag" "$manifests" } # Makes sure that we provided (from the cli) # enough arguments. check_args() { if (($# != 2)); then echo "Error: Two arguments must be provided - $# provided. Usage: $0 Aborting." exit 1 fi } totalSize(){ local image=$1 local tag=$2 local manifests=$3 echo "Calculate the total size of image. IMAGE: $image TAG: $tag " >&2 for manifest in $(jq -r '.[] | @text' <<<"$manifests"); do local platform=$(jq -r '.platform | @text' <<< "$manifest") local digest=$(jq -r '.digest' <<< "$manifest") local layers=$(jq -r '.layers' <<< "$manifest") echo " Digest: $digest Platform: $platform TOTAL_SIZE: $(jq -r 'reduce (.[]|.size) as $item (0; . + $item)' <<< "$layers") " >&2 done } # Run the entry point with the CLI arguments # as a list of words as supplied. main "$@"