Skip to content

Commit

Permalink
Rewrite gsl.sh so it relies less on SharedTags
Browse files Browse the repository at this point in the history
This should make our "version" provenance metadata more correct
  • Loading branch information
tianon committed Nov 2, 2023
1 parent bd5b5e8 commit 2dada3b
Showing 1 changed file with 65 additions and 28 deletions.
93 changes: 65 additions & 28 deletions hub/gsl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ dir="$(dirname "$BASH_SOURCE")"
cd "$dir"

commit="$(git log -1 --format='format:%H' HEAD -- .)"
cat <<-EOH
Maintainers: Tianon Gravi <tianon@tianon.xyz> (@tianon)
GitRepo: https://github.com/tianon/gosu.git
GitCommit: $commit
Directory: hub
Builder: buildkit
EOH

version=
i=0; jq=; froms=()
Expand All @@ -31,24 +24,68 @@ for variant in "${preferredOrder[@]}"; do
done
arches="$(bashbrew remote arches --json "${froms[@]}" | jq -sc "{ $jq }")" # { alpine: [ "amd64", ... ], debian: [ "amd64", ... ] }

queue="$(jq <<<"$arches" -r 'to_entries | map(@sh "variant=\(.key)\narch=\(.value[])") | map(@sh) | join("\n")')"
eval "queue=( $queue )"

declare -A seenArches=()
for item in "${queue[@]}"; do
eval "$item" # variant=yyy arch=xxx
[ -n "$variant" ]
[ -n "$arch" ]
tags="$variant-$arch"
sharedTags="$variant, $version-$variant"
if [ -z "${seenArches["$arch"]:-}" ]; then
tags+=", $arch"
sharedTags+=", $version, latest"
fi
echo
echo "Tags: $tags"
[ -z "$sharedTags" ] || echo "SharedTags: $sharedTags"
echo "Architectures: $arch"
echo "File: Dockerfile.$variant"
: "${seenArches["$arch"]:=1}"
done
exec jq <<<"$arches" -r --arg commit "$commit" --arg version "$version" '
with_entries(select(length > 0))
| keys_unsorted as $variants
| (add | unique) as $arches
| . as $variantArches
| (
reduce (
to_entries[]
| {
variant: .key,
arch: .value[],
}
) as $m ({};
if has($m.arch) then . else
.[$m.arch] = $m.variant
end
)
) as $archVariants
| [
{
Maintainers: "Tianon Gravi <tianon@tianon.xyz> (@tianon)",
GitRepo: "https://github.com/tianon/gosu.git",
GitCommit: $commit,
Directory: "hub",
Builder: "buildkit",
},
reduce $arches[] as $arch (
{
Tags: [ $version, "latest" ],
Architectures: $arches,
File: "Dockerfile.\($variants[0])",
};
if has($arch + "-File") then . else
"Dockerfile.\($archVariants[$arch])" as $df
| if $df == .File then . else
.[$arch + "-File"] = $df
end
end
),
(
$variants[]
| {
Tags: [ "\($version)-\(.)", . ],
Architectures: $variantArches[.],
File: "Dockerfile.\(.)",
},
(
. as $variant
| $variantArches[.][]
| {
Tags: [ "\($variant)-\(.)", if $archVariants[.] == $variant then . else empty end ],
Architectures: .,
File: "Dockerfile.\($variant)",
}
)
),
empty
]
| map(to_entries | map(.key + ": " + ([ .value ] | flatten | join(", "))) | join("\n"))
| join("\n\n")
'

0 comments on commit 2dada3b

Please sign in to comment.