-
Notifications
You must be signed in to change notification settings - Fork 345
/
scan-local.sh
executable file
·60 lines (50 loc) · 1.75 KB
/
scan-local.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
set -e
trap 'echo >&2 Ctrl+C captured, exiting; exit 1' SIGINT
image="$1"; shift
docker build --pull -t repo-info:local-apk -q -f Dockerfile.local-apk . > /dev/null
docker build --pull -t repo-info:local-dpkg -q -f Dockerfile.local-dpkg . > /dev/null
docker build --pull -t repo-info:local-rpm -q -f Dockerfile.local-rpm . > /dev/null
name="repo-info-local-$$-$RANDOM"
trap "docker rm -vf '$name-data' > /dev/null || :" EXIT
docker create \
--name "$name-data" \
-v /etc \
-v /lib/apk \
-v /usr/lib/rpm \
-v /usr/share/apk \
-v /usr/share/doc \
-v /var/lib \
"$image" \
bogus > /dev/null
echo '# `'"$image"'`'
size="$(
docker inspect -f '{{ .VirtualSize }}' "$image" | awk '{
oneKb = 1000;
oneMb = 1000 * oneKb;
oneGb = 1000 * oneMb;
if ($1 >= oneGb) {
printf "~ %.2f Gb", $1 / oneGb
} else if ($1 >= oneMb) {
printf "~ %.2f Mb", $1 / oneMb
} else if ($1 >= oneKb) {
printf "~ %.2f Kb", $1 / oneKb
} else {
printf "%d bytes", $1
}
}'
)"
docker inspect -f '
## Docker Metadata
- Image ID: `{{ .Id }}`
- Created: `{{ .Created }}`
- Virtual Size: '"$size"'
(total size of all layers on-disk)
- Arch: `{{ .Os }}`/`{{ .Architecture }}`
{{ if .Config.Entrypoint }}- Entrypoint: `{{ json .Config.Entrypoint }}`
{{ end }}{{ if .Config.Cmd }}- Command: `{{ json .Config.Cmd }}`
{{ end }}- Environment:{{ range .Config.Env }}{{ "\n" }} - `{{ . }}`{{ end }}{{ if .Config.Labels }}
- Labels:{{ range $k, $v := .Config.Labels }}{{ "\n" }} - `{{ $k }}={{ $v }}`{{ end }}{{ end }}' "$image"
docker run --rm --volumes-from "$name-data" -v /etc/ssl repo-info:local-apk || :
docker run --rm --volumes-from "$name-data" -v /etc/ssl repo-info:local-dpkg || :
docker run --rm --volumes-from "$name-data" -v /etc/ssl repo-info:local-rpm || :