Skip to content

Commit a70ae48

Browse files
authored
Merge pull request #163 from infosiftr/multiarch-arches
Refactor multiarch support to go all the way to correct Architectures lines in "generate-stackbrew-library.sh"
2 parents 108d578 + 97b2ff2 commit a70ae48

9 files changed

+110
-24
lines changed

.architectures-lib

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
3+
_awkArch() {
4+
local version="$1"; shift
5+
local awkExpr="$1"; shift
6+
awk "$@" "/^#|^\$/ { next } $awkExpr" "$version/release-architectures"
7+
}
8+
9+
dpkgArches() {
10+
local version="$1"; shift
11+
_awkArch "$version" '{ print $2 }'
12+
}
13+
14+
hasBashbrewArch() {
15+
local version="$1"; shift
16+
local bashbrewArch="$1"; shift
17+
_awkArch "$version" 'BEGIN { exitCode = 1 } $1 == bashbrewArch { exitCode = 0 } END { exit exitCode }' -v bashbrewArch="$bashbrewArch"
18+
}
19+
20+
dpkgToGoArch() {
21+
local version="$1"; shift
22+
local dpkgArch="$1"; shift
23+
_awkArch "$version" '$2 == dpkgArch { print $3; exit }' -v dpkgArch="$dpkgArch"
24+
}
25+
26+
_generateParentRepoToArches() {
27+
local repo="$1"; shift
28+
local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/'
29+
30+
eval "declare -g -A parentRepoToArches=( $(
31+
find -name 'Dockerfile' -exec awk '
32+
toupper($1) == "FROM" && $2 !~ /^('"$repo"'|scratch|microsoft\/[^:]+)(:|$)/ {
33+
print "'"$officialImagesUrl"'" $2
34+
}
35+
' '{}' + \
36+
| sort -u \
37+
| xargs bashbrew cat --format '[{{ .RepoName }}:{{ .TagName }}]="{{ join " " .TagEntry.Architectures }}"'
38+
) )"
39+
}
40+
_generateParentRepoToArches 'golang'
41+
42+
parentArches() {
43+
local version="$1"; shift # "1.8", etc
44+
local variant="$1"; shift # "", "stretch", etc
45+
46+
local parent="$(awk 'toupper($1) == "FROM" { print $2 }' "$version/$variant/Dockerfile")"
47+
echo "${parentRepoToArches[$parent]:-}"
48+
}
49+
variantArches() {
50+
local version="$1"; shift # "1.8", etc
51+
local variant="$1"; shift # "", "stretch", etc
52+
53+
local parentArches="$(parentArches "$version" "$variant")"
54+
55+
local variantArches=()
56+
for arch in $parentArches; do
57+
if hasBashbrewArch "$version" "$arch"; then
58+
variantArches+=( "$arch" )
59+
fi
60+
done
61+
echo "${variantArches[*]}"
62+
}

1.7/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ RUN set -eux; \
1616
# this "case" statement is generated via "update.sh"
1717
dpkgArch="$(dpkg --print-architecture)"; \
1818
case "${dpkgArch##*-}" in \
19-
ppc64el) goRelArch='linux-ppc64le'; goRelSha256='8b5b602958396f165a3547a1308ab91ae3f2ad8ecb56063571a37aadc2df2332' ;; \
19+
amd64) goRelArch='linux-amd64'; goRelSha256='ad5808bf42b014c22dd7646458f631385003049ded0bb6af2efc7f1f79fa29ea' ;; \
20+
armhf) goRelArch='linux-armv6l'; goRelSha256='fc5c40fb1f76d0978504b94cd06b5ea6e0e216ba1d494060d081e022540900f8' ;; \
2021
i386) goRelArch='linux-386'; goRelSha256='99f79d4e0f966f492794963ecbf4b08c16a9a268f2c09053a5ce10b343ee4082' ;; \
22+
ppc64el) goRelArch='linux-ppc64le'; goRelSha256='8b5b602958396f165a3547a1308ab91ae3f2ad8ecb56063571a37aadc2df2332' ;; \
2123
s390x) goRelArch='linux-s390x'; goRelSha256='d692643d1ac4f4dea8fb6d949ffa750e974e63ff0ee6ca2a7c38fc7c90da8b5b' ;; \
22-
armhf) goRelArch='linux-armv6l'; goRelSha256='fc5c40fb1f76d0978504b94cd06b5ea6e0e216ba1d494060d081e022540900f8' ;; \
23-
amd64) goRelArch='linux-amd64'; goRelSha256='ad5808bf42b014c22dd7646458f631385003049ded0bb6af2efc7f1f79fa29ea' ;; \
2424
*) goRelArch='src'; goRelSha256='1a67a4e688673fdff7ba41e73482b0e59ac5bd0f7acf703bc6d50cc775c5baba'; \
2525
echo >&2; echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; echo >&2 ;; \
2626
esac; \

1.7/release-architectures

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# see https://golang.org/dl/
2+
3+
# bashbrew-arch dpkg-arch golang-release-arch
4+
amd64 amd64 amd64
5+
arm32v7 armhf armv6l
6+
i386 i386 386
7+
ppc64le ppc64el ppc64le
8+
s390x s390x s390x

