variant.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. set -eo pipefail
  3. repo="$1"
  4. if [ -z "$repo" ]; then
  5. echo >&2 "usage: $0 repo"
  6. echo >&2 " ie: $0 hylang"
  7. exit 1
  8. fi
  9. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  10. repoDir="$dir/../$repo"
  11. # if we haven't set BASHBREW_LIBRARY explicitly (like Jenkins does, for example), don't trust the local library
  12. if [ -z "${BASHBREW_LIBRARY:-}" ]; then
  13. repo="https://github.com/docker-library/official-images/raw/master/library/$repo"
  14. fi
  15. IFS=$'\n'
  16. tags=( $(bashbrew cat -f '
  17. {{- $archSpecific := getenv "ARCH_SPECIFIC_DOCS" -}}
  18. {{- range .Entries -}}
  19. {{- $arch := $archSpecific | ternary arch (.HasArchitecture arch | ternary arch (.Architectures | first)) -}}
  20. {{- if .HasArchitecture $arch -}}
  21. {{- join "\n" .Tags -}}
  22. {{- "\n" -}}
  23. {{- end -}}
  24. {{- end -}}
  25. ' "$repo") )
  26. unset IFS
  27. text=
  28. declare -A includedFiles=()
  29. for tag in "${tags[@]}"; do
  30. for f in \
  31. "$repoDir/variant-$tag.md" "$repoDir/variant-${tag##*-}.md" \
  32. "$dir/variant-$tag.md" "$dir/variant-${tag##*-}.md" \
  33. ; do
  34. if [ -n "${includedFiles[$f]}" ]; then
  35. # make sure we don't duplicate variant sections
  36. break
  37. fi
  38. if [ -f "$f" ]; then
  39. includedFiles[$f]=1
  40. if [ -s "$f" ]; then
  41. # an empty file can be used to disable a specific "variant" section for an image
  42. text+=$'\n' # give a little space
  43. text+="$(< "$f")"
  44. text+=$'\n' # parameter expansion eats the trailing newline
  45. fi
  46. break
  47. fi
  48. done
  49. done
  50. if [ "$text" ]; then
  51. buildpacks=
  52. potentialTags="$(bashbrew list --uniq "$repo" | cut -d: -f2)"
  53. for tag in $potentialTags; do
  54. baseImage="$(bashbrew cat -f '{{ .ArchDockerFrom (.TagEntry.Architectures | first) .TagEntry }}' "$repo:$tag")"
  55. case "$baseImage" in
  56. buildpack-deps:*-*) ;; # "scm", "curl" -- not large images
  57. buildpack-deps:*) buildpacks=1; break ;;
  58. esac
  59. done
  60. echo
  61. echo
  62. if [ -n "$buildpacks" ]; then
  63. f='variant-buildpacks.md'
  64. else
  65. f='variant.md'
  66. fi
  67. [ -f "$repoDir/$f" ] && cat "$repoDir/$f" || cat "$dir/$f"
  68. echo "$text"
  69. fi