build-docs-container 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. function usage()
  26. {
  27. echo "$0 -- script to build documentation from within a container
  28. $0 OCI_IMAGE [make arguments...]
  29. OCI_IMAGE is an image:tag of an OCI image hosted on hub.docker.com. It is one
  30. of:
  31. - debian:12
  32. - fedora:38
  33. - fedora:39
  34. - fedora:40
  35. - leap:15.4
  36. - leap:15.5
  37. - ubuntu:22.04
  38. - ubuntu:24.04
  39. [make arguments] is one or more argument to pass to the make command of
  40. documentation/Makefile, see that file for what's supported. This is typically
  41. intended to be used to provide specific make targets.
  42. Default: publish
  43. "
  44. }
  45. main ()
  46. {
  47. if [ "$#" -lt 1 ]; then
  48. usage
  49. exit 1
  50. fi
  51. local image="$1"
  52. shift
  53. OCI=$(which "$CONTAINERCMD")
  54. # docker build doesn't accept 2 colons, so "sanitize" the name
  55. local sanitized_dockername
  56. sanitized_dockername=$(echo "$image" | tr ':.' '-')
  57. local version
  58. version=$(echo "$image" | awk -F: '{print $NF}')
  59. case $image in
  60. # Missing latexmk texlive-gnu-freefont packages at the very least
  61. # "almalinux:8"*|\
  62. # "almalinux:9"*)
  63. # containerfile=Containerfile.almalinux
  64. # docs=almalinux_docs.sh
  65. # docs_pdf=almalinux_docs_pdf.sh
  66. # pip3=pip3_docs.sh
  67. # ;;
  68. # Missing python3-saneyaml
  69. # "debian:11"*|\
  70. "debian:12"*)
  71. containerfile=Containerfile.debian
  72. docs=ubuntu_docs.sh
  73. docs_pdf=ubuntu_docs_pdf.sh
  74. ;;
  75. "fedora:38"*|\
  76. "fedora:39"*|\
  77. "fedora:40"*)
  78. containerfile=Containerfile.fedora
  79. docs=fedora_docs.sh
  80. docs_pdf=fedora_docs_pdf.sh
  81. pip3=pip3_docs.sh
  82. ;;
  83. "leap:15.4"*|\
  84. "leap:15.5"*)
  85. # Seems like issue with permissions package, c.f.
  86. #
  87. # Updating /etc/sysconfig/security ...
  88. # /dev/zero: chown: Permission denied
  89. # /dev/null: chown: Permission denied
  90. # /dev/full: chown: Permission denied
  91. # ERROR: not all operations were successful.
  92. # Checking permissions and ownerships - using the permissions files
  93. # /etc/permissions
  94. # /etc/permissions.easy
  95. # /etc/permissions.local
  96. # setting / to root:root 0755. (wrong permissions 0555)
  97. # setting /dev/zero to root:root 0666. (wrong owner/group 65534:65534)
  98. # setting /dev/null to root:root 0666. (wrong owner/group 65534:65534)
  99. # setting /dev/full to root:root 0666. (wrong owner/group 65534:65534)
  100. # warning: %post(permissions-20240826-150600.10.12.1.x86_64) scriptlet failed, exit status 1
  101. #
  102. # "leap:15.6"*)
  103. image=opensuse/leap:$version
  104. containerfile=Containerfile.zypper
  105. docs=opensuse_docs.sh
  106. docs_pdf=opensuse_docs_pdf.sh
  107. pip3=pip3_docs.sh
  108. ;;
  109. # Missing python3-saneyaml
  110. # "ubuntu:18.04"*|\
  111. # "ubuntu:20.04"*|\
  112. # Cannot fetch packages anymore
  113. # "ubuntu:23.04"*|\
  114. "ubuntu:22.04"*|\
  115. "ubuntu:24.04"*)
  116. containerfile=Containerfile.ubuntu
  117. docs=ubuntu_docs.sh
  118. docs_pdf=ubuntu_docs_pdf.sh
  119. ;;
  120. *)
  121. echo "$image not supported!"
  122. usage
  123. exit 1
  124. ;;
  125. esac
  126. $OCI build \
  127. --tag "yocto-docs-$sanitized_dockername:latest" \
  128. --build-arg ARG_FROM="docker.io/$image" \
  129. --build-arg DOCS="$docs" \
  130. --build-arg DOCS_PDF="$docs_pdf" \
  131. --build-arg PIP3="${pip3:-}" \
  132. --file "$SCRIPT_DIR/$containerfile" \
  133. "$SH_DIR/"
  134. local -a args_run=(
  135. --rm
  136. --interactive
  137. --tty
  138. --volume="$DOCS_DIR:/docs:rw"
  139. --workdir=/docs
  140. --security-opt label=disable
  141. )
  142. if [ "$OCI" = "docker" ]; then
  143. args_run+=(
  144. --user="$(id -u)":"$(id -g)"
  145. )
  146. elif [ "$OCI" = "podman" ]; then
  147. # we need net access to fetch bitbake terms
  148. args_run+=(
  149. --cap-add=NET_RAW
  150. --userns=keep-id
  151. )
  152. fi
  153. $OCI run \
  154. "${args_run[@]}" \
  155. "yocto-docs-$sanitized_dockername" \
  156. "$@"
  157. }
  158. main "$@"