1
0

update.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #!/usr/bin/env bash
  2. set -Eeuo pipefail
  3. cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. helperDir='.template-helpers'
  5. # usage: ./update.sh [--namespace NAMESPACE] [[NAMESPACE/]IMAGE ...]
  6. # ie: ./update.sh
  7. # ./update.sh debian golang
  8. # ./update.sh --namespace tianontesting debian golang
  9. # ./update.sh tianontesting/debian tianontestingmore/golang
  10. # BASHBREW_ARCH=windows-amd64 BASHBREW_ARCH_NAMESPACES='...' ./update.sh --namespace winamd64
  11. forceNamespace=
  12. if [ "${1:-}" = '--namespace' ]; then
  13. shift
  14. forceNamespace="$1"
  15. shift
  16. fi
  17. images=( "$@" )
  18. if [ ${#images[@]} -eq 0 ]; then
  19. images=( */ )
  20. fi
  21. images=( "${images[@]%/}" )
  22. if [ -n "$forceNamespace" ]; then
  23. images=( "${images[@]/#/"$forceNamespace/"}" )
  24. fi
  25. replace_field() {
  26. targetFile="$1"
  27. field="$2"
  28. content="$3"
  29. extraSed="${4:-}"
  30. sed_escaped_value="$(echo "$content" | sed 's/[\/&]/\\&/g')"
  31. sed_escaped_value="${sed_escaped_value//$'\n'/\\n}"
  32. sed -ri -e "s/${extraSed}%%${field}%%${extraSed}/$sed_escaped_value/g" "$targetFile"
  33. }
  34. for image in "${images[@]}"; do
  35. repo="${image##*/}"
  36. namespace="${image%$repo}"
  37. namespace="${namespace%/}"
  38. # this is used by subscripts to determine whether we're pushing /_/xxx or /r/ARCH/xxx
  39. # (especialy for "supported tags")
  40. export ARCH_SPECIFIC_DOCS=
  41. if [ -n "$namespace" ] && [ -n "${BASHBREW_ARCH:-}" ]; then
  42. export ARCH_SPECIFIC_DOCS=1
  43. fi
  44. if [ -x "$repo/update.sh" ]; then
  45. ( set -x; "$repo/update.sh" "$image" )
  46. fi
  47. if [ -e "$repo/content.md" ]; then
  48. githubRepo="$(cat "$repo/github-repo")"
  49. maintainer="$(cat "$repo/maintainer.md")"
  50. issues="$(cat "$repo/issues.md" 2>/dev/null || cat "$helperDir/issues.md")"
  51. getHelp="$(cat "$repo/get-help.md" 2>/dev/null || cat "$helperDir/get-help.md")"
  52. license="$(cat "$repo/license.md" 2>/dev/null || true)"
  53. licenseCommon="$(cat "$repo/license-common.md" 2>/dev/null || cat "$helperDir/license-common.md")"
  54. if [ "$license" ]; then
  55. license=$'\n\n''# License'$'\n\n'"$license"$'\n\n'"$licenseCommon"
  56. fi
  57. logo=
  58. logoFile=
  59. for f in png svg; do
  60. if [ -e "$repo/logo.$f" ]; then
  61. logoFile="$repo/logo.$f"
  62. break
  63. fi
  64. done
  65. if [ "$logoFile" ]; then
  66. logoCommit="$(git log -1 --format='format:%H' -- "$logoFile" 2>/dev/null || true)"
  67. [ "$logoCommit" ] || logoCommit='master'
  68. logoUrl="https://raw.githubusercontent.com/docker-library/docs/$logoCommit/$logoFile"
  69. if [ "${logoFile##*.}" = 'svg' ]; then
  70. # https://stackoverflow.com/a/16462143/433558
  71. logoUrl+='?sanitize=true'
  72. fi
  73. logo="![logo]($logoUrl)"
  74. fi
  75. compose=
  76. composeYaml=
  77. if [ -f "$repo/compose.yaml" ]; then
  78. compose="$(cat "$repo/compose.md" 2>/dev/null || cat "$helperDir/compose.md")"
  79. composeYaml=$'```yaml\n'"$(cat "$repo/compose.yaml")"$'\n```'
  80. fi
  81. deprecated=
  82. if [ -f "$repo/deprecated.md" ]; then
  83. deprecated="$(< "$repo/deprecated.md")"
  84. if [ "${deprecated:0:2}" != '# ' ]; then
  85. deprecated=$'# **DEPRECATION NOTICE**\n\n'"$deprecated"
  86. fi
  87. deprecated+=$'\n\n'
  88. fi
  89. if ! partial="$("$helperDir/generate-dockerfile-links-partial.sh" "$repo")"; then
  90. {
  91. echo
  92. echo "WARNING: failed to fetch tags for '$repo'; skipping!"
  93. echo
  94. } >&2
  95. continue
  96. fi
  97. targetFile="$repo/README.md"
  98. {
  99. cat "$helperDir/autogenerated-warning.md"
  100. echo
  101. if [ -n "$ARCH_SPECIFIC_DOCS" ]; then
  102. echo '**Note:** this is the "per-architecture" repository for the `'"$BASHBREW_ARCH"'` builds of [the `'"$repo"'` official image](https://hub.docker.com/_/'"$repo"') -- for more information, see ["Architectures other than amd64?" in the official images documentation](https://github.com/docker-library/official-images#architectures-other-than-amd64) and ["An image'\''s source changed in Git, now what?" in the official images FAQ](https://github.com/docker-library/faq#an-images-source-changed-in-git-now-what).'
  103. echo
  104. fi
  105. echo -n "$deprecated"
  106. cat "$helperDir/template.md"
  107. } > "$targetFile"
  108. echo ' TAGS => generate-dockerfile-links-partial.sh "'"$repo"'"'
  109. if [ -z "$partial" ]; then
  110. if [ -n "$ARCH_SPECIFIC_DOCS" ]; then
  111. partial='**No supported tags found!**'$'\n\n''It is very likely that `%%REPO%%` does not support the currently selected architecture (`'"$BASHBREW_ARCH"'`).'
  112. else
  113. # opensuse, etc
  114. partial='**No supported tags**'
  115. fi
  116. fi
  117. replace_field "$targetFile" 'TAGS' "$partial"
  118. echo ' ARCHES => arches.sh "'"$repo"'"'
  119. arches="$("$helperDir/arches.sh" "$repo")"
  120. [ -n "$arches" ] || arches='**No supported architectures**'
  121. replace_field "$targetFile" 'ARCHES' "$arches"
  122. echo ' CONTENT => '"$repo"'/content.md'
  123. replace_field "$targetFile" 'CONTENT' "$(cat "$repo/content.md")"
  124. echo ' VARIANT => variant.sh'
  125. replace_field "$targetFile" 'VARIANT' "$("$helperDir/variant.sh" "$repo")"
  126. # has to be after CONTENT because it's contained in content.md
  127. echo " LOGO => $logo"
  128. replace_field "$targetFile" 'LOGO' "$logo" '\s*'
  129. echo ' COMPOSE => '"$repo"'/compose.md'
  130. replace_field "$targetFile" 'COMPOSE' "$compose"
  131. echo ' COMPOSE-YAML => '"$repo"'/compose.yaml'
  132. replace_field "$targetFile" 'COMPOSE-YAML' "$composeYaml"
  133. echo ' LICENSE => '"$repo"'/license.md'
  134. replace_field "$targetFile" 'LICENSE' "$license"
  135. echo ' ISSUES => "'"$issues"'"'
  136. replace_field "$targetFile" 'ISSUES' "$issues"
  137. echo ' GET-HELP => "'"$getHelp"'"'
  138. replace_field "$targetFile" 'GET-HELP' "$getHelp"
  139. echo ' MAINTAINER => "'"$maintainer"'"'
  140. replace_field "$targetFile" 'MAINTAINER' "$maintainer"
  141. echo ' IMAGE => "'"$image"'"'
  142. replace_field "$targetFile" 'IMAGE' "$image"
  143. echo ' REPO => "'"$repo"'"'
  144. replace_field "$targetFile" 'REPO' "$repo"
  145. echo ' GITHUB-REPO => "'"$githubRepo"'"'
  146. replace_field "$targetFile" 'GITHUB-REPO' "$githubRepo"
  147. echo
  148. else
  149. echo >&2 "skipping $repo: missing repo/content.md"
  150. fi
  151. done