understand-autobuilder.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 Autobuilder Console
  10. view (:yocto_ab:`/typhoon/#/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-autobuilder-helper`` repository. The targets are
  18. defined in the ‘overrides' section, a quick example could be qemux86-64
  19. 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 build where the
  50. ``bitbake BBTARGETS`` would be run, then ``bitbake SANITYTARGETS`` for each step; all for
  51. ``MACHINE="qemx86-64"`` but with differing SDKMACHINE settings. In step
  52. 1 an extra variable is added to the ``auto.conf`` file to enable wic
  53. 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-autobuilder-helper`` git repository.
  75. This is necessary to prevent the requirement to maintain all the
  76. 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 :ref:`test-manual/understand-autobuilder:Autobuilder Target Execution Overview`: Run clobberdir) and
  132. maintenance of a cache of cloned repositories to improve the speed
  133. the system can checkout repositories.
  134. Shared DL_DIR
  135. -------------
  136. The Workers are all connected over NFS which allows DL_DIR to be shared
  137. between them. This reduces network accesses from the system and allows
  138. the build to be sped up. Usage of the directory within the build system
  139. is designed to be able to be shared over NFS.
  140. Shared SSTATE_DIR
  141. -----------------
  142. The Workers are all connected over NFS which allows the ``sstate``
  143. directory to be shared between them. This means once a Worker has built
  144. an artifact, all the others can benefit from it. Usage of the directory
  145. within the directory is designed for sharing over NFS.
  146. Resulttool
  147. ----------
  148. All of the different tests run as part of the build generate output into
  149. ``testresults.json`` files. This allows us to determine which tests ran
  150. in a given build and their status. Additional information, such as
  151. failure logs or the time taken to run the tests, may also be included.
  152. Resulttool is part of OpenEmbedded-Core and is used to manipulate these
  153. json results files. It has the ability to merge files together, display
  154. reports of the test results and compare different result files.
  155. For details, see :yocto_wiki:`/Resulttool`.
  156. run-config Target Execution
  157. ===========================
  158. The ``scripts/run-config`` execution is where most of the work within
  159. the Autobuilder happens. It runs through a number of steps; the first
  160. are general setup steps that are run once and include:
  161. #. Set up any ``buildtools-tarball`` if configured.
  162. #. Call "buildhistory-init" if buildhistory is configured.
  163. For each step that is configured in ``config.json``, it will perform the
  164. following:
  165. #. Add any layers that are specified using the
  166. ``bitbake-layers add-layer`` command (logging as stepXa)
  167. #. Call the ``scripts/setup-config`` script to generate the necessary
  168. ``auto.conf`` configuration file for the build
  169. #. Run the ``bitbake BBTARGETS`` command (logging as stepXb)
  170. #. Run the ``bitbake SANITYTARGETS`` command (logging as stepXc)
  171. #. Run the ``EXTRACMDS`` command, which are run within the BitBake build
  172. environment (logging as stepXd)
  173. #. Run the ``EXTRAPLAINCMDS`` command(s), which are run outside the
  174. BitBake build environment (logging as stepXd)
  175. #. Remove any layers added in step
  176. 1 using the ``bitbake-layers remove-layer`` command (logging as stepXa)
  177. Once the execution steps above complete, ``run-config`` executes a set
  178. of post-build steps, including:
  179. #. Call ``scripts/publish-artifacts`` to collect any output which is to
  180. be saved from the build.
  181. #. Call ``scripts/collect-results`` to collect any test results to be
  182. saved from the build.
  183. #. Call ``scripts/upload-error-reports`` to send any error reports
  184. generated to the remote server.
  185. #. Cleanup the build directory using
  186. :ref:`test-manual/understand-autobuilder:clobberdir` if the build was successful,
  187. else rename it to "build-renamed" for potential future debugging.
  188. Deploying Yocto Autobuilder
  189. ===========================
  190. The most up to date information about how to setup and deploy your own
  191. Autobuilder can be found in README.md in the ``yocto-autobuilder2``
  192. repository.
  193. We hope that people can use the ``yocto-autobuilder2`` code directly but
  194. it is inevitable that users will end up needing to heavily customise the
  195. ``yocto-autobuilder-helper`` repository, particularly the
  196. ``config.json`` file as they will want to define their own test matrix.
  197. The Autobuilder supports wo customization options:
  198. - variable substitution
  199. - overlaying configuration files
  200. The standard ``config.json`` minimally attempts to allow substitution of
  201. the paths. The Helper script repository includes a
  202. ``local-example.json`` file to show how you could override these from a
  203. separate configuration file. Pass the following into the environment of
  204. the Autobuilder::
  205. $ ABHELPER_JSON="config.json local-example.json"
  206. As another example, you could also pass the following into the
  207. environment::
  208. $ ABHELPER_JSON="config.json /some/location/local.json"
  209. One issue users often run into is validation of the ``config.json`` files. A
  210. tip for minimizing issues from invalid json files is to use a Git
  211. ``pre-commit-hook.sh`` script to verify the JSON file before committing
  212. it. Create a symbolic link as follows::
  213. $ ln -s ../../scripts/pre-commit-hook.sh .git/hooks/pre-commit