Integrating ESP-Docs into Your Project
This document describes how to integrate ESP-Docs into your project to continuously build and deploy your documentation to a server, such as Espressif’s server docs.espressif.com (recommended for Espressif software documentation).
While performing the steps in this document, you can always refer to the documentation that has already been deployed to Espressif’s server as examples, such as ESP-IDF Programming Guide, ESP-AT User Guide, esptool.py Documentation, and ESP-Docs User Guide.
The process to integrate ESP-Docs can be broken down into the following steps:
Get Familiar with the Documentation Folder
The contents of the basic documentation folder are described below to provide more details about the folder structure and the function of each file. Your folder might look slightly different, but being familiar with these building blocks will help you better understand the following steps in this document.
_static: contains graphics files, sources of diagrams, attachments not shown directly in the documentation (e.g., schematics) as well as other resources, such as font files.docs_version.js: configures target and version information displayed in HTML layout, such as the target and language selector in the top-left corner of ESP-IDF Programming Guide.periph_timing.json: sample figure in JSON format.
en: English language folder that contains English documents and a build configuration file.conf.py: build configuration file that contains configuration information specific to the English documents, such as the English copyright information.index.rst: English homepage that defines documentation structure with a table of contents tree (toctree). See Defining document structure for more information.subpage.rst: sample subpage ofindex.rst.
zh_CN: the same asenbut for the Simplified Chinese language.conf.py: the same asen/conf.pybut for the Chinese documents.index.rst: the same asen/index.rstbut for the Chinese documents.subpage.rst: the same asen/subpage.rstbut in Chinese.
README.md: introduction to thedocsfolder.build_example.sh: contains the command to simplify building this sample documentation.conf_common.py: contains the build configuration information common to both English and Chinese documents. The contents of this file are imported during the building process for each language to the standard Sphinx configuration fileconf.pylocated in respective language folders (e.g.docs/en,docs/zh_CN). See Sphinx Configuration for more information.requirements.txt: package dependencies and their versions for building documentation, such as ESP-Docs.
Prepare a Documentation Folder
Copy one of the following sample documentation folders to the root directory of your project depending on whether the project needs support for target, version, or building API documentation from header files:
Doc Folder
Target
Version
API Doc
Y
Y
–
Y
Y
Y
–
Y
Y
–
–
Y
Y
–
Y
Rename the folder to
docs.Delete the
build_example.shfile (if there is one).(Optional) Go to
docs/requirements.txtand change the ESP-Docs version as needed. ESP-Docs follows the semantic versioning scheme. For features supported by each release, please see release history.
Update Build Configuration Files
Build configuration files are where you set the variables that are affecting the final documentation output built with ESP-Docs. As mentioned in Get Familiar with the Documentation Folder, there should be two types of configuration files in each project:
conf_common.pyen/conf.pyandzh_CN/conf.py
The configuration files in the sample documentation folder configure how to build the sample documentation instead of your documentation, so you need to reconfigure a few variables for your documentation.
In
conf_common.py, reconfigure some of the following variables based on your needs:
languages: supported languages, such asenandzh_CN. It must be set to at least one language element, namely the current project’s language.
idf_targets: project target used as a URL slug, such asesp32inhttps://docs.espressif.com/projects/esp-idf/en/latest/esp32/. The variable is optional, but you should set either both this variable andidf_targetor neither. For more information aboutidf_target, see Build System Integration .
extensions: extensions that add more functionalities to ESP-Docs, such assphinx_copybuttonandsphinxcontrib.wavedrom.
github_repo: GitHub repository to which the links generated by link_roles.py point.
html_context['github_user']: GitHub user name used by sphinx_idf_theme.
html_context['github_repo']: GitHub repo name used by sphinx_idf_theme.
html_static_path: path to the_staticfolder.
project_slug: short name of the project as a URL slug, such asesp-docs.
versions_url: URL from which to download theversions.jsfile. If it is specified as a relative URL, such as_static/docs_version.js, the file will be downloaded relative to theHTMLroot folder.
pdf_file_prefix: PDF filename prefix used for generating the link to download the PDF together with the target and version name.
In
en/conf.pyandzh_CN/conf.py, reconfigure some of the following variables based on your needs:
project: name of your documentation in HTML, such as ESP-IDF Programming Guide, ESP-AT User Guide.
copyright: copyright statement.
pdf_title: name of your documentation in PDF.
language: language for content autogenerated by ESP-Docs.
Update CI Configuration File
Note
The following descriptions assume you are using Gitlab CI for building documentation and deploying it to www.espressif.com, and will have to be tweaked if you are running something else for CI/CD.
The GitLab CI configuration file, .gitlab-ci.yml, is where you add jobs to enable the automatic and continuous building and deploying of your documentation to the www.espressif.com server.
In the .gitlab-ci.yml of your project, do the steps given below. For examples, please refer to esp-docs/.gitlab-ci.yml and esp-idf/.gitlab/ci/docs.yml.
Build Documentation
In your
.gitlab-ci.yml, add a template that installs the documentation packages indocs/requirements.txtand selects the Docker image. The HTML and PDF build jobs share this template..build_template: stage: build image: $ESP_DOCS_ENV_IMAGE variables: DOCS_DIR: $CI_PROJECT_DIR/docs before_script: - pip install -r docs/requirements.txt
Note
If you define
ESP_DOCS_ENV_IMAGEonce in the top-levelvariablessection of.gitlab-ci.yml, the build jobs and the deploy jobs then shareimage: $ESP_DOCS_ENV_IMAGE. You can reuse the image used by ESP-IDF, such as$CI_REGISTRY/ci/images/idf-v5.5-docs:1. For the latest version of this image, go to Documentation Team Site > Section ESP-Docs User Guide > esp-idf-doc-env image.The following snippet from .gitlab-ci.yml shows that global variable:
8variables: 9 # Versioned esp-idf docs image to use for all document building jobs 10 ESP_DOCS_ENV_IMAGE: "$CI_REGISTRY/ci/images/idf-v5.5-docs:1"
Add the HTML and PDF build jobs to your
.gitlab-ci.yml. The snippets below are from .gitlab-ci.yml.96build_esp_docs_html: 97 extends: 98 - .build_template 99 variables: 100 DOCS_DIR: $CI_PROJECT_DIR/docs 101 artifacts: 102 when: always 103 paths: 104 - $DOCS_DIR/_build/*/*/html/* 105 - $DOCS_DIR/_build/*/*/*.txt 106 expire_in: 4 days 107 script: 108 - cd $DOCS_DIR 109 - build-docs --skip-reqs-check -l $DOCLANG 110 - echo "ESP-Docs documentation preview available at $CI_JOB_URL/artifacts/file/docs/_build/$DOCLANG/generic/html/index.html" 111 parallel: 112 matrix: 113 - DOCLANG: ["en"] 114 115build_esp_docs_pdf: 116 extends: 117 - .build_template 118 variables: 119 DOCS_DIR: $CI_PROJECT_DIR/docs 120 artifacts: 121 when: always 122 paths: 123 - $DOCS_DIR/_build/*/*/latex/* 124 - $DOCS_DIR/_build/*/*/*.txt 125 expire_in: 4 days 126 script: 127 - cd $DOCS_DIR 128 - build-docs --skip-reqs-check -l $DOCLANG -bs latex 129 parallel: 130 matrix: 131 - DOCLANG: ["en"]
Change these values in your
.gitlab-ci.ymlwhen your project differs from the snippets above:DOCS_DIR: the directory the job enters before it runsbuild-docs. The snippets above set$CI_PROJECT_DIR/docs.build-docsuses the directory it is run from. It does not readDOCS_DIR.ESP_DOCS_LATEST_BRANCH_NAME: the branch to be built and published aslatest. If not configured, the default value ismaster. Set this variable when the branch published aslatesthas another name, such asmain.
Deploy Documentation
In your
.gitlab-ci.yml, add a deploy template. The template uses the sameESP_DOCS_ENV_IMAGEfrom the top-levelvariablessection, so the deploy jobs use the same image as the build jobs..deploy_docs_template: stage: deploy image: $ESP_DOCS_ENV_IMAGE needs: - build_esp_docs_html - build_esp_docs_pdf script: - add_doc_server_ssh_keys $DOCS_DEPLOY_PRIVATEKEY $DOCS_DEPLOY_SERVER $DOCS_DEPLOY_SERVER_USER - export GIT_VER=$(git describe --abbrev=10 --always) - pip install -r ${CI_PROJECT_DIR}/docs/requirements.txt - deploy-docs
Add jobs to deploy docs to the preview server when the MR is open, and to the production server when the MR is merged.
deploy_docs_preview: extends: - .deploy_docs_template rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' changes: - "docs/**/*" variables: TYPE: "preview" DOCS_BUILD_DIR: "${CI_PROJECT_DIR}/docs/_build/" DOCS_DEPLOY_PRIVATEKEY: "$DOCS_PREVIEW_DEPLOY_KEY" DOCS_DEPLOY_SERVER: "$DOCS_PREVIEW_SERVER" DOCS_DEPLOY_SERVER_USER: "$DOCS_PREVIEW_SERVER_USER" DOCS_DEPLOY_PATH: "$DOCS_PREVIEW_PATH" DOCS_DEPLOY_URL_BASE: "$DOCS_PREVIEW_SERVER_URL/your-project-name" deploy_docs_production: extends: - .deploy_docs_template rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH changes: - "docs/**/*" variables: TYPE: "production" DOCS_BUILD_DIR: "${CI_PROJECT_DIR}/docs/_build/" DOCS_DEPLOY_PRIVATEKEY: "$DOCS_PROD_DEPLOY_KEY" DOCS_DEPLOY_SERVER: "$DOCS_PROD_SERVER" DOCS_DEPLOY_SERVER_USER: "$DOCS_PROD_SERVER_USER" DOCS_DEPLOY_PATH: "$DOCS_PROD_PATH" DOCS_DEPLOY_URL_BASE: "https://docs.espressif.com/projects/your-project-name"
Note
If your project is hosted on GitLab and the updates made in GitLab later are synchronized to GitHub, run the deploy job after the job that synchronizes your repository to GitHub. If synchronization to GitHub fails, links in the documentation that refer to the GitHub project do not work.
Change these values in your
.gitlab-ci.ymlwhen your project differs from the snippets above:DOCS_BUILD_DIR: directory that contains the built HTML and PDF files. The snippets above set${CI_PROJECT_DIR}/docs/_build/.DOCS_DEPLOY_URL_BASE: base URL printed after deployment. The preview job uses$DOCS_PREVIEW_SERVER_URL/<project-path>. The production job useshttps://docs.espressif.com/projects/<project-name>.DEPLOY_STABLE: optionally set this to1on the production job when a stable release should also be published understable. For example of a stable release, see https://docs.espressif.com/projects/esp-idf/en/stable/esp32/index.html.
Add the SSH private key, server host, SSH user, remote directory, and preview URL as CI/CD variables:
Find out who the server’s admin is. To know who this person is, go to Documentation Team Site > Section ESP-Docs User Guide > Deploying documentation to docs.espressif.com.
Ask the admin to create an SSH key for you and a directory for your documentation on the server.
Go to your project’s Settings > CI/CD and expand the Variables section. Select Add variable and fill in the details for your variables. For more information on how to add a variable to a project, see the GitLab documentation.
deploy_docs_previewreads these variables:DOCS_PREVIEW_DEPLOY_KEY: SSH private key. The job assigns it toDOCS_DEPLOY_PRIVATEKEY.DOCS_PREVIEW_SERVER: server host. The job assigns it toDOCS_DEPLOY_SERVER.DOCS_PREVIEW_SERVER_USER: SSH user. The job assigns it toDOCS_DEPLOY_SERVER_USER.DOCS_PREVIEW_PATH: directory on the server. The job assigns it toDOCS_DEPLOY_PATH.DOCS_PREVIEW_SERVER_URL: base URL of the preview server. The job uses it inDOCS_DEPLOY_URL_BASE.
deploy_docs_productionreads these variables:DOCS_PROD_DEPLOY_KEY: SSH private key. The job assigns it toDOCS_DEPLOY_PRIVATEKEY.DOCS_PROD_SERVER: server host, such asdocs.espressif.com. The job assigns it toDOCS_DEPLOY_SERVER.DOCS_PROD_SERVER_USER: SSH user. The job assigns it toDOCS_DEPLOY_SERVER_USER.DOCS_PROD_PATH: directory on the server. The job assigns it toDOCS_DEPLOY_PATH.
What’s Next?
Push your changes to GitLab and check if the pipeline passes.
If yes, you can check the Artifacts to see what the built sample documentation looks like.
Now it is time to put your reST source files into the respective language folder and have them built and deployed!