update.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #!/bin/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. stack=
  76. stackYml=
  77. stackUrl=
  78. if [ -f "$repo/stack.yml" ]; then
  79. stack="$(cat "$repo/stack.md" 2>/dev/null || cat "$helperDir/stack.md")"
  80. stackYml=$'```yaml\n'"$(cat "$repo/stack.yml")"$'\n```'
  81. stackCommit="$(git log -1 --format='format:%H' -- "$repo/stack.yml" 2>/dev/null || true)"
  82. [ "$stackCommit" ] || stackCommit='master'
  83. stackUrl="https://raw.githubusercontent.com/docker-library/docs/$stackCommit/$repo/stack.yml"
  84. fi
  85. compose=
  86. composeYml=
  87. if [ -f "$repo/docker-compose.yml" ]; then
  88. compose="$(cat "$repo/compose.md" 2>/dev/null || cat "$helperDir/compose.md")"
  89. composeYml=$'```yaml\n'"$(cat "$repo/docker-compose.yml")"$'\n```'
  90. fi
  91. deprecated=
  92. if [ -f "$repo/deprecated.md" ]; then
  93. deprecated=$'# **DEPRECATION NOTICE**\n\n'
  94. deprecated+="$(cat "$repo/deprecated.md")"
  95. deprecated+=$'\n\n'
  96. fi
  97. if ! partial="$("$helperDir/generate-dockerfile-links-partial.sh" "$repo")"; then
  98. {
  99. echo
  100. echo "WARNING: failed to fetch tags for '$repo'; skipping!"
  101. echo
  102. } >&2
  103. continue
  104. fi
  105. targetFile="$repo/README.md"
  106. {
  107. cat "$helperDir/autogenerated-warning.md"
  108. echo
  109. if [ -n "$ARCH_SPECIFIC_DOCS" ]; then
  110. 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).'
  111. echo
  112. fi
  113. echo -n "$deprecated"
  114. cat "$helperDir/template.md"
  115. } > "$targetFile"
  116. echo ' TAGS => generate-dockerfile-links-partial.sh "'"$repo"'"'
  117. if [ -z "$partial" ]; then
  118. if [ -n "$ARCH_SPECIFIC_DOCS" ]; then
  119. partial='**No supported tags found!**'$'\n\n''It is very likely that `%%REPO%%` does not support the currently selected architecture (`'"$BASHBREW_ARCH"'`).'
  120. else
  121. # opensuse, etc
  122. partial='**No supported tags**'
  123. fi
  124. elif [ -n "$ARCH_SPECIFIC_DOCS" ]; then
  125. jenkinsJobUrl="https://doi-janky.infosiftr.net/job/multiarch/job/$BASHBREW_ARCH/job/$repo/"
  126. jenkinsImageUrl="https://img.shields.io/jenkins/s/https/doi-janky.infosiftr.net/job/multiarch/job/$BASHBREW_ARCH/job/$repo.svg?label=%%IMAGE%%%20%20build%20job"
  127. partial+=$'\n\n''[![%%IMAGE%% build status badge]('"$jenkinsImageUrl"')]('"$jenkinsJobUrl"')'
  128. fi
  129. replace_field "$targetFile" 'TAGS' "$partial"
  130. echo ' ARCHES => arches.sh "'"$repo"'"'
  131. arches="$("$helperDir/arches.sh" "$repo")"
  132. [ -n "$arches" ] || arches='**No supported architectures**'
  133. replace_field "$targetFile" 'ARCHES' "$arches"
  134. echo ' CONTENT => '"$repo"'/content.md'
  135. replace_field "$targetFile" 'CONTENT' "$(cat "$repo/content.md")"
  136. echo ' VARIANT => variant.sh'
  137. replace_field "$targetFile" 'VARIANT' "$("$helperDir/variant.sh" "$repo")"
  138. # has to be after CONTENT because it's contained in content.md
  139. echo " LOGO => $logo"
  140. replace_field "$targetFile" 'LOGO' "$logo" '\s*'
  141. echo ' STACK => '"$repo"'/stack.md'
  142. replace_field "$targetFile" 'STACK' "$stack"
  143. echo ' STACK-YML => '"$repo"'/stack.yml'
  144. replace_field "$targetFile" 'STACK-YML' "$stackYml"
  145. echo ' STACK-URL => '"$repo"'/stack.yml'
  146. replace_field "$targetFile" 'STACK-URL' "$stackUrl"
  147. echo ' COMPOSE => '"$repo"'/compose.md'
  148. replace_field "$targetFile" 'COMPOSE' "$compose"
  149. echo ' COMPOSE-YML => '"$repo"'/docker-compose.yml'
  150. replace_field "$targetFile" 'COMPOSE-YML' "$composeYml"
  151. echo ' LICENSE => '"$repo"'/license.md'
  152. replace_field "$targetFile" 'LICENSE' "$license"
  153. echo ' ISSUES => "'"$issues"'"'
  154. replace_field "$targetFile" 'ISSUES' "$issues"
  155. echo ' GET-HELP => "'"$getHelp"'"'
  156. replace_field "$targetFile" 'GET-HELP' "$getHelp"
  157. echo ' MAINTAINER => "'"$maintainer"'"'
  158. replace_field "$targetFile" 'MAINTAINER' "$maintainer"
  159. echo ' IMAGE => "'"$image"'"'
  160. replace_field "$targetFile" 'IMAGE' "$image"
  161. echo ' REPO => "'"$repo"'"'
  162. replace_field "$targetFile" 'REPO' "$repo"
  163. echo ' GITHUB-REPO => "'"$githubRepo"'"'
  164. replace_field "$targetFile" 'GITHUB-REPO' "$githubRepo"
  165. echo
  166. else
  167. echo >&2 "skipping $repo: missing repo/content.md"
  168. fi
  169. done