understand-autobuilder.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. *******************************************
  3. Understanding the Yocto Project Autobuilder
  4. *******************************************
  5. Execution Flow within the Autobuilder
  6. =====================================
  7. The "a-full" and "a-quick" targets are the usual entry points into the
  8. Autobuilder and it makes sense to follow the process through the system
  9. starting there. This is best visualized from the :yocto_ab:`Autobuilder
  10. Console view </valkyrie/#/console>`.
  11. Each item along the top of that view represents some "target build" and
  12. these targets are all run in parallel. The 'full' build will trigger the
  13. majority of them, the "quick" build will trigger some subset of them.
  14. The Autobuilder effectively runs whichever configuration is defined for
  15. each of those targets on a separate buildbot worker. To understand the
  16. configuration, you need to look at the entry on ``config.json`` file
  17. within the :yocto_git:`yocto-autobuilder-helper </yocto-autobuilder-helper>`
  18. repository. The targets are defined in the ``overrides`` section, a quick
  19. example could be ``qemux86-64`` which looks like::
  20. "qemux86-64" : {
  21. "MACHINE" : "qemux86-64",
  22. "TEMPLATE" : "arch-qemu",
  23. "step1" : {
  24. "extravars" : [
  25. "IMAGE_FSTYPES:append = ' wic wic.bmap'"
  26. ]
  27. }
  28. },
  29. And to expand that, you need the ``arch-qemu`` entry from
  30. the ``templates`` section, which looks like::
  31. "arch-qemu" : {
  32. "BUILDINFO" : true,
  33. "BUILDHISTORY" : true,
  34. "step1" : {
  35. "BBTARGETS" : "core-image-sato core-image-sato-dev core-image-sato-sdk core-image-minimal core-image-minimal-dev core-image-sato:do_populate_sdk",
  36. "SANITYTARGETS" : "core-image-minimal:do_testimage core-image-sato:do_testimage core-image-sato-sdk:do_testimage core-image-sato:do_testsdk"
  37. },
  38. "step2" : {
  39. "SDKMACHINE" : "x86_64",
  40. "BBTARGETS" : "core-image-sato:do_populate_sdk core-image-minimal:do_populate_sdk_ext core-image-sato:do_populate_sdk_ext",
  41. "SANITYTARGETS" : "core-image-sato:do_testsdk core-image-minimal:do_testsdkext core-image-sato:do_testsdkext"
  42. },
  43. "step3" : {
  44. "BUILDHISTORY" : false,
  45. "EXTRACMDS" : ["${SCRIPTSDIR}/checkvnc; DISPLAY=:1 oe-selftest ${HELPERSTMACHTARGS} -j 15"],
  46. "ADDLAYER" : ["${BUILDDIR}/../meta-selftest"]
  47. }
  48. },
  49. Combining these two entries you can see that ``qemux86-64`` is a three step
  50. build where ``bitbake BBTARGETS`` would be run, then ``bitbake SANITYTARGETS``
  51. for each step; all for ``MACHINE="qemux86-64"`` but with differing
  52. :term:`SDKMACHINE` settings. In step 1, an extra variable is added to the
  53. ``auto.conf`` file to enable wic image generation.
  54. While not every detail of this is covered here, you can see how the
  55. template mechanism allows quite complex configurations to be built up
  56. yet allows duplication and repetition to be kept to a minimum.
  57. The different build targets are designed to allow for parallelization,
  58. so different machines are usually built in parallel, operations using
  59. the same machine and metadata are built sequentially, with the aim of
  60. trying to optimize build efficiency as much as possible.
  61. The ``config.json`` file is processed by the scripts in the Helper
  62. repository in the ``scripts`` directory. The following section details
  63. how this works.
  64. Autobuilder Target Execution Overview
  65. =====================================
  66. For each given target in a build, the Autobuilder executes several
  67. steps. These are configured in ``yocto-autobuilder2/builders.py`` and
  68. roughly consist of:
  69. #. *Run clobberdir*.
  70. This cleans out any previous build. Old builds are left around to
  71. allow easier debugging of failed builds. For additional information,
  72. see :ref:`test-manual/understand-autobuilder:clobberdir`.
  73. #. *Obtain yocto-autobuilder-helper*
  74. This step clones the :yocto_git:`yocto-autobuilder-helper </yocto-autobuilder-helper>`
  75. git repository. This is necessary to avoid the requirement to maintain all
  76. the release or project-specific code within Buildbot. The branch chosen
  77. matches the release being built so we can support older releases and
  78. still make changes in newer ones.
  79. #. *Write layerinfo.json*
  80. This transfers data in the Buildbot UI when the build was configured
  81. to the Helper.
  82. #. *Call scripts/shared-repo-unpack*
  83. This is a call into the Helper scripts to set up a checkout of all
  84. the pieces this build might need. It might clone the BitBake
  85. repository and the OpenEmbedded-Core repository. It may clone the
  86. Poky repository, as well as additional layers. It will use the data
  87. from the ``layerinfo.json`` file to help understand the
  88. configuration. It will also use a local cache of repositories to
  89. speed up the clone checkouts. For additional information, see
  90. :ref:`test-manual/understand-autobuilder:Autobuilder Clone Cache`.
  91. This step has two possible modes of operation. If the build is part
  92. of a parent build, it's possible that all the repositories needed may
  93. already be available, ready in a pre-prepared directory. An "a-quick"
  94. or "a-full" build would prepare this before starting the other
  95. sub-target builds. This is done for two reasons:
  96. - the upstream may change during a build, for example, from a forced
  97. push and this ensures we have matching content for the whole build
  98. - if 15 Workers all tried to pull the same data from the same repos,
  99. we can hit resource limits on upstream servers as they can think
  100. they are under some kind of network attack
  101. This pre-prepared directory is shared among the Workers over NFS. If
  102. the build is an individual build and there is no "shared" directory
  103. available, it would clone from the cache and the upstreams as
  104. necessary. This is considered the fallback mode.
  105. #. *Call scripts/run-config*
  106. This is another call into the Helper scripts where it's expected that
  107. the main functionality of this target will be executed.
  108. Autobuilder Technology
  109. ======================
  110. The Autobuilder has Yocto Project-specific functionality to allow builds
  111. to operate with increased efficiency and speed.
  112. clobberdir
  113. ----------
  114. When deleting files, the Autobuilder uses ``clobberdir``, which is a
  115. special script that moves files to a special location, rather than
  116. deleting them. Files in this location are deleted by an ``rm`` command,
  117. which is run under ``ionice -c 3``. For example, the deletion only
  118. happens when there is idle IO capacity on the Worker. The Autobuilder
  119. Worker Janitor runs this deletion. See :ref:`test-manual/understand-autobuilder:Autobuilder Worker Janitor`.
  120. Autobuilder Clone Cache
  121. -----------------------
  122. Cloning repositories from scratch each time they are required was slow
  123. on the Autobuilder. We therefore have a stash of commonly used
  124. repositories pre-cloned on the Workers. Data is fetched from these
  125. during clones first, then "topped up" with later revisions from any
  126. upstream when necessary. The cache is maintained by the Autobuilder
  127. Worker Janitor. See :ref:`test-manual/understand-autobuilder:Autobuilder Worker Janitor`.
  128. Autobuilder Worker Janitor
  129. --------------------------
  130. This is a process running on each Worker that performs two basic
  131. operations, including background file deletion at IO idle (see
  132. "Run clobberdir" in :ref:`test-manual/understand-autobuilder:Autobuilder Target Execution Overview`)
  133. and maintenance of a cache of cloned repositories to improve the speed
  134. the system can checkout repositories.
  135. Shared DL_DIR
  136. -------------
  137. The Workers are all connected over NFS which allows :term:`DL_DIR` to be shared
  138. between them. This reduces network accesses from the system and allows
  139. the build to be sped up. The usage of the directory within the build system
  140. is designed to be able to be shared over NFS.
  141. Shared SSTATE_DIR
  142. -----------------
  143. The Workers are all connected over NFS which allows the ``sstate``
  144. directory to be shared between them. This means once a Worker has built
  145. an artifact, all the others can benefit from it. The usage of the directory
  146. within the build system is designed for sharing over NFS.
  147. Resulttool
  148. ----------
  149. All of the different tests run as part of the build generate output into
  150. ``testresults.json`` files. This allows us to determine which tests ran
  151. in a given build and their status. Additional information, such as
  152. failure logs or the time taken to run the tests, may also be included.
  153. Resulttool is part of OpenEmbedded-Core and is used to manipulate these
  154. JSON results files. It has the ability to merge files together, display
  155. reports of the test results and compare different result files.
  156. For details, see :yocto_wiki:`/Resulttool`.
  157. run-config Target Execution
  158. ===========================
  159. The ``scripts/run-config`` execution is where most of the work within
  160. the Autobuilder happens. It runs through a number of steps; the first
  161. are general setup steps that are run once and include:
  162. #. Set up any :term:`buildtools` tarball if configured.
  163. #. Call ``buildhistory-init`` if :ref:`ref-classes-buildhistory` is configured.
  164. For each step that is configured in ``config.json``, it will perform the
  165. following:
  166. #. Add any layers that are specified using the
  167. ``bitbake-layers add-layer`` command (logging as stepXa)
  168. #. Call the ``scripts/setup-config`` script to generate the necessary
  169. ``auto.conf`` configuration file for the build
  170. #. Run the ``bitbake BBTARGETS`` command (logging as stepXb)
  171. #. Run the ``bitbake SANITYTARGETS`` command (logging as stepXc)
  172. #. Run the ``EXTRACMDS`` command, which are run within the BitBake build
  173. environment (logging as stepXd)
  174. #. Run the ``EXTRAPLAINCMDS`` command(s), which are run outside the
  175. BitBake build environment (logging as stepXd)
  176. #. Remove any layers added in step
  177. 1 using the ``bitbake-layers remove-layer`` command (logging as stepXa)
  178. Once the execution steps above complete, ``run-config`` executes a set
  179. of post-build steps, including:
  180. #. Call ``scripts/publish-artifacts`` to collect any output which is to
  181. be saved from the build.
  182. #. Call ``scripts/collect-results`` to collect any test results to be
  183. saved from the build.
  184. #. Call ``scripts/upload-error-reports`` to send any error reports
  185. generated to the remote server.
  186. #. Cleanup the :term:`Build Directory` using
  187. :ref:`test-manual/understand-autobuilder:clobberdir` if the build was successful,
  188. else rename it to "build-renamed" for potential future debugging.
  189. Deploying Yocto Autobuilder
  190. ===========================
  191. The most up to date information about how to setup and deploy your own
  192. Autobuilder can be found in :yocto_git:`README.md </yocto-autobuilder2/tree/README.md>`
  193. in the :yocto_git:`yocto-autobuilder2 </yocto-autobuilder2>` repository.
  194. We hope that people can use the :yocto_git:`yocto-autobuilder2 </yocto-autobuilder2>`
  195. code directly but it is inevitable that users will end up needing to heavily
  196. customize the :yocto_git:`yocto-autobuilder-helper </yocto-autobuilder-helper>`
  197. repository, particularly the ``config.json`` file as they will want to define
  198. their own test matrix.
  199. The Autobuilder supports two customization options:
  200. - variable substitution
  201. - overlaying configuration files
  202. The standard ``config.json`` minimally attempts to allow substitution of
  203. the paths. The Helper script repository includes a
  204. ``local-example.json`` file to show how you could override these from a
  205. separate configuration file. Pass the following into the environment of
  206. the Autobuilder::
  207. $ ABHELPER_JSON="config.json local-example.json"
  208. As another example, you could also pass the following into the
  209. environment::
  210. $ ABHELPER_JSON="config.json /some/location/local.json"
  211. One issue users often run into is validation of the ``config.json`` files. A
  212. tip for minimizing issues from invalid JSON files is to use a Git
  213. ``pre-commit-hook.sh`` script to verify the JSON file before committing
  214. it. Create a symbolic link as follows::
  215. $ ln -s ../../scripts/pre-commit-hook.sh .git/hooks/pre-commit