From 8e97f59d42f6f47a7556274186b4ff84a6de419f Mon Sep 17 00:00:00 2001 From: Joe Ferguson Date: Thu, 11 Oct 2018 13:19:26 -0700 Subject: [PATCH] Add blurb for "*-stretch" and "*-xenial" tags; Improve variant detection for "windowsservercore-zzz" tags --- .template-helpers/variant-buildpacks.md | 7 - .../variant-default-buildpack-deps.md | 1 + .template-helpers/variant-default-debian.md | 1 + .template-helpers/variant-default-ubuntu.md | 1 + .template-helpers/variant.sh | 123 +++++++++++++++--- 5 files changed, 106 insertions(+), 27 deletions(-) delete mode 100644 .template-helpers/variant-buildpacks.md create mode 100644 .template-helpers/variant-default-buildpack-deps.md create mode 100644 .template-helpers/variant-default-debian.md create mode 100644 .template-helpers/variant-default-ubuntu.md diff --git a/.template-helpers/variant-buildpacks.md b/.template-helpers/variant-buildpacks.md deleted file mode 100644 index 0189e7f6c..000000000 --- a/.template-helpers/variant-buildpacks.md +++ /dev/null @@ -1,7 +0,0 @@ -# Image Variants - -The `%%IMAGE%%` images come in many flavors, each designed for a specific use case. - -## `%%IMAGE%%:` - -This is the defacto image. If you are unsure about what your needs are, you probably want to use this one. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as the base to build other images off of. This tag is based off of [`buildpack-deps`](https://registry.hub.docker.com/_/buildpack-deps/). `buildpack-deps` is designed for the average user of docker who has many images on their system. It, by design, has a large number of extremely common Debian packages. This reduces the number of packages that images that derive from it need to install, thus reducing the overall size of all images on your system. diff --git a/.template-helpers/variant-default-buildpack-deps.md b/.template-helpers/variant-default-buildpack-deps.md new file mode 100644 index 000000000..bc900b3ce --- /dev/null +++ b/.template-helpers/variant-default-buildpack-deps.md @@ -0,0 +1 @@ +This tag is based off of [`buildpack-deps`](https://registry.hub.docker.com/_/buildpack-deps/). `buildpack-deps` is designed for the average user of docker who has many images on their system. It, by design, has a large number of extremely common Debian packages. This reduces the number of packages that images that derive from it need to install, thus reducing the overall size of all images on your system. diff --git a/.template-helpers/variant-default-debian.md b/.template-helpers/variant-default-debian.md new file mode 100644 index 000000000..b3f99fbc9 --- /dev/null +++ b/.template-helpers/variant-default-debian.md @@ -0,0 +1 @@ +Some of these tags may have names like %%DEB-SUITES%% in them. These are the suite code names for releases of [Debian](https://wiki.debian.org/DebianReleases) and indicate which release the image is based on. diff --git a/.template-helpers/variant-default-ubuntu.md b/.template-helpers/variant-default-ubuntu.md new file mode 100644 index 000000000..ef152548d --- /dev/null +++ b/.template-helpers/variant-default-ubuntu.md @@ -0,0 +1 @@ +Some of these tags may have names like %%DEB-SUITES%% in them. These are the suite code names for releases of [Ubuntu](https://wiki.ubuntu.com/Releases) and indicate which release the image is based on. diff --git a/.template-helpers/variant.sh b/.template-helpers/variant.sh index 85b35c628..03c28dc8b 100755 --- a/.template-helpers/variant.sh +++ b/.template-helpers/variant.sh @@ -11,11 +11,59 @@ fi dir="$(dirname "$(readlink -f "$BASH_SOURCE")")" repoDir="$dir/../$repo" -# if we haven't set BASHBREW_LIBRARY explicitly (like Jenkins does, for example), don't trust the local library -if [ -z "${BASHBREW_LIBRARY:-}" ]; then - repo="https://github.com/docker-library/official-images/raw/master/library/$repo" -fi +# prints "$2$1$3$1...$N" +join() { + local sep="$1"; shift + local out; printf -v out "${sep//%/%%}%s" "$@" + echo "${out#$sep}" +} +commaJoin() { + local items=( $(xargs -n1 <<<"$1" | sort -u) ); shift + sep=', ' + case "${#items[@]}" in + 0) + return + ;; + 1) + echo "$items" + return + ;; + 2) + sep=' ' + ;; + esac + + items[-1]="or ${items[-1]}" + join "$sep" "${items[@]}" +} + +tagFiles() { + local tag="$1"; shift + local tagUltimate="${tag##*-}" # 3.6-stretch -> stretch + local tagPenultimate="${tag%-*}" # 2.7.15-windowsservercore-1803 -> 2.7.15-windowsservercore + tagPenultimate="${tagPenultimate##*-}" # 2.7.15-windowsservercore -> windowsservercore + + echo \ + "$repoDir/variant-$tag.md" \ + "$repoDir/variant-$tagUltimate.md" \ + "$repoDir/variant-$tagPenultimate.md" \ + "$dir/variant-$tag.md" \ + "$dir/variant-$tagUltimate.md" \ + "$dir/variant-$tagPenultimate.md" +} + +_repo() { + local repo=$1; shift +# if we haven't set BASHBREW_LIBRARY explicitly (like Jenkins does, for example), don't trust the local library + if [ -z "${BASHBREW_LIBRARY:-}" ]; then + repo="https://github.com/docker-library/official-images/raw/master/library/$repo" + fi + + echo "$repo" +} + +bbRepo="$(_repo "$repo")" IFS=$'\n' tags=( $(bashbrew cat -f ' {{- $archSpecific := getenv "ARCH_SPECIFIC_DOCS" -}} @@ -24,16 +72,13 @@ tags=( $(bashbrew cat -f ' {{- join "\n" .Tags -}} {{- "\n" -}} {{- end -}} -' "$repo") ) +' "$bbRepo") ) unset IFS text= declare -A includedFiles=() for tag in "${tags[@]}"; do - for f in \ - "$repoDir/variant-$tag.md" "$repoDir/variant-${tag##*-}.md" \ - "$dir/variant-$tag.md" "$dir/variant-${tag##*-}.md" \ - ; do + for f in $(tagFiles "$tag"); do if [ -n "${includedFiles[$f]}" ]; then # make sure we don't duplicate variant sections break @@ -52,25 +97,63 @@ for tag in "${tags[@]}"; do done if [ "$text" ]; then - buildpacks= - potentialTags="$(bashbrew list --uniq "$repo" | cut -d: -f2)" + default="$([ -f "$repoDir/variant.md" ] && cat "$repoDir/variant.md" || cat "$dir/variant.md")" + default+=$'\n' # parameter expansion eats the trailing newline + + # buildpack-deps text + potentialTags="$(bashbrew list --uniq "$bbRepo" | cut -d: -f2)" for tag in $potentialTags; do - baseImage="$(bashbrew cat -f '{{ .ArchDockerFrom (.TagEntry.Architectures | first) .TagEntry }}' "$repo:$tag")" + baseImage="$(bashbrew cat -f '{{ .ArchDockerFrom (.TagEntry.Architectures | first) .TagEntry }}' "$bbRepo:$tag")" case "$baseImage" in buildpack-deps:*-*) ;; # "scm", "curl" -- not large images - buildpack-deps:*) buildpacks=1; break ;; + buildpack-deps:*) + default+=$'\n' # give a little space + default+="$(< "$dir/variant-default-buildpack-deps.md")" + default+=$'\n' # parameter expansion eats the trailing newline + break + ;; esac done - echo - echo + if [ "$repo" != 'debian' ] && [ "$repo" != 'ubuntu' ]; then + # what is 'jessie', 'stretch' and 'sid' + # https://github.com/docker-library/python/issues/343 + debian=( $(bashbrew list --uniq "$(_repo 'debian')" | grep -vE 'stable|slim|backports|experimental' | cut -d: -f2) ) + ubuntu=( $(bashbrew list "$(_repo 'ubuntu')" | grep -vE 'devel|latest|[0-9]' | cut -d: -f2) ) + foundDebianTags= + foundUbuntuTags= + for tag in ${tags[@]}; do + for suite in "${debian[@]}"; do + case "$tag" in + *-"$suite" | "$suite"-* | *-"$suite"-* | "$suite" ) + foundDebianTags+=" $suite" + ;; + esac + done + for suite in "${ubuntu[@]}"; do + case "$tag" in + *-"$suite" | "$suite"-* | *-"$suite"-* | "$suite" ) + foundUbuntuTags+=" $suite" + ;; + esac + done + done - if [ -n "$buildpacks" ]; then - f='variant-buildpacks.md' - else - f='variant.md' + if [ -n "$foundDebianTags" ]; then + default+=$'\n' # give a little space + default+="$( sed -e 's/%%DEB-SUITES%%/'"$(commaJoin "$foundDebianTags")"'/' "$dir/variant-default-debian.md" )" + default+=$'\n' # parameter expansion eats the trailing newline + fi + if [ -n "$foundUbuntuTags" ]; then + default+=$'\n' # give a little space + default+="$( sed -e 's/%%DEB-SUITES%%/'"$(commaJoin "$foundUbuntuTags")"'/' "$dir/variant-default-ubuntu.md" )" + default+=$'\n' # parameter expansion eats the trailing newline + fi fi - [ -f "$repoDir/$f" ] && cat "$repoDir/$f" || cat "$dir/$f" + echo + echo + + echo -n "$default" echo "$text" fi