|
| 1 | +Allow Installation of System Packages |
| 2 | +===================================== |
| 3 | + |
| 4 | +Currently we don't allow executing arbitrary commands in the build process. |
| 5 | +The more common use case is to install extra dependencies. |
| 6 | + |
| 7 | +.. contents:: |
| 8 | + :local: |
| 9 | + :depth: 3 |
| 10 | + |
| 11 | +Current status |
| 12 | +-------------- |
| 13 | + |
| 14 | +There is a workaround when using Sphinx to run arbitrary commands, |
| 15 | +this is executing the commands inside the ``conf.py`` file. |
| 16 | +There isn't a workaround for MkDocs, but this problem is more common in Sphinx, |
| 17 | +since users need to install some extra dependencies in order to use autodoc or build Jupyter Notebooks. |
| 18 | + |
| 19 | +However, installation of some dependencies require root access, |
| 20 | +or are easier to install using ``apt``. |
| 21 | +Most of the CI services allow to use ``apt`` or execute any command with ``sudo``, |
| 22 | +so users are more familiar with that workflow. |
| 23 | + |
| 24 | +Some users use Conda instead of pip to install dependencies in order to avoid these problems, |
| 25 | +but not all pip users are familiar with Conda, or want to migrate to Conda just to use Read the Docs. |
| 26 | + |
| 27 | +Security concerns |
| 28 | +----------------- |
| 29 | + |
| 30 | +Builds are run in a Docker container, |
| 31 | +but the app controlling that container lives in the same server. |
| 32 | +Allowing to execute arbitrary commands with super user privileges may introduce some security issues. |
| 33 | + |
| 34 | +Exposing ``apt install`` |
| 35 | +------------------------ |
| 36 | + |
| 37 | +For the previous reasons we won't allow to execute arbitrary commands with root (yet), |
| 38 | +but instead allow only to install extra packages using ``apt``. |
| 39 | + |
| 40 | +We would expose this through the config file. |
| 41 | +Users will provide a list of packages to install, and under the hook we would run: |
| 42 | + |
| 43 | +- ``apt update -y`` |
| 44 | +- ``apt install -y {packages}`` |
| 45 | + |
| 46 | +These commands will be run before the Python setup step and after the clone step. |
| 47 | + |
| 48 | +.. note:: |
| 49 | + |
| 50 | + All package names must be validated to avoid injection of extra options |
| 51 | + (like ``-v``). |
| 52 | + |
| 53 | +Using ``docker exec`` |
| 54 | +--------------------- |
| 55 | + |
| 56 | +Currently we use ``docker exec`` to execute commands in a running container. |
| 57 | +This command also allows to pass a user which is used to run the commands (#8058_). |
| 58 | +We can run the ``apt`` commands in our current containers using a super user momentarily. |
| 59 | + |
| 60 | +.. _#8058: https://github.com/readthedocs/readthedocs.org/pull/8058 |
| 61 | + |
| 62 | +Config file |
| 63 | +----------- |
| 64 | + |
| 65 | +The config file can add an additional mapping ``build.apt_packages`` to a list of packages to install. |
| 66 | + |
| 67 | +.. code-block:: yaml |
| 68 | +
|
| 69 | + version: 2 |
| 70 | +
|
| 71 | + build: |
| 72 | + apt_packages: |
| 73 | + - cmatrix |
| 74 | + - mysql-server |
| 75 | +
|
| 76 | +.. note:: |
| 77 | + |
| 78 | + Other names that were considered were: |
| 79 | + |
| 80 | + - ``build.packages`` |
| 81 | + - ``build.extra_packages`` |
| 82 | + - ``build.system_packages`` |
| 83 | + |
| 84 | + These were rejected to avoid confusion with existing keys, |
| 85 | + and to be explicit about the type of package. |
| 86 | + |
| 87 | +Possible problems |
| 88 | +----------------- |
| 89 | + |
| 90 | +- Some users may require to pass some additional flags or install from a ppa. |
| 91 | +- Some packages may require some additional setup after installation. |
| 92 | + |
| 93 | +Other possible solutions |
| 94 | +------------------------ |
| 95 | + |
| 96 | +- We can allow to run the containers as root doing something similar to what Travis does: |
| 97 | + They have one tool to convert the config file to a shell script (travis-build_), |
| 98 | + and another that spins a docker container, executes that shell script and streams the logs back (travis-worker_). |
| 99 | + |
| 100 | + .. _travis-build: https://github.com/travis-ci/travis-build |
| 101 | + .. _travis-worker: https://github.com/travis-ci/worker |
| 102 | + |
| 103 | +- A similar solution could be implemented using `AWS Lambda`_. |
| 104 | + |
| 105 | + .. NOTE: Haven't done much research around this, |
| 106 | + but I remember David mentioned this a time ago. |
| 107 | +
|
| 108 | + .. _AWS Lambda: https://aws.amazon.com/lambda/ |
| 109 | + |
| 110 | +This of course would require a large amount of work, |
| 111 | +but may be useful for the future. |
0 commit comments