Developing in Linux containers ¶
In PR #1803 we added a lot of scripts to Searx’s boilerplate. In this blog post I will show you, how you can make use of them in distributed and heterogeneous development cycles (TL;DR; jump to the Abstract).
Normally in our development cycle, we edit the sources and run some test and/or
builds by using
make before we commit. This cycle is simple and perfect but
might fail in some aspects we should not overlook.
The environment in which we run all our development processes matters!
The Makefile Targets and the Python environment encapsulate a lot for us, but they do not have access to all prerequisites. For example, there may have dependencies on packages that are installed on the developer’s desktop, but usually are not preinstalled on a server or client system. Another examples are; settings have been made to the software on the developer’s host that would never be set on a production system.
Linux Containers (LXC) are isolate environments and not to mix up on developer’s all the prerequisites of all the projects he contribute to, is always a good choice.
The scripts from PR #1803 can divide in those to install and maintain software:
and the script utils/lxc.sh, with we can scale our installation, maintenance or even development tasks over a stack of containers, what we call: Searx’s lxc suite.
Before you can start with containers, you need to install and initiate LXD once:
And you need to clone from origin or if you have your own fork, clone from your fork:
The searx suite consists of several images, see
LXC_SUITE=(... near by git://utils/lxc-searx.env#L19. For this blog post
we exercise on a archlinux image. The container of this image is named
searx-archlinux. Lets build the container, but be sure that this container
does not already exists, so first lets remove possible old one:
In this container we install all services including searx, morty & filtron in once:
To proxy HTTP from filtron and morty in the container to the outside of the container, install nginx into the container. Once for the bot blocker filtron:
and once for the content sanitizer (content proxy morty):
On your system, the IP of your
searx-archlinux container differs from
http://10.174.184.156/searx, just open the URL reported in your installation
protocol in your WEB browser from the desktop to test the instance from outside
of the container.
In such a searx suite admins can maintain and access the debug log of the different services quite easy.
Usually you open a root-bash using
sudo -H bash. In case of LXC containers
open the root-bash in the container using
[root@searx-archlinux ...] signals, that you are the root user in
the searx-container. To debug the running searx instance use:
Back in the browser on your desktop open the service http://10.174.184.156/searx
and run your application tests while the debug log is shown in the terminal from
above. You can stop monitoring using
CTRL-C, this also disables the “debug
option” in searx’s settings file and restarts the searx uwsgi application. To
debug services from filtron and morty analogous use:
Another point we have to notice is that each service (searx, filtron and morty) runs under dedicated system user account with the same name (compare Create user). To get a shell from theses accounts, simply call one of the scripts:
To get in touch, open a shell from the service user (searx@searx-archlinux):
[searx@searx-archlinux] signals that you are logged in as system
searx in the
searx-archlinux container and the python virtualenv
(searx-pyenv) environment is activated.
In this section we will see how to change the “Fully functional searx suite” from a LXC container (which is quite ready for production) into a developer suite. For this, we have to keep an eye on the Step by step installation:
searx setup in:
searx user’s home:
searx software in:
The searx software is a clone of the
GIT_URL (see Makefile setup) and
the working tree is checked out from the
GIT_BRANCH. With the use of the
utils/searx.sh the searx service was installed as uWSGI application. To maintain this service, we can use
service architectures on distributions).
With the command above, we stopped the searx uWSGI-App in the archlinux container.
The uWSGI-App for the archlinux dsitros is configured in
git://utils/templates/etc/uwsgi/apps-archlinux/searx.ini, from where at
least you should attend the settings of
env = SEARX_SETTINGS_PATH=/etc/searx/settings.yml http = 127.0.0.1:8888 chdir = /usr/local/searx/searx-src/searx virtualenv = /usr/local/searx/searx-pyenv pythonpath = /usr/local/searx/searx-src
If you have read the “Good to know section” you remember, that
each container shares the root folder of the repository and the command
utils/lxc.sh cmd handles relative path names transparent. To wrap the
searx installation into a developer one, we simple have to create a smylink to
the transparent reposetory from the desktop. Now lets replace the
searx-src in the container with the working tree from outside
of the container:
Now we can develop as usual in the working tree of our desktop system. Every time the software was changed, you have to restart the searx service (in the conatiner):
Remember: In containers, work as usual .. here are just some examples from my daily usage:
We build up a fully functional searx suite in a archlinux container:
$ sudo -H ./utils/lxc.sh install suite searx-archlinux
To access HTTP from the desktop we installed nginx for the services inside the conatiner:
To wrap the suite into a developer one, we created a symbolic link to the repository which is shared transparent from the desktop’s file system into the container :
To get remarks from the suite of the archlinux container we can use: