|
| 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 | +} |
0 commit comments