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