Skip to content

Commit 05a4747

Browse files
committed
Update "naughty-from.sh" to support multi-stage (and to have a better message for fully-unsupported FROMs)
1 parent fcd58b5 commit 05a4747

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

naughty-from.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ _arches() {
5353
_froms() {
5454
bashbrew cat --format '
5555
{{- range .TagEntries -}}
56-
{{- $.DockerFrom . -}}
56+
{{- $meta := ($.DockerfileMetadata .) -}}
57+
{{- $meta.Froms | join "\n" -}}
5758
{{- "\n" -}}
5859
{{- end -}}
5960
' "$@" | sort -u
@@ -63,10 +64,14 @@ declare -A naughtyFromsArches=(
6364
#[img:tag=from:tag]='arch arch ...'
6465
)
6566
naughtyFroms=()
67+
declare -A allNaughty=(
68+
#[img:tag]=1
69+
)
6670

6771
tags="$(bashbrew list --uniq "$@" | sort -u)"
6872
for img in $tags; do
6973
arches="$(_arches "$img")"
74+
hasNice= # do we have _any_ arches that aren't naughty? (so we can make the message better if not)
7075
for BASHBREW_ARCH in $arches; do
7176
export BASHBREW_ARCH
7277

@@ -97,15 +102,25 @@ for img in $tags; do
97102
naughtyFromsArches["$img=$from"]+=', '
98103
fi
99104
naughtyFromsArches["$img=$from"]+="$BASHBREW_ARCH"
105+
else
106+
hasNice=1
100107
fi
101108
done
102109
done
110+
111+
if [ -z "$hasNice" ]; then
112+
allNaughty["$img"]=1
113+
fi
103114
done
104115

105116
for naughtyFrom in "${naughtyFroms[@]:-}"; do
106117
[ -n "$naughtyFrom" ] || continue # https://mywiki.wooledge.org/BashFAQ/112#BashFAQ.2F112.line-8 (empty array + "set -u" + bash 4.3 == sad day)
107118
img="${naughtyFrom%%=*}"
108119
from="${naughtyFrom#$img=}"
109-
arches="${naughtyFromsArches[$naughtyFrom]}"
110-
echo " - $img (FROM $from) [$arches]"
120+
if [ -n "${allNaughty["$img"]:-}" ]; then
121+
echo " - $img (FROM $from) -- completely unsupported base!"
122+
else
123+
arches="${naughtyFromsArches[$naughtyFrom]}"
124+
echo " - $img (FROM $from) [$arches]"
125+
fi
111126
done

0 commit comments

Comments
 (0)