variant.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. for tag in "${tags[@]}"; do
  29. for f in "$repoDir/variant-$tag.md" "$dir/variant-$tag.md"; do
  30. if [ -f "$f" ]; then
  31. text+=$'\n' # give a little space
  32. text+="$(< "$f")"
  33. text+=$'\n' # parameter expansion eats the trailing newline
  34. break
  35. fi
  36. done
  37. done
  38. if [ "$text" ]; then
  39. baseImage="$(bashbrew cat -f '{{ .DockerFrom .TagEntry }}' "$repo":latest)"
  40. baseImage="${baseImage%:*}"
  41. echo
  42. echo
  43. if [ "$baseImage" = 'buildpack-deps' ]; then
  44. f='variant-buildpacks.md'
  45. else
  46. f='variant.md'
  47. fi
  48. [ -f "$repoDir/$f" ] && cat "$repoDir/$f" || cat "$dir/$f"
  49. echo "$text"
  50. fi