1.7/wheezy/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ RUN set -eux; \
1616
# this "case" statement is generated via "update.sh"
1717
dpkgArch="$(dpkg --print-architecture)"; \
1818
case "${dpkgArch##*-}" in \
19-
ppc64el) goRelArch='linux-ppc64le'; goRelSha256='8b5b602958396f165a3547a1308ab91ae3f2ad8ecb56063571a37aadc2df2332' ;; \
19+
amd64) goRelArch='linux-amd64'; goRelSha256='ad5808bf42b014c22dd7646458f631385003049ded0bb6af2efc7f1f79fa29ea' ;; \
20+
armhf) goRelArch='linux-armv6l'; goRelSha256='fc5c40fb1f76d0978504b94cd06b5ea6e0e216ba1d494060d081e022540900f8' ;; \
2021
i386) goRelArch='linux-386'; goRelSha256='99f79d4e0f966f492794963ecbf4b08c16a9a268f2c09053a5ce10b343ee4082' ;; \
22+
ppc64el) goRelArch='linux-ppc64le'; goRelSha256='8b5b602958396f165a3547a1308ab91ae3f2ad8ecb56063571a37aadc2df2332' ;; \
2123
s390x) goRelArch='linux-s390x'; goRelSha256='d692643d1ac4f4dea8fb6d949ffa750e974e63ff0ee6ca2a7c38fc7c90da8b5b' ;; \
22-
armhf) goRelArch='linux-armv6l'; goRelSha256='fc5c40fb1f76d0978504b94cd06b5ea6e0e216ba1d494060d081e022540900f8' ;; \
23-
amd64) goRelArch='linux-amd64'; goRelSha256='ad5808bf42b014c22dd7646458f631385003049ded0bb6af2efc7f1f79fa29ea' ;; \
2424
*) goRelArch='src'; goRelSha256='1a67a4e688673fdff7ba41e73482b0e59ac5bd0f7acf703bc6d50cc775c5baba'; \
2525
echo >&2; echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; echo >&2 ;; \
2626
esac; \

1.8/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ RUN set -eux; \
1616
# this "case" statement is generated via "update.sh"
1717
dpkgArch="$(dpkg --print-architecture)"; \
1818
case "${dpkgArch##*-}" in \
19-
ppc64el) goRelArch='linux-ppc64le'; goRelSha256='e5fb00adfc7291e657f1f3d31c09e74890b5328e6f991a3f395ca72a8c4dc0b3' ;; \
19+
amd64) goRelArch='linux-amd64'; goRelSha256='1862f4c3d3907e59b04a757cfda0ea7aa9ef39274af99a784f5be843c80c6772' ;; \
20+
armhf) goRelArch='linux-armv6l'; goRelSha256='3c30a3e24736ca776fc6314e5092fb8584bd3a4a2c2fa7307ae779ba2735e668' ;; \
2021
i386) goRelArch='linux-386'; goRelSha256='ff4895eb68fb1daaec41c540602e8bb4c1e8bb2f0e7017367171913fc9995ed2' ;; \
22+
ppc64el) goRelArch='linux-ppc64le'; goRelSha256='e5fb00adfc7291e657f1f3d31c09e74890b5328e6f991a3f395ca72a8c4dc0b3' ;; \
2123
s390x) goRelArch='linux-s390x'; goRelSha256='e2ec3e7c293701b57ca1f32b37977ac9968f57b3df034f2cc2d531e80671e6c8' ;; \
22-
armhf) goRelArch='linux-armv6l'; goRelSha256='3c30a3e24736ca776fc6314e5092fb8584bd3a4a2c2fa7307ae779ba2735e668' ;; \
23-
amd64) goRelArch='linux-amd64'; goRelSha256='1862f4c3d3907e59b04a757cfda0ea7aa9ef39274af99a784f5be843c80c6772' ;; \
2424
*) goRelArch='src'; goRelSha256='5f5dea2447e7dcfdc50fa6b94c512e58bfba5673c039259fd843f68829d99fa6'; \
2525
echo >&2; echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; echo >&2 ;; \
2626
esac; \

1.8/release-architectures

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# see https://golang.org/dl/
2+
3+
# bashbrew-arch dpkg-arch golang-release-arch
4+
amd64 amd64 amd64
5+
arm32v7 armhf armv6l
6+
i386 i386 386
7+
ppc64le ppc64el ppc64le
8+
s390x s390x s390x

