Skip to content

Commit 8620ae0

Browse files
committed
Fix Architectures calculation to take *all* FROM values into account
1 parent 201b7c0 commit 8620ae0

File tree

1 file changed

+46
-13
lines changed

1 file changed

+46
-13
lines changed

generate-stackbrew-library.sh

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#!/bin/bash
2-
set -eu
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
33

44
declare -A aliases=(
55
[8.9]='8'
@@ -47,19 +47,38 @@ dirCommit() {
4747
)
4848
}
4949

50+
gawkParents='
51+
{ cmd = toupper($1) }
52+
cmd == "FROM" {
53+
print $2
54+
next
55+
}
56+
cmd == "COPY" {
57+
for (i = 2; i < NF; i++) {
58+
if ($i ~ /^--from=/) {
59+
gsub(/^--from=/, "", $i)
60+
print $i
61+
next
62+
}
63+
}
64+
}
65+
'
66+
5067
getArches() {
5168
local repo="$1"; shift
52-
local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/'
5369

54-
eval "declare -g -A parentRepoToArches=( $(
55-
find -name 'Dockerfile' -exec awk '
56-
toupper($1) == "FROM" && $2 !~ /^('"$repo"'|scratch|.*\/.*)(:|$)/ {
57-
print "'"$officialImagesUrl"'" $2
58-
}
59-
' '{}' + \
70+
local parentRepoToArchesStr
71+
parentRepoToArchesStr="$(
72+
find -name 'Dockerfile' -exec gawk "$gawkParents" '{}' + \
6073
| sort -u \
61-
| xargs bashbrew cat --format '[{{ .RepoName }}:{{ .TagName }}]="{{ join " " .TagEntry.Architectures }}"'
62-
) )"
74+
| gawk -v officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/' '
75+
$1 !~ /^('"$repo"'|scratch|.*\/.*)(:|$)/ {
76+
printf "%s%s\n", officialImagesUrl, $1
77+
}
78+
' \
79+
| xargs -r bashbrew cat --format '["{{ .RepoName }}:{{ .TagName }}"]="{{ join " " .TagEntry.Architectures }}"'
80+
)"
81+
eval "declare -g -A parentRepoToArches=( $parentRepoToArchesStr )"
6382
}
6483
getArches 'drupal'
6584

@@ -108,8 +127,22 @@ for version in "${versions[@]}"; do
108127
esac
109128
variantAliases=( "${variantAliases[@]//latest-/}" )
110129

111-
variantParent="$(awk 'toupper($1) == "FROM" { print $2 }' "$version/$variant/Dockerfile")"
112-
variantArches="${parentRepoToArches[$variantParent]}"
130+
variantParents="$(gawk "$gawkParents" "$version/$variant/Dockerfile")"
131+
variantArches=
132+
for variantParent in $variantParents; do
133+
parentArches="${parentRepoToArches[$variantParent]:-}"
134+
if [ -z "$parentArches" ]; then
135+
continue
136+
elif [ -z "$variantArches" ]; then
137+
variantArches="$parentArches"
138+
else
139+
variantArches="$(
140+
comm -12 \
141+
<(xargs -n1 <<<"$variantArches" | sort -u) \
142+
<(xargs -n1 <<<"$parentArches" | sort -u)
143+
)"
144+
fi
145+
done
113146

114147
if [[ "$variant" = apache-* ]]; then
115148
variantAliases+=( "${versionAliases[@]}" )

0 commit comments

Comments
 (0)