From 97b2ff201ec59b9a037197d132c64eb937370c64 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Wed, 7 Jun 2017 15:15:03 -0700 Subject: [PATCH] Refactor multiarch support to go all the way to correct Architectures lines in "generate-stackbrew-library.sh" --- .architectures-lib | 62 +++++++++++++++++++++++++++++++++++ 1.7/Dockerfile | 6 ++-- 1.7/release-architectures | 8 +++++ 1.7/wheezy/Dockerfile | 6 ++-- 1.8/Dockerfile | 6 ++-- 1.8/release-architectures | 8 +++++ 1.8/stretch/Dockerfile | 6 ++-- generate-stackbrew-library.sh | 16 +++++++++ update.sh | 16 +++------ 9 files changed, 110 insertions(+), 24 deletions(-) create mode 100644 .architectures-lib create mode 100644 1.7/release-architectures create mode 100644 1.8/release-architectures diff --git a/.architectures-lib b/.architectures-lib new file mode 100644 index 00000000..4dce7eb4 --- /dev/null +++ b/.architectures-lib @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +_awkArch() { + local version="$1"; shift + local awkExpr="$1"; shift + awk "$@" "/^#|^\$/ { next } $awkExpr" "$version/release-architectures" +} + +dpkgArches() { + local version="$1"; shift + _awkArch "$version" '{ print $2 }' +} + +hasBashbrewArch() { + local version="$1"; shift + local bashbrewArch="$1"; shift + _awkArch "$version" 'BEGIN { exitCode = 1 } $1 == bashbrewArch { exitCode = 0 } END { exit exitCode }' -v bashbrewArch="$bashbrewArch" +} + +dpkgToGoArch() { + local version="$1"; shift + local dpkgArch="$1"; shift + _awkArch "$version" '$2 == dpkgArch { print $3; exit }' -v dpkgArch="$dpkgArch" +} + +_generateParentRepoToArches() { + local repo="$1"; shift + local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/' + + eval "declare -g -A parentRepoToArches=( $( + find -name 'Dockerfile' -exec awk ' + toupper($1) == "FROM" && $2 !~ /^('"$repo"'|scratch|microsoft\/[^:]+)(:|$)/ { + print "'"$officialImagesUrl"'" $2 + } + ' '{}' + \ + | sort -u \ + | xargs bashbrew cat --format '[{{ .RepoName }}:{{ .TagName }}]="{{ join " " .TagEntry.Architectures }}"' + ) )" +} +_generateParentRepoToArches 'golang' + +parentArches() { + local version="$1"; shift # "1.8", etc + local variant="$1"; shift # "", "stretch", etc + + local parent="$(awk 'toupper($1) == "FROM" { print $2 }' "$version/$variant/Dockerfile")" + echo "${parentRepoToArches[$parent]:-}" +} +variantArches() { + local version="$1"; shift # "1.8", etc + local variant="$1"; shift # "", "stretch", etc + + local parentArches="$(parentArches "$version" "$variant")" + + local variantArches=() + for arch in $parentArches; do + if hasBashbrewArch "$version" "$arch"; then + variantArches+=( "$arch" ) + fi + done + echo "${variantArches[*]}" +} diff --git a/1.7/Dockerfile b/1.7/Dockerfile index ce235fa8..f49fdd0b 100644 --- a/1.7/Dockerfile +++ b/1.7/Dockerfile @@ -16,11 +16,11 @@ RUN set -eux; \ # this "case" statement is generated via "update.sh" dpkgArch="$(dpkg --print-architecture)"; \ case "${dpkgArch##*-}" in \ - ppc64el) goRelArch='linux-ppc64le'; goRelSha256='8b5b602958396f165a3547a1308ab91ae3f2ad8ecb56063571a37aadc2df2332' ;; \ + amd64) goRelArch='linux-amd64'; goRelSha256='ad5808bf42b014c22dd7646458f631385003049ded0bb6af2efc7f1f79fa29ea' ;; \ + armhf) goRelArch='linux-armv6l'; goRelSha256='fc5c40fb1f76d0978504b94cd06b5ea6e0e216ba1d494060d081e022540900f8' ;; \ i386) goRelArch='linux-386'; goRelSha256='99f79d4e0f966f492794963ecbf4b08c16a9a268f2c09053a5ce10b343ee4082' ;; \ + ppc64el) goRelArch='linux-ppc64le'; goRelSha256='8b5b602958396f165a3547a1308ab91ae3f2ad8ecb56063571a37aadc2df2332' ;; \ s390x) goRelArch='linux-s390x'; goRelSha256='d692643d1ac4f4dea8fb6d949ffa750e974e63ff0ee6ca2a7c38fc7c90da8b5b' ;; \ - armhf) goRelArch='linux-armv6l'; goRelSha256='fc5c40fb1f76d0978504b94cd06b5ea6e0e216ba1d494060d081e022540900f8' ;; \ - amd64) goRelArch='linux-amd64'; goRelSha256='ad5808bf42b014c22dd7646458f631385003049ded0bb6af2efc7f1f79fa29ea' ;; \ *) goRelArch='src'; goRelSha256='1a67a4e688673fdff7ba41e73482b0e59ac5bd0f7acf703bc6d50cc775c5baba'; \ echo >&2; echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; echo >&2 ;; \ esac; \ diff --git a/1.7/release-architectures b/1.7/release-architectures new file mode 100644 index 00000000..341cb860 --- /dev/null +++ b/1.7/release-architectures @@ -0,0 +1,8 @@ +# see https://golang.org/dl/ + +# bashbrew-arch dpkg-arch golang-release-arch +amd64 amd64 amd64 +arm32v7 armhf armv6l +i386 i386 386 +ppc64le ppc64el ppc64le +s390x s390x s390x diff --git a/1.7/wheezy/Dockerfile b/1.7/wheezy/Dockerfile index 69fb33a7..77a35704 100644 --- a/1.7/wheezy/Dockerfile +++ b/1.7/wheezy/Dockerfile @@ -16,11 +16,11 @@ RUN set -eux; \ # this "case" statement is generated via "update.sh" dpkgArch="$(dpkg --print-architecture)"; \ case "${dpkgArch##*-}" in \ - ppc64el) goRelArch='linux-ppc64le'; goRelSha256='8b5b602958396f165a3547a1308ab91ae3f2ad8ecb56063571a37aadc2df2332' ;; \ + amd64) goRelArch='linux-amd64'; goRelSha256='ad5808bf42b014c22dd7646458f631385003049ded0bb6af2efc7f1f79fa29ea' ;; \ + armhf) goRelArch='linux-armv6l'; goRelSha256='fc5c40fb1f76d0978504b94cd06b5ea6e0e216ba1d494060d081e022540900f8' ;; \ i386) goRelArch='linux-386'; goRelSha256='99f79d4e0f966f492794963ecbf4b08c16a9a268f2c09053a5ce10b343ee4082' ;; \ + ppc64el) goRelArch='linux-ppc64le'; goRelSha256='8b5b602958396f165a3547a1308ab91ae3f2ad8ecb56063571a37aadc2df2332' ;; \ s390x) goRelArch='linux-s390x'; goRelSha256='d692643d1ac4f4dea8fb6d949ffa750e974e63ff0ee6ca2a7c38fc7c90da8b5b' ;; \ - armhf) goRelArch='linux-armv6l'; goRelSha256='fc5c40fb1f76d0978504b94cd06b5ea6e0e216ba1d494060d081e022540900f8' ;; \ - amd64) goRelArch='linux-amd64'; goRelSha256='ad5808bf42b014c22dd7646458f631385003049ded0bb6af2efc7f1f79fa29ea' ;; \ *) goRelArch='src'; goRelSha256='1a67a4e688673fdff7ba41e73482b0e59ac5bd0f7acf703bc6d50cc775c5baba'; \ echo >&2; echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; echo >&2 ;; \ esac; \ diff --git a/1.8/Dockerfile b/1.8/Dockerfile index fa53f951..6ec6f0ab 100644 --- a/1.8/Dockerfile +++ b/1.8/Dockerfile @@ -16,11 +16,11 @@ RUN set -eux; \ # this "case" statement is generated via "update.sh" dpkgArch="$(dpkg --print-architecture)"; \ case "${dpkgArch##*-}" in \ - ppc64el) goRelArch='linux-ppc64le'; goRelSha256='e5fb00adfc7291e657f1f3d31c09e74890b5328e6f991a3f395ca72a8c4dc0b3' ;; \ + amd64) goRelArch='linux-amd64'; goRelSha256='1862f4c3d3907e59b04a757cfda0ea7aa9ef39274af99a784f5be843c80c6772' ;; \ + armhf) goRelArch='linux-armv6l'; goRelSha256='3c30a3e24736ca776fc6314e5092fb8584bd3a4a2c2fa7307ae779ba2735e668' ;; \ i386) goRelArch='linux-386'; goRelSha256='ff4895eb68fb1daaec41c540602e8bb4c1e8bb2f0e7017367171913fc9995ed2' ;; \ + ppc64el) goRelArch='linux-ppc64le'; goRelSha256='e5fb00adfc7291e657f1f3d31c09e74890b5328e6f991a3f395ca72a8c4dc0b3' ;; \ s390x) goRelArch='linux-s390x'; goRelSha256='e2ec3e7c293701b57ca1f32b37977ac9968f57b3df034f2cc2d531e80671e6c8' ;; \ - armhf) goRelArch='linux-armv6l'; goRelSha256='3c30a3e24736ca776fc6314e5092fb8584bd3a4a2c2fa7307ae779ba2735e668' ;; \ - amd64) goRelArch='linux-amd64'; goRelSha256='1862f4c3d3907e59b04a757cfda0ea7aa9ef39274af99a784f5be843c80c6772' ;; \ *) goRelArch='src'; goRelSha256='5f5dea2447e7dcfdc50fa6b94c512e58bfba5673c039259fd843f68829d99fa6'; \ echo >&2; echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; echo >&2 ;; \ esac; \ diff --git a/1.8/release-architectures b/1.8/release-architectures new file mode 100644 index 00000000..341cb860 --- /dev/null +++ b/1.8/release-architectures @@ -0,0 +1,8 @@ +# see https://golang.org/dl/ + +# bashbrew-arch dpkg-arch golang-release-arch +amd64 amd64 amd64 +arm32v7 armhf armv6l +i386 i386 386 +ppc64le ppc64el ppc64le +s390x s390x s390x diff --git a/1.8/stretch/Dockerfile b/1.8/stretch/Dockerfile index ebe855bd..90647e9e 100644 --- a/1.8/stretch/Dockerfile +++ b/1.8/stretch/Dockerfile @@ -16,11 +16,11 @@ RUN set -eux; \ # this "case" statement is generated via "update.sh" dpkgArch="$(dpkg --print-architecture)"; \ case "${dpkgArch##*-}" in \ - ppc64el) goRelArch='linux-ppc64le'; goRelSha256='e5fb00adfc7291e657f1f3d31c09e74890b5328e6f991a3f395ca72a8c4dc0b3' ;; \ + amd64) goRelArch='linux-amd64'; goRelSha256='1862f4c3d3907e59b04a757cfda0ea7aa9ef39274af99a784f5be843c80c6772' ;; \ + armhf) goRelArch='linux-armv6l'; goRelSha256='3c30a3e24736ca776fc6314e5092fb8584bd3a4a2c2fa7307ae779ba2735e668' ;; \ i386) goRelArch='linux-386'; goRelSha256='ff4895eb68fb1daaec41c540602e8bb4c1e8bb2f0e7017367171913fc9995ed2' ;; \ + ppc64el) goRelArch='linux-ppc64le'; goRelSha256='e5fb00adfc7291e657f1f3d31c09e74890b5328e6f991a3f395ca72a8c4dc0b3' ;; \ s390x) goRelArch='linux-s390x'; goRelSha256='e2ec3e7c293701b57ca1f32b37977ac9968f57b3df034f2cc2d531e80671e6c8' ;; \ - armhf) goRelArch='linux-armv6l'; goRelSha256='3c30a3e24736ca776fc6314e5092fb8584bd3a4a2c2fa7307ae779ba2735e668' ;; \ - amd64) goRelArch='linux-amd64'; goRelSha256='1862f4c3d3907e59b04a757cfda0ea7aa9ef39274af99a784f5be843c80c6772' ;; \ *) goRelArch='src'; goRelSha256='5f5dea2447e7dcfdc50fa6b94c512e58bfba5673c039259fd843f68829d99fa6'; \ echo >&2; echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; echo >&2 ;; \ esac; \ diff --git a/generate-stackbrew-library.sh b/generate-stackbrew-library.sh index a47c1b8c..3c4c58fa 100755 --- a/generate-stackbrew-library.sh +++ b/generate-stackbrew-library.sh @@ -9,9 +9,14 @@ declare -A aliases=( self="$(basename "$BASH_SOURCE")" cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" +source '.architectures-lib' + versions=( */ ) versions=( "${versions[@]%/}" ) +# sort version numbers with highest first +IFS=$'\n'; versions=( $(echo "${versions[*]}" | sort -rV) ); unset IFS + # get the most recent commit which modified any of "$@" fileCommit() { git log -1 --format='format:%H' HEAD -- "$@" @@ -71,9 +76,12 @@ for version in "${versions[@]}"; do ${aliases[$version]:-} ) + versionArches="$(variantArches "$version" '')" + echo cat <<-EOE Tags: $(join ', ' "${versionAliases[@]}") + Architectures: $(join ', ' $versionArches) GitCommit: $commit Directory: $version EOE @@ -92,9 +100,17 @@ for version in "${versions[@]}"; do variantAliases=( "${versionAliases[@]/%/-$variant}" ) variantAliases=( "${variantAliases[@]//latest-/}" ) + case "$v" in + onbuild) variantArches="$versionArches" ;; + alpine*) variantArches="$(parentArches "$version" "$v")" ;; + windows/*) variantArches='windows-amd64' ;; + *) variantArches="$(variantArches "$version" "$v")" ;; + esac + echo cat <<-EOE Tags: $(join ', ' "${variantAliases[@]}") + Architectures: $(join ', ' $variantArches) GitCommit: $commit Directory: $dir EOE diff --git a/update.sh b/update.sh index 015d8705..cc743991 100755 --- a/update.sh +++ b/update.sh @@ -1,16 +1,6 @@ #!/bin/bash set -Eeuo pipefail -# a mapping of "dpkg --print-architecture" to Go release arch -# see https://golang.org/dl/ -declare -A dpkgArches=( - [amd64]='amd64' - [armhf]='armv6l' - [i386]='386' - [ppc64el]='ppc64le' - [s390x]='s390x' -) - defaultDebianSuite='stretch' declare -A debianSuite=( [1.8]='jessie' @@ -24,6 +14,8 @@ declare -A alpineVersion=( cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" +source '.architectures-lib' + versions=( "$@" ) if [ ${#versions[@]} -eq 0 ]; then versions=( */ ) @@ -77,8 +69,8 @@ for version in "${versions[@]}"; do linuxArchCase='dpkgArch="$(dpkg --print-architecture)"; '$'\\\n' linuxArchCase+=$'\t''case "${dpkgArch##*-}" in '$'\\\n' - for dpkgArch in "${!dpkgArches[@]}"; do - goArch="${dpkgArches[$dpkgArch]}" + for dpkgArch in $(dpkgArches "$version"); do + goArch="$(dpkgToGoArch "$version" "$dpkgArch")" sha256="$(curl -fsSL "https://storage.googleapis.com/golang/go${fullVersion}.linux-${goArch}.tar.gz.sha256")" if [ -z "$sha256" ]; then echo >&2 "warning: cannot find sha256 for $fullVersion on arch $goArch"