makefile.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. .. _makefile:
  2. ========
  3. Makefile
  4. ========
  5. .. _gnu-make: https://www.gnu.org/software/make/manual/make.html#Introduction
  6. .. sidebar:: build environment
  7. Before looking deeper at the targets, first read about :ref:`make
  8. install`.
  9. To install system requirements follow :ref:`buildhosts`.
  10. All relevant build tasks are implemented in :origin:`manage` and for CI or
  11. IDE integration a small ``Makefile`` wrapper is available. If you are not
  12. familiar with Makefiles, we recommend to read gnu-make_ introduction.
  13. The usage is simple, just type ``make {target-name}`` to *build* a target.
  14. Calling the ``help`` target gives a first overview (``make help``):
  15. .. program-output:: bash -c "cd ..; make --no-print-directory help"
  16. .. contents:: Contents
  17. :depth: 2
  18. :local:
  19. :backlinks: entry
  20. .. _make install:
  21. Python environment (``make install``)
  22. =====================================
  23. .. sidebar:: activate environment
  24. ``source ./local/py3/bin/activate``
  25. We do no longer need to build up the virtualenv manually. Jump into your git
  26. working tree and release a ``make install`` to get a virtualenv with a
  27. *developer install* of SearXNG (:origin:`setup.py`). ::
  28. $ cd ~/searxng-clone
  29. $ make install
  30. PYENV [virtualenv] installing ./requirements*.txt into local/py3
  31. ...
  32. PYENV OK
  33. PYENV [install] pip install -e 'searx[test]'
  34. ...
  35. Successfully installed argparse-1.4.0 searx
  36. BUILDENV INFO:searx:load the default settings from ./searx/settings.yml
  37. BUILDENV INFO:searx:Initialisation done
  38. BUILDENV build utils/brand.env
  39. If you release ``make install`` multiple times the installation will only
  40. rebuild if the sha256 sum of the *requirement files* fails. With other words:
  41. the check fails if you edit the requirements listed in
  42. :origin:`requirements-dev.txt` and :origin:`requirements.txt`). ::
  43. $ make install
  44. PYENV OK
  45. PYENV [virtualenv] requirements.sha256 failed
  46. [virtualenv] - 6cea6eb6def9e14a18bf32f8a3e... ./requirements-dev.txt
  47. [virtualenv] - 471efef6c73558e391c3adb35f4... ./requirements.txt
  48. ...
  49. PYENV [virtualenv] installing ./requirements*.txt into local/py3
  50. ...
  51. PYENV OK
  52. PYENV [install] pip install -e 'searx[test]'
  53. ...
  54. Successfully installed argparse-1.4.0 searx
  55. BUILDENV INFO:searx:load the default settings from ./searx/settings.yml
  56. BUILDENV INFO:searx:Initialisation done
  57. BUILDENV build utils/brand.env
  58. .. sidebar:: drop environment
  59. To get rid of the existing environment before re-build use :ref:`clean target
  60. <make clean>` first.
  61. If you think, something goes wrong with your ./local environment or you change
  62. the :origin:`setup.py` file, you have to call :ref:`make clean`.
  63. .. _make buildenv:
  64. ``make buildenv``
  65. =================
  66. Rebuild instance's environment with the modified settings from the
  67. :ref:`settings brand` and :ref:`settings server` section of your
  68. :ref:`settings.yml <settings location>`.
  69. What is the :origin:`utils/brand.env` needed for and why do you need to rebuild
  70. it if necessary?
  71. Short answer: :ref:`installation and maintenance <searxng maintenance>`
  72. scripts are running outside of instance's runtime environment and need some
  73. values defined in the runtime environment.
  74. All the SearXNG setups are centralized in the :ref:`settings.yml` file. This
  75. setup is available as long we are in a *installed instance*. E.g. the
  76. *installed instance* on the server or the *installed developer instance* at
  77. ``./local`` (the later one is created by a :ref:`make install <make install>` or
  78. :ref:`make run <make run>`).
  79. Tasks running outside of an *installed instance*, especially :ref:`installation
  80. and maintenance <searxng maintenance>` tasks running at (pre-) installation time
  81. do not have access to the SearXNG setup (from a *installed instance*). Those
  82. tasks need a *build environment*.
  83. The ``make buildenv`` target will update the *build environment* in:
  84. - :origin:`utils/brand.env`
  85. Tasks running outside of an *installed instance*, need the following settings
  86. from the YAML configuration:
  87. - ``SEARXNG_URL`` from :ref:`server.base_url <settings server>` (aka
  88. ``PUBLIC_URL``)
  89. - ``SEARXNG_BIND_ADDRESS`` from :ref:`server.bind_address <settings server>`
  90. - ``SEARXNG_PORT`` from :ref:`server.port <settings server>`
  91. The ``GIT_URL`` and ``GIT_BRANCH`` in the origin:`utils/brand.env` file, are
  92. readed from the git VCS and the branch that is checked out when ``make
  93. buildenv`` command runs.
  94. .. _brand:
  95. **I would like to create my own brand, how should I proceed?**
  96. Create a remote branch (``example.org``), checkout the remote branch (on your
  97. local developer desktop) and in the :origin:`searx/settings.yml` file in the
  98. :ref:`settings server` section set ``base_url``. Run ``make buildenv`` and
  99. create a commit for your brand.
  100. On your server you clone the branch (``example.org``) into your HOME folder
  101. ``~`` from where you run the :ref:`installation <installation>` and
  102. :ref:`maintenance <searxng maintenance>` task.
  103. To upgrade you brand, rebase on SearXNG's master branch (on your local
  104. developer desktop), force push it to your remote branch. Go to your server, do
  105. a force pull and run :ref:`sudo -H ./utils/searxng.sh instance update <update
  106. searxng>`.
  107. .. _make node.env:
  108. Node.js environment (``make node.env``)
  109. =======================================
  110. .. _Node.js: https://nodejs.org/
  111. .. _nvm: https://github.com/nvm-sh
  112. .. _npm: https://www.npmjs.com/
  113. .. jinja:: searx
  114. Node.js_ version {{version.node}} or higher is required to build the themes.
  115. If the requirement is not met, the build chain uses nvm_ (Node Version
  116. Manager) to install latest LTS of Node.js_ locally: there is no need to
  117. install nvm_ or npm_ on your system.
  118. Use ``make nvm.status`` to get the current status of you Node.js_ and nvm_ setup.
  119. Here is the output you will typically get on a Ubuntu 20.04 system which serves
  120. only a `no longer active <https://nodejs.org/en/about/releases/>`_ Release
  121. `Node.js v10.19.0 <https://packages.ubuntu.com/focal/nodejs>`_.
  122. ::
  123. $ make nvm.status
  124. INFO: Node.js is installed at /usr/bin/node
  125. INFO: Node.js is version v10.19.0
  126. WARN: minimal Node.js version is 16.13.0
  127. INFO: npm is installed at /usr/bin/npm
  128. INFO: npm is version 6.14.4
  129. WARN: NVM is not installed
  130. INFO: to install NVM and Node.js (LTS) use: manage nvm install --lts
  131. To install you can also use :ref:`make nvm.nodejs`
  132. .. _make nvm.nodejs:
  133. ``make nvm.nodejs``
  134. ===================
  135. Install latest Node.js_ LTS locally (uses nvm_)::
  136. $ make nvm.nodejs
  137. INFO: install (update) NVM at /share/searxng/.nvm
  138. INFO: clone: https://github.com/nvm-sh/nvm.git
  139. ...
  140. Downloading and installing node v16.13.0...
  141. ...
  142. INFO: Node.js is installed at searxng/.nvm/versions/node/v16.13.0/bin/node
  143. INFO: Node.js is version v16.13.0
  144. INFO: npm is installed at searxng/.nvm/versions/node/v16.13.0/bin/npm
  145. INFO: npm is version 8.1.0
  146. INFO: NVM is installed at searxng/.nvm
  147. .. _make run:
  148. ``make run``
  149. ============
  150. To get up a running a developer instance simply call ``make run``. This enables
  151. *debug* option in :origin:`searx/settings.yml`, starts a ``./searx/webapp.py``
  152. instance and opens the URL in your favorite WEB browser (:man:`xdg-open`)::
  153. $ make run
  154. Changes to theme's HTML templates (jinja2) are instant. Changes to the CSS & JS
  155. sources of the theme need to be rebuild. You can do that by running::
  156. $ make themes.all
  157. Alternatively to ``themes.all`` you can run *live builds* of the theme you are
  158. modify::
  159. $ LIVE_THEME=simple make run
  160. .. _make clean:
  161. ``make clean``
  162. ==============
  163. Drops all intermediate files, all builds, but keep sources untouched. Before
  164. calling ``make clean`` stop all processes using the :ref:`make install` or
  165. :ref:`make node.env`. ::
  166. $ make clean
  167. CLEAN pyenv
  168. PYENV [virtualenv] drop local/py3
  169. CLEAN docs -- build/docs dist/docs
  170. CLEAN themes -- locally installed npm dependencies
  171. ...
  172. CLEAN test stuff
  173. CLEAN common files
  174. .. _make docs:
  175. ``make docs docs.autobuild docs.clean``
  176. =======================================
  177. We describe the usage of the ``doc.*`` targets in the :ref:`How to contribute /
  178. Documentation <contrib docs>` section. If you want to edit the documentation
  179. read our :ref:`make docs.live` section. If you are working in your own brand,
  180. adjust your :ref:`settings global`.
  181. .. _make docs.gh-pages:
  182. ``make docs.gh-pages``
  183. ======================
  184. To deploy on github.io first adjust your :ref:`settings global`. For any
  185. further read :ref:`deploy on github.io`.
  186. .. _make test:
  187. ``make test``
  188. =============
  189. Runs a series of tests: :ref:`make test.pylint`, ``test.pep8``, ``test.unit``
  190. and ``test.robot``. You can run tests selective, e.g.::
  191. $ make test.pep8 test.unit test.sh
  192. TEST test.pep8 OK
  193. ...
  194. TEST test.unit OK
  195. ...
  196. TEST test.sh OK
  197. .. _make test.shell:
  198. ``make test.shell``
  199. ===================
  200. :ref:`sh lint` / if you have changed some bash scripting run this test before
  201. commit.
  202. .. _make test.pylint:
  203. ``make test.pylint``
  204. ====================
  205. .. _Pylint: https://www.pylint.org/
  206. Pylint_ is known as one of the best source-code, bug and quality checker for the
  207. Python programming language. The pylint profile used in the SearXNG project is
  208. found in project's root folder :origin:`.pylintrc`.
  209. .. _make search.checker:
  210. ``search.checker.{engine name}``
  211. ================================
  212. To check all engines::
  213. make search.checker
  214. To check a engine with whitespace in the name like *google news* replace space
  215. by underline::
  216. make search.checker.google_news
  217. To see HTTP requests and more use SEARXNG_DEBUG::
  218. make SEARXNG_DEBUG=1 search.checker.google_news
  219. .. _3xx: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_redirection
  220. To filter out HTTP redirects (3xx_)::
  221. make SEARXNG_DEBUG=1 search.checker.google_news | grep -A1 "HTTP/1.1\" 3[0-9][0-9]"
  222. ...
  223. Engine google news Checking
  224. https://news.google.com:443 "GET /search?q=life&hl=en&lr=lang_en&ie=utf8&oe=utf8&ceid=US%3Aen&gl=US HTTP/1.1" 302 0
  225. https://news.google.com:443 "GET /search?q=life&hl=en-US&lr=lang_en&ie=utf8&oe=utf8&ceid=US:en&gl=US HTTP/1.1" 200 None
  226. --
  227. https://news.google.com:443 "GET /search?q=computer&hl=en&lr=lang_en&ie=utf8&oe=utf8&ceid=US%3Aen&gl=US HTTP/1.1" 302 0
  228. https://news.google.com:443 "GET /search?q=computer&hl=en-US&lr=lang_en&ie=utf8&oe=utf8&ceid=US:en&gl=US HTTP/1.1" 200 None
  229. --