1.8/stretch/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ RUN set -eux; \
1616
# this "case" statement is generated via "update.sh"
1717
dpkgArch="$(dpkg --print-architecture)"; \
1818
case "${dpkgArch##*-}" in \
19-
ppc64el) goRelArch='linux-ppc64le'; goRelSha256='e5fb00adfc7291e657f1f3d31c09e74890b5328e6f991a3f395ca72a8c4dc0b3' ;; \
19+
amd64) goRelArch='linux-amd64'; goRelSha256='1862f4c3d3907e59b04a757cfda0ea7aa9ef39274af99a784f5be843c80c6772' ;; \
20+
armhf) goRelArch='linux-armv6l'; goRelSha256='3c30a3e24736ca776fc6314e5092fb8584bd3a4a2c2fa7307ae779ba2735e668' ;; \
2021
i386) goRelArch='linux-386'; goRelSha256='ff4895eb68fb1daaec41c540602e8bb4c1e8bb2f0e7017367171913fc9995ed2' ;; \
22+
ppc64el) goRelArch='linux-ppc64le'; goRelSha256='e5fb00adfc7291e657f1f3d31c09e74890b5328e6f991a3f395ca72a8c4dc0b3' ;; \
2123
s390x) goRelArch='linux-s390x'; goRelSha256='e2ec3e7c293701b57ca1f32b37977ac9968f57b3df034f2cc2d531e80671e6c8' ;; \
22-
armhf) goRelArch='linux-armv6l'; goRelSha256='3c30a3e24736ca776fc6314e5092fb8584bd3a4a2c2fa7307ae779ba2735e668' ;; \
23-
amd64) goRelArch='linux-amd64'; goRelSha256='1862f4c3d3907e59b04a757cfda0ea7aa9ef39274af99a784f5be843c80c6772' ;; \
2424
*) goRelArch='src'; goRelSha256='5f5dea2447e7dcfdc50fa6b94c512e58bfba5673c039259fd843f68829d99fa6'; \
2525
echo >&2; echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; echo >&2 ;; \
2626
esac; \

generate-stackbrew-library.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ declare -A aliases=(
99
self="$(basename "$BASH_SOURCE")"
1010
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
1111

12+
source '.architectures-lib'
13+
1214
versions=( */ )
1315
versions=( "${versions[@]%/}" )
1416

17+
# sort version numbers with highest first
18+
IFS=$'\n'; versions=( $(echo "${versions[*]}" | sort -rV) ); unset IFS
19+
1520
# get the most recent commit which modified any of "$@"
1621
fileCommit() {
1722
git log -1 --format='format:%H' HEAD -- "$@"
@@ -71,9 +76,12 @@ for version in "${versions[@]}"; do
7176
${aliases[$version]:-}
7277
)
7378

79+
versionArches="$(variantArches "$version" '')"
80+
7481
echo
7582
cat <<-EOE
7683
Tags: $(join ', ' "${versionAliases[@]}")
84+
Architectures: $(join ', ' $versionArches)
7785
GitCommit: $commit
7886
Directory: $version
7987
EOE
@@ -92,9 +100,17 @@ for version in "${versions[@]}"; do
92100
variantAliases=( "${versionAliases[@]/%/-$variant}" )
93101
variantAliases=( "${variantAliases[@]//latest-/}" )
94102

103+
case "$v" in
104+
onbuild) variantArches="$versionArches" ;;
105+
alpine*) variantArches="$(parentArches "$version" "$v")" ;;
106+
windows/*) variantArches='windows-amd64' ;;
107+
*) variantArches="$(variantArches "$version" "$v")" ;;
108+
esac
109+
95110
echo
96111
cat <<-EOE
97112
Tags: $(join ', ' "${variantAliases[@]}")
113+
Architectures: $(join ', ' $variantArches)
98114
GitCommit: $commit
99115
Directory: $dir
100116
EOE

update.sh

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
#!/bin/bash
22
set -Eeuo pipefail
33

4-
# a mapping of "dpkg --print-architecture" to Go release arch
5-
# see https://golang.org/dl/
6-
declare -A dpkgArches=(
7-
[amd64]='amd64'
8-
[armhf]='armv6l'
9-
[i386]='386'
10-
[ppc64el]='ppc64le'
11-
[s390x]='s390x'
12-
)
13-
144
defaultDebianSuite='stretch'
155
declare -A debianSuite=(
166
[1.8]='jessie'
@@ -24,6 +14,8 @@ declare -A alpineVersion=(
2414

2515
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
2616

17+
source '.architectures-lib'
18+
2719
versions=( "$@" )
2820
if [ ${#versions[@]} -eq 0 ]; then
2921
versions=( */ )
@@ -77,8 +69,8 @@ for version in "${versions[@]}"; do
7769

7870
linuxArchCase='dpkgArch="$(dpkg --print-architecture)"; '$'\\\n'
7971
linuxArchCase+=$'\t''case "${dpkgArch##*-}" in '$'\\\n'
80-
for dpkgArch in "${!dpkgArches[@]}"; do
81-
goArch="${dpkgArches[$dpkgArch]}"
72+
for dpkgArch in $(dpkgArches "$version"); do
73+
goArch="$(dpkgToGoArch "$version" "$dpkgArch")"
8274
sha256="$(curl -fsSL "https://storage.googleapis.com/golang/go${fullVersion}.linux-${goArch}.tar.gz.sha256")"
8375
if [ -z "$sha256" ]; then
8476
echo >&2 "warning: cannot find sha256 for $fullVersion on arch $goArch"

0 commit comments

Comments
 (0)