|
| 1 | +#!/opt/homebrew/bin/bash |
| 2 | + |
| 3 | +## You need to perform the following steps before executing this script: |
| 4 | +## 1. Install a newer version of bash: `brew install bash`. |
| 5 | +## 2. Install additional packages: `brew install coreutils gawk`. |
| 6 | +## 3. Ensure that you have `bashbrew` built and in your PATH. |
| 7 | + |
| 8 | +set -Eeuo pipefail |
| 9 | + |
| 10 | +declare -A aliases=( |
| 11 | + [7.2]='7 latest' |
| 12 | + [6.2]='6' |
| 13 | +) |
| 14 | + |
| 15 | +self="$(basename "$0")" |
| 16 | +cd "$(dirname "$(greadlink -f "$0")")" |
| 17 | + |
| 18 | +if [ "$#" -eq 0 ]; then |
| 19 | + versions="$(jq -r 'keys | map(@sh) | join(" ")' versions.json)" |
| 20 | + eval "set -- $versions" |
| 21 | +fi |
| 22 | + |
| 23 | +# sort version numbers with highest first |
| 24 | +IFS=$'\n'; set -- $(sort -rV <<<"$*"); unset IFS |
| 25 | + |
| 26 | +# get the most recent commit which modified any of "$@" |
| 27 | +fileCommit() { |
| 28 | + git log -1 --format='format:%H' HEAD -- "$@" |
| 29 | +} |
| 30 | + |
| 31 | +# get the most recent commit which modified "$1/Dockerfile" or any file COPY'd from "$1/Dockerfile" |
| 32 | +dirCommit() { |
| 33 | + local dir="$1"; shift |
| 34 | + ( |
| 35 | + cd "$dir" |
| 36 | + fileCommit \ |
| 37 | + Dockerfile \ |
| 38 | + $(git show HEAD:./Dockerfile | gawk ' |
| 39 | + toupper($1) == "COPY" { |
| 40 | + for (i = 2; i < NF; i++) { |
| 41 | + print $i |
| 42 | + } |
| 43 | + } |
| 44 | + ') |
| 45 | + ) |
| 46 | +} |
| 47 | + |
| 48 | +getArches() { |
| 49 | + local repo="$1"; shift |
| 50 | + local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/' |
| 51 | + |
| 52 | + eval "declare -g -A parentRepoToArches=( $( |
| 53 | + find . -name 'Dockerfile' -exec gawk ' |
| 54 | + toupper($1) == "FROM" && $2 !~ /^('"$repo"'|scratch|.*\/.*)(:|$)/ { |
| 55 | + print "'"$officialImagesUrl"'" $2 |
| 56 | + } |
| 57 | + ' '{}' + \ |
| 58 | + | sort -u \ |
| 59 | + | xargs bashbrew cat --format '[{{ .RepoName }}:{{ .TagName }}]="{{ join " " .TagEntry.Architectures }}"' |
| 60 | + ) )" |
| 61 | +} |
| 62 | +getArches 'redis' |
| 63 | + |
| 64 | +cat <<-EOH |
| 65 | +# this file is generated via https://github.com/redis/docker-library-redis/blob/$(fileCommit "$self")/$self |
| 66 | +
|
| 67 | +Maintainers: David Maier <[email protected]> (@dmaier-redislabs), |
| 68 | + Yossi Gottlieb <[email protected]> (@yossigo) |
| 69 | +GitRepo: https://github.com/redis/docker-library-redis.git |
| 70 | +EOH |
| 71 | + |
| 72 | +# prints "$2$1$3$1...$N" |
| 73 | +join() { |
| 74 | + local sep="$1"; shift |
| 75 | + local out; printf -v out "${sep//%/%%}%s" "$@" |
| 76 | + echo "${out#$sep}" |
| 77 | +} |
| 78 | + |
| 79 | +for version; do |
| 80 | + export version |
| 81 | + |
| 82 | + fullVersion="$(jq -r '.[env.version].version' versions.json)" |
| 83 | + |
| 84 | + versionAliases=() |
| 85 | + while [ "$fullVersion" != "$version" ] && [ "${fullVersion%.*}" != "$fullVersion" ]; do |
| 86 | + versionAliases+=( $fullVersion ) |
| 87 | + fullVersion="${fullVersion%.*}" |
| 88 | + done |
| 89 | + versionAliases+=( |
| 90 | + $version |
| 91 | + ${aliases[$version]:-} |
| 92 | + ) |
| 93 | + |
| 94 | + for variant in debian alpine; do |
| 95 | + export variant |
| 96 | + dir="$version/$variant" |
| 97 | + |
| 98 | + commit="$(dirCommit "$dir")" |
| 99 | + |
| 100 | + if [ "$variant" = 'debian' ]; then |
| 101 | + variantAliases=( "${versionAliases[@]}" ) |
| 102 | + else |
| 103 | + variantAliases=( "${versionAliases[@]/%/-$variant}" ) |
| 104 | + variantAliases=( "${variantAliases[@]//latest-/}" ) |
| 105 | + fi |
| 106 | + |
| 107 | + parent="$(gawk 'toupper($1) == "FROM" { print $2 }' "$dir/Dockerfile")" |
| 108 | + arches="${parentRepoToArches[$parent]}" |
| 109 | + |
| 110 | + suite="${parent#*:}" # "bookworm-slim", "bookworm" |
| 111 | + suite="${suite%-slim}" # "bookworm" |
| 112 | + if [ "$variant" = 'alpine' ]; then |
| 113 | + suite="alpine$suite" # "alpine3.18" |
| 114 | + fi |
| 115 | + suiteAliases=( "${versionAliases[@]/%/-$suite}" ) |
| 116 | + suiteAliases=( "${suiteAliases[@]//latest-/}" ) |
| 117 | + variantAliases+=( "${suiteAliases[@]}" ) |
| 118 | + |
| 119 | + # calculate the intersection of parent image arches and gosu arches |
| 120 | + arches="$(jq -r --arg arches "$arches" ' |
| 121 | + ( |
| 122 | + $arches |
| 123 | + | gsub("^[[:space:]]+|[[:space:]]+$"; "") |
| 124 | + | split("[[:space:]]+"; "") |
| 125 | + ) as $parentArches |
| 126 | + | .[env.version] |
| 127 | + | $parentArches - ($parentArches - (.gosu.arches | keys)) |
| 128 | + | join(", ") |
| 129 | + ' versions.json)" |
| 130 | + |
| 131 | + echo |
| 132 | + cat <<-EOE |
| 133 | + Tags: $(join ', ' "${variantAliases[@]}") |
| 134 | + Architectures: $arches |
| 135 | + GitCommit: $commit |
| 136 | + Directory: $dir |
| 137 | + EOE |
| 138 | + done |
| 139 | +done |
0 commit comments