forked from docker-library/official-images
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request docker-library#16042 from infosiftr/naughty-shared…
…tags Add new `naughty-sharedtags.sh` script to detect incorrect `SharedTags` combinations
- Loading branch information
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuo pipefail | ||
|
||
if [ "$#" -eq 0 ]; then | ||
set -- '--all' | ||
fi | ||
|
||
bashbrew cat --format ' | ||
{{- range $e := .Entries -}} | ||
{{- range $t := .SharedTags -}} | ||
{{- "{" -}} | ||
"sharedTag": {{ join ":" $.RepoName $t | json }}, | ||
"tag": {{ join ":" $.RepoName ($e.Tags | first) | json }}, | ||
"arches": {{ $e.Architectures | json }} | ||
{{- "}\n" -}} | ||
{{- end -}} | ||
{{- end -}} | ||
' "$@" | jq -rn ' | ||
# collect map of "shared tag -> all architectures" (combining shared tags back together, respecting/keeping duplicates, since that is what this is testing for) | ||
reduce inputs as $in ({}; .[$in.sharedTag] |= (. // {} | .arches += $in.arches | .tags += [$in.tag])) | ||
# convert that into a map of "shared tags -> same architecture list" (just to shrink the problem set and make it easier to look at/think about) | ||
| reduce to_entries[] as $in ([]; | ||
(path(first(.[] | select(.value.arches == $in.value.arches))) // [length]) as $i | ||
| .[$i[0]] |= ( | ||
.key |= if . then "\(.), \($in.key)" else $in.key end | ||
| .value //= $in.value | ||
) | ||
) | ||
| map( | ||
# filter down to just entries with duplicates (ignoring Windows duplicates, since duplicating them is the primary use case of SharedTags in the first place) | ||
.value.arches |= ( | ||
# TODO we *should* try to further verify that there is only one copy of each underlying Windows version here (not 2x "ltsc2022" for example), but that is a much more difficult query to automate | ||
. - ["windows-amd64"] | ||
# trim the list down to just the duplicates (so the error is more obvious) | ||
| group_by(.) | ||
| map(select(length > 1)) | ||
| flatten | ||
) | ||
| select(.value.arches | length > 0) | ||
| " - \(.key): (duplicate architectures in SharedTags; \(.value.tags | join(", ")))\([ "", .value.arches[] ] | join("\n - "))" | ||
) | ||
| join("\n\n") | ||
' |