Skip to content

Commit fe76aaa

Browse files
committed
Add "VSize" to "Supported tags and respective Dockerfile links"
1 parent fbddfc0 commit fe76aaa

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

generate-dockerfile-links-partial.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
set -e
33

4+
thisDir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
5+
46
repo="$1"
57
if [ -z "$repo" ]; then
68
echo >&2 "usage: $0 repo"
@@ -14,6 +16,7 @@ unset IFS
1416

1517
repoDirs=()
1618
declare -A repoDirTags=()
19+
declare -A repoDirFirstTag=()
1720

1821
for line in "${lines[@]}"; do
1922
tag="$(echo "$line" | awk -F ': +' '{ print $1 }')"
@@ -24,6 +27,9 @@ for line in "${lines[@]}"; do
2427
repoDirTags["$repoDir"]+=', '
2528
fi
2629
repoDirTags["$repoDir"]+='`'"$tag"'`'
30+
if [ -z "${repoDirFirstTag[$repoDir]}" ]; then
31+
repoDirFirstTag["$repoDir"]="$tag"
32+
fi
2733
done
2834

2935
for repoDir in "${repoDirs[@]}"; do
@@ -51,7 +57,7 @@ for repoDir in "${repoDirs[@]}"; do
5157

5258
url="https://$gitUrl/blob/$commit/${dir}Dockerfile"
5359

54-
echo '- ['"${repoDirTags["$repoDir"]}"' (*'"${dir}Dockerfile"'*)]('"$url"')'
60+
echo '- ['"${repoDirTags["$repoDir"]}"' (*'"${dir}Dockerfile"'*)]('"$url"') [VSize: '"$("$thisDir/get-image-data.sh" vsize "$repo" "${repoDirFirstTag["$repoDir"]}")"']'
5561
done
5662

5763
echo

get-image-data.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
set -e
3+
4+
usage() {
5+
echo "usage: $0 [options] data image [tag]"
6+
echo " ie: $0 vsize scratch"
7+
echo " $0 id debian latest"
8+
echo " $0 -v vsize golang cross"
9+
}
10+
11+
opts="$(getopt -o 'h?v' --long 'help,verbose' -- "$@" || { usage >&2 && false; })"
12+
eval set -- "$opts"
13+
14+
verbose=
15+
while true; do
16+
flag="$1"
17+
shift
18+
case "$flag" in
19+
--help|-h|'-?')
20+
usage
21+
exit 0
22+
;;
23+
--verbose|-v) verbose=1 ;;
24+
--)
25+
break
26+
;;
27+
*)
28+
{
29+
echo "error: unknown flag: $flag"
30+
usage
31+
} >&2
32+
exit 1
33+
;;
34+
esac
35+
done
36+
37+
data="$1"
38+
image="$2"
39+
tag="${3:-latest}"
40+
41+
if [ -z "$data" -o -z "$image" -o -z "$tag" ]; then
42+
usage >&2
43+
exit 1
44+
fi
45+
46+
token="$(curl -sSL -o /dev/null -D- -H 'X-Docker-Token: true' "https://index.docker.io/v1/repositories/$image/images" | awk -F ':[[:space:]]*|\r' '$1 == "X-Docker-Token" { print $2 }')"
47+
48+
imageId="$(curl -sSL -H "Authorization: Token $token" "https://registry-1.docker.io/v1/repositories/$image/tags/$tag")"
49+
imageId="${imageId%\"}"
50+
imageId="${imageId#\"}"
51+
52+
case "$data" in
53+
id)
54+
echo "$imageId"
55+
;;
56+
vsize)
57+
ancestry=( $(curl -sSL -H "Authorization: Token $token" "https://registry-1.docker.io/v1/images/$imageId/ancestry" | sed -r 's/^\["|"\]//g; s/",[[:space:]]*"/ /g') )
58+
59+
humanSizeUnits=( B KB MB GB TB )
60+
[ "$verbose" ] && humanSizeScale=3 || humanSizeScale=1
61+
human_size() {
62+
bytes="$1"
63+
unit=0
64+
unitBytes="$1"
65+
while unitBytes="$(echo "scale=0; $bytes / (1000 ^ $unit)" | bc -l)" && [ "$unitBytes" -gt 1000 ]; do
66+
if [ ! "${humanSizeUnits[$(( unit + 1 ))]}" ]; then
67+
break
68+
fi
69+
unit="$(( unit + 1 ))"
70+
done
71+
echo "$(echo "scale=$humanSizeScale; $bytes / (1000 ^ $unit)" | bc -l) ${humanSizeUnits[$unit]}"
72+
}
73+
74+
total=0
75+
for ancestor in "${ancestry[@]}"; do
76+
size="$(curl -sSL -H "Authorization: Token $token" "https://registry-1.docker.io/v1/images/$ancestor/json" | awk -F '"Size":[[:space:]]*' '{ sub(/(,|}).*/, "", $2); if ($2 == "") { print 0 } else { print $2 } }')"
77+
total="$(echo "$total + $size" | bc)"
78+
if [ "$verbose" ]; then
79+
echo "${ancestor:0:12}: $(human_size $size)"
80+
fi
81+
done
82+
if [ "$verbose" ]; then
83+
echo -n 'total: '
84+
fi
85+
echo "$(human_size $total)"
86+
;;
87+
*)
88+
echo >&2 "unknown data type requested: $data"
89+
exit 1
90+
;;
91+
esac

0 commit comments

Comments
 (0)