build-docs-container 4.4 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. 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. image=opensuse/leap:$version
  101. containerfile=Containerfile.zypper
  102. essential=opensuse_essential.sh
  103. docs=opensuse_docs.sh
  104. docs_pdf=opensuse_docs_pdf.sh
  105. pip3=pip3_docs.sh
  106. ;;
  107. "ubuntu:22.04"*|\
  108. "ubuntu:24.04"*|\
  109. "ubuntu:25.04"*)
  110. containerfile=Containerfile.ubuntu
  111. essential=ubuntu_essential.sh
  112. docs=ubuntu_docs.sh
  113. docs_pdf=ubuntu_docs_pdf.sh
  114. ;;
  115. *)
  116. echo "$image not supported!"
  117. usage
  118. exit 1
  119. ;;
  120. esac
  121. $OCI build \
  122. --tag "yocto-docs-$sanitized_dockername:latest" \
  123. --build-arg ARG_FROM="docker.io/$image" \
  124. --build-arg INCLUDE_ESSENTIAL_PACKAGES="${INCLUDE_ESSENTIAL_PACKAGES}" \
  125. --build-arg ESSENTIAL="$essential" \
  126. --build-arg DOCS="$docs" \
  127. --build-arg DOCS_PDF="$docs_pdf" \
  128. --build-arg PIP3="${pip3:-}" \
  129. --file "$SCRIPT_DIR/$containerfile" \
  130. "$SH_DIR/"
  131. local -a args_run=(
  132. --rm
  133. --interactive
  134. --tty
  135. --volume="$DOCS_DIR:/docs:rw"
  136. --workdir=/docs
  137. --security-opt label=disable
  138. )
  139. if [ "$OCI" = "docker" ]; then
  140. args_run+=(
  141. --user="$(id -u)":"$(id -g)"
  142. )
  143. elif [ "$OCI" = "podman" ]; then
  144. # we need net access to fetch bitbake terms
  145. args_run+=(
  146. --cap-add=NET_RAW
  147. --userns=keep-id
  148. )
  149. fi
  150. $OCI run \
  151. "${args_run[@]}" \
  152. "yocto-docs-$sanitized_dockername" \
  153. "$@"
  154. }
  155. main "$@"