From 87c62823a86470276b96b51a81db9772624dbee4 Mon Sep 17 00:00:00 2001 From: Michal Wasko Date: Tue, 25 Apr 2023 11:03:22 +0200 Subject: [PATCH] docbuild: docker support Docker image and build script added Signed-off-by: Michal Wasko --- contribute/process/docbuild.rst | 34 ++++++++++++++++- scripts/docker_build/Dockerfile | 56 ++++++++++++++++++++++++++++ scripts/docker_build/docker-build.sh | 34 +++++++++++++++++ 3 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 scripts/docker_build/Dockerfile create mode 100644 scripts/docker_build/docker-build.sh diff --git a/contribute/process/docbuild.rst b/contribute/process/docbuild.rst index 43f4998b..f1dd8f91 100644 --- a/contribute/process/docbuild.rst +++ b/contribute/process/docbuild.rst @@ -124,6 +124,11 @@ creating drawings: drawing syntax into an image. You need to have a Java runtime environment (JRE) installed when generating documentation. +There is a sof-docs Docker image recipe that can be used as an alternative to +installing the documentation tools on local OS. If you choose to use Docker then +please skip the tools installation steps and go directly to +:ref:`run_documentation_processors` + Depending on your Linux version, install the following tools: * For Ubuntu use: @@ -202,13 +207,18 @@ another ``make html`` and the output layout and style is changed. The ``read-the-docs`` theme is installed as part of the ``requirements.txt`` list above. +.. _run_documentation_processors: + Run documentation processors **************************** The sof-docs directory contains all the .rst source files, extra tools, and Makefile for generating a local copy of the SOF technical documentation. -* Generate the HTML output by using the following commands: +You can generate the HTML documentation by using local build tools (1) or by +Docker image (2) + +1. Generate the HTML output by using the following commands (**local build**): .. code-block:: bash @@ -228,6 +238,28 @@ If your changes are not related to any UML diagram, you can build more than 10 times faster from scratch by temporarily changing the ``plantuml_output_format`` line in :git-sof-docs-mainline:`conf.py`. +2. Generate the HTML output by using the following commands (**Docker build**): + + .. code-block:: bash + + cd thesofproject + # Build both sof (Doxygen) and sof-docs UML and reStruredText + ./sof-docs/scripts/docker_build/docker-build.sh + +The docker build script will copy the sof and sof-docs source code from host +working directory to image, build the documentation and when completed copy back +output to the host (./sof-docs/_build) + +The first docker build run will take more time due to image creation and +installation of all the necessary build tools. Each next build is much faster +and can additionally be speed up by selecting only sof-docs to build: + + .. code-block:: bash + + cd thesofproject + # Re-build only sof-docs + ./sof-docs/scripts/docker_build/docker-build.sh docs + Publish content *************** diff --git a/scripts/docker_build/Dockerfile b/scripts/docker_build/Dockerfile new file mode 100644 index 00000000..070f7209 --- /dev/null +++ b/scripts/docker_build/Dockerfile @@ -0,0 +1,56 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2023 Intel Corporation. All rights reserved. +# +# Defines a docker image that can build Sound Open Firmware documentation +# +# Usage: +# create parent directory for sof and sof-docs repository (e.g. thesofproject) +# clone sof repository to thesofproject\sof folder +# clone sof-docs repository to thesofproject\sof-docs folder +# build docker image from parent directory .\thesofproject: +# > docker build -t ubuntu-sofdocs -f ./sof-docs/scripts/docker_build/Dockerfile ./ +# run the image container: +# > docker run -d --name sofdocs_container ubuntu-sofdocs sleep infinity +# copy build output from container to host: +# > docker cp sofdocs_container:/home/thesofproject/sof/doc ./sof/ +# > docker cp sofdocs_container:/home/thesofproject/sof-docs/_build ./sof-docs/ +# stop the container: +# docker stop sofdocs_container +# +# Note: The first build can take time to setup ubuntu and install tools, +# but each next one will repeat only copy and build steps. +# + +FROM dokken/ubuntu-22.04 + +# Set image working directory +WORKDIR /home/thesofproject + +RUN apt-get update + +# Install sof-docs build tools +RUN apt-get install -y python3.6 +RUN apt-get install -y doxygen python3-pip python3-wheel make \ + default-jre graphviz cmake ninja-build + +# Copy sof-docs file with dependency tools list +COPY ./sof-docs/scripts/requirements.txt /home/thesofproject/sof-docs/scripts/requirements.txt + +# Install sof-docs requirements tools +RUN pip3 install --user -r /home/thesofproject/sof-docs/scripts/requirements.txt + +# Directly install sphinx to add 'sphinx-build' to the system +RUN apt-get install -y python3-sphinx + +# Copy sof source code from host to image +COPY ./sof/ /home/thesofproject/sof/ + +# Build API documentation from SOF source (Doxygen) +RUN cmake -S sof/doc -B sof/doc -GNinja +RUN ninja -C sof/doc -v doc + +# Copy sof-docs source code from host to image +COPY ./sof-docs/ /home/thesofproject/sof-docs/ + +# Build sof-docs, ignore eventual errors to complete image creation +RUN make -C sof-docs VERBOSE=1 html; exit 0 diff --git a/scripts/docker_build/docker-build.sh b/scripts/docker_build/docker-build.sh new file mode 100644 index 00000000..e16e7507 --- /dev/null +++ b/scripts/docker_build/docker-build.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2023 Intel Corporation. All rights reserved. + +build_docs_only="FALSE" +if [ $# -eq 1 ] && [[ $1 = "docs" ]]; then + build_docs_only="TRUE" + echo "Re-build sof-docs only." +fi + +# Build documentation using docker image +docker build -t ubuntu-sofdocs -f ./sof-docs/scripts/docker_build/Dockerfile ./ + +# Run image container to copy output. +# Add sleep infinity to keep container running. +docker run -d --rm --name sofdocs_container ubuntu-sofdocs sleep infinity + +if [ $build_docs_only = "FALSE" ]; then + echo "Copy SOF Doxygen generated documentation from container to host ./sof/doc/" + docker cp sofdocs_container:/home/thesofproject/sof/doc ./sof/ +fi + +echo "Copy SOF-DOCS generated documentation from container to host ./sof-docs/_build .." +docker cp sofdocs_container:/home/thesofproject/sof-docs/_build ./sof-docs/ + +echo "Stop the sofdocs_container" +docker stop sofdocs_container + +# It is required to prevent stacking of images for each build run +echo "Remove dangling docker images" +docker image prune --force + +echo "Press key to exit..." +read -n 1 k <&1