build-docs-container 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #!/usr/bin/env bash
  2. # -*- vim: set expandtab tabstop=2 shiftwidth=2:
  3. #
  4. # Build a container ready to build the documentation be reading the dependencies
  5. # listed in shell scripts in documentation/tools/host_packages_scripts, and
  6. # start a documentation build in this container.
  7. #
  8. # Usage:
  9. #
  10. # ./documentation/tools/build-docs-container <image> [<make target>]
  11. #
  12. # e.g.:
  13. #
  14. # ./documentation/tools/build-docs-container ubuntu:24.04 html
  15. #
  16. # Will build the docs in an Ubuntu 24.04 container in html.
  17. #
  18. # The container engine can be selected by exporting CONTAINERCMD in the
  19. # environment. The default is docker, but podman can also be used.
  20. set -eu -o pipefail
  21. SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
  22. CONTAINERCMD=${CONTAINERCMD:-docker}
  23. DOCS_DIR="$SCRIPT_DIR/../.."
  24. SH_DIR="$SCRIPT_DIR/host_packages_scripts"
  25. INCLUDE_ESSENTIAL_PACKAGES=${INCLUDE_ESSENTIAL_PACKAGES:-0}
  26. function usage()
  27. {
  28. echo "$0 -- script to build documentation from within a container
  29. $0 OCI_IMAGE [make arguments...]
  30. OCI_IMAGE is an image:tag of an OCI image hosted on hub.docker.com. It is one
  31. of:
  32. - debian:12
  33. - debian:13
  34. - fedora:39
  35. - fedora:40
  36. - fedora:41
  37. - fedora:42
  38. - leap:15.5
  39. - leap:15.6
  40. - ubuntu:22.04
  41. - ubuntu:24.04
  42. - ubuntu:25.04
  43. [make arguments] is one or more argument to pass to the make command of
  44. documentation/Makefile, see that file for what's supported. This is typically
  45. intended to be used to provide specific make targets.
  46. Default: publish
  47. Environment variables:
  48. - CONTAINERCMD can be set to 'docker' or 'podman' to select the
  49. container engine (default: 'docker').
  50. - INCLUDE_ESSENTIAL_PACKAGES can be set to 0 or 1 to also include essential
  51. packages listed in documentation/tools/host_packages_scripts/*_essential.sh.
  52. This is not required to build the documentation but can be useful to validate
  53. the installation of packages listed in these files (default: 0).
  54. "
  55. }
  56. main ()
  57. {
  58. if [ "$#" -lt 1 ]; then
  59. usage
  60. exit 1
  61. fi
  62. local image="$1"
  63. shift
  64. OCI=$(which "$CONTAINERCMD")
  65. # docker build doesn't accept 2 colons, so "sanitize" the name
  66. local sanitized_dockername
  67. sanitized_dockername=$(echo "$image" | tr ':.' '-')
  68. local version
  69. version=$(echo "$image" | awk -F: '{print $NF}')
  70. case $image in
  71. # Missing latexmk texlive-gnu-freefont packages at the very least
  72. # "almalinux:8"*|\
  73. # "almalinux:9"*)
  74. # containerfile=Containerfile.almalinux
  75. # docs=almalinux_docs.sh
  76. # docs_pdf=almalinux_docs_pdf.sh
  77. # pip3=pip3_docs.sh
  78. # ;;
  79. # Missing python3-saneyaml
  80. # "debian:11"*|\
  81. "debian:12"*|\
  82. "debian:13"*)
  83. containerfile=Containerfile.debian
  84. essential=ubuntu_essential.sh
  85. docs=ubuntu_docs.sh
  86. docs_pdf=ubuntu_docs_pdf.sh
  87. ;;
  88. "fedora:39"*|\
  89. "fedora:40"*|\
  90. "fedora:41"*|\
  91. "fedora:42"*)
  92. containerfile=Containerfile.fedora
  93. essential=fedora_essential.sh
  94. docs=fedora_docs.sh
  95. docs_pdf=fedora_docs_pdf.sh
  96. pip3=pip3_docs.sh
  97. ;;
  98. "leap:15.5"*|\
  99. "leap:15.6"*)
  100. # Seems like issue with permissions package, c.f.
  101. #
  102. # Updating /etc/sysconfig/security ...
  103. # /dev/zero: chown: Permission denied
  104. # /dev/null: chown: Permission denied
  105. # /dev/full: chown: Permission denied
  106. # ERROR: not all operations were successful.
  107. # Checking permissions and ownerships - using the permissions files
  108. # /etc/permissions
  109. # /etc/permissions.easy
  110. # /etc/permissions.local
  111. # setting / to root:root 0755. (wrong permissions 0555)
  112. # setting /dev/zero to root:root 0666. (wrong owner/group 65534:65534)
  113. # setting /dev/null to root:root 0666. (wrong owner/group 65534:65534)
  114. # setting /dev/full to root:root 0666. (wrong owner/group 65534:65534)
  115. # warning: %post(permissions-20240826-150600.10.12.1.x86_64) scriptlet failed, exit status 1
  116. #
  117. # "leap:15.6"*)
  118. image=opensuse/leap:$version
  119. containerfile=Containerfile.zypper
  120. essential=opensuse_essential.sh
  121. docs=opensuse_docs.sh
  122. docs_pdf=opensuse_docs_pdf.sh
  123. pip3=pip3_docs.sh
  124. ;;
  125. # Cannot fetch packages anymore
  126. # "ubuntu:23.04"*|\
  127. "ubuntu:22.04"*|\
  128. "ubuntu:24.04"*|\
  129. "ubuntu:25.04"*)
  130. containerfile=Containerfile.ubuntu
  131. essential=ubuntu_essential.sh
  132. docs=ubuntu_docs.sh
  133. docs_pdf=ubuntu_docs_pdf.sh
  134. ;;
  135. *)
  136. echo "$image not supported!"
  137. usage
  138. exit 1
  139. ;;
  140. esac
  141. $OCI build \
  142. --tag "yocto-docs-$sanitized_dockername:latest" \
  143. --build-arg ARG_FROM="docker.io/$image" \
  144. --build-arg INCLUDE_ESSENTIAL_PACKAGES="${INCLUDE_ESSENTIAL_PACKAGES}" \
  145. --build-arg ESSENTIAL="$essential" \
  146. --build-arg DOCS="$docs" \
  147. --build-arg DOCS_PDF="$docs_pdf" \
  148. --build-arg PIP3="${pip3:-}" \
  149. --file "$SCRIPT_DIR/$containerfile" \
  150. "$SH_DIR/"
  151. local -a args_run=(
  152. --rm
  153. --interactive
  154. --tty
  155. --volume="$DOCS_DIR:/docs:rw"
  156. --workdir=/docs
  157. --security-opt label=disable
  158. )
  159. if [ "$OCI" = "docker" ]; then
  160. args_run+=(
  161. --user="$(id -u)":"$(id -g)"
  162. )
  163. elif [ "$OCI" = "podman" ]; then
  164. # we need net access to fetch bitbake terms
  165. args_run+=(
  166. --cap-add=NET_RAW
  167. --userns=keep-id
  168. )
  169. fi
  170. $OCI run \
  171. "${args_run[@]}" \
  172. "yocto-docs-$sanitized_dockername" \
  173. "$@"
  174. }
  175. main "$@"