Installing SourceLab¶
SourceLab has no packages yet: install it from the sources. See Components for what the different pieces do.
Installing from the sources¶
The sources are a uv workspace, in which each component is a package under packages/. To install the web applications (the core and the documentation server):
git clone https://code.abilian.com/abilian/sourcelab.git
cd sourcelab
python -m pip install ./packages/sourcelab
Note
To turn on the live updates or install the milter, refer to their own pages: Live Updates and Email Replies.
Then install the additional files as follows:
| Source | Destination |
|---|---|
files/sourcelab.cfg.sample |
/etc/sourcelab/sourcelab.cfg |
files/alembic.ini |
/etc/sourcelab/alembic.ini |
files/sourcelab-apache-httpd.conf |
/etc/httpd/conf.d/sourcelab.conf |
files/sourcelab.wsgi |
/usr/share/sourcelab/sourcelab.wsgi |
bin/createdb.py |
/usr/share/sourcelab/sourcelab_createdb.py |
Set-up SourceLab¶
Once SourceLab's files are installed, you still need to set up some things.
- Create the folder release
This folder is used by project maintainers to upload the tarball of the releases of their project.
This folder must be accessible by the user under which the application is running (in our case: git). :
- Create the folders where the repos, forks and checkouts will be stored
SourceLab stores the sources of a project in a git repository, and its documentation in another. It stores a JSON dump of all issues and of all pull requests in two more repositories, and keeps a local checkout of remote projects for remote pull requests. All these repositories are stored in different folders that must be created manually.
For example you can place them under /srv/git/repositories/ which would make /srv/git the home of your git user.
You would then create the folders with:
- Configure apache
An example configuration file is in the sources: files/sourcelab-apache-httpd.conf.
Adjust it for your needs.
- Configure the WSGI file
Example WSGI files are in the sources: files/sourcelab.wsgi for the core server and files/doc_sourcelab.wsgi for the doc server.
Adjust them for your needs
SourceLab is an ASGI application, sourcelab.web.asgi:create_asgi_app (a factory). sourcelab.wsgi wraps it for mod_wsgi with a2wsgi, at some cost in speed. The preferred setup runs it under an ASGI server behind the reverse proxy, as the sourcelab_web service does with nginx:
SOURCELAB_CONFIG=/etc/sourcelab/sourcelab.cfg uvicorn --factory sourcelab.web.asgi:create_asgi_app --workers 4 --uds /tmp/sourcelab_web.sock
The documentation server is an ASGI application too, sourcelab.web.docs_server:create_docs_app: the sourcelab_docs_web service runs it with uvicorn, and doc_sourcelab.wsgi wraps it for mod_wsgi.
- Give apache permission to read the repositories owned by the
gituser.
For the sake of this document, we assume that the web application runs under the git user, the same user as your git user, but apache itself runs under the httpd (or apache2) user. So by default, apache will not be allowed to read git repositories created and managed by SourceLab.
To give apache this permission (required to make git clone via http work), we use file access control lists (aka FACL):
setfacl -m user:apache:rx --default
setfacl -Rdm user:apache:rx /srv/git
setfacl -Rm user:apache:rx /srv/git
Where /srv/git is the home of your git user (which will thus need to be adjusted for your configuration).
- Set up the configuration file of SourceLab
This is an important step which concerns the file /etc/sourcelab/sourcelab.cfg. Copy the example of the sources, files/sourcelab.cfg.sample, there.
Confer the Configuration section of this documentation for a full explanation of all the options of SourceLab.
- Create the database
You first need to create the database itself. For this, since SourceLab can work with: PostgreSQL, MySQL or MariaDB, we would like to invite you to consult the documentation of your database system for this operation.
Once you have specified in the configuration file the to url used to connect to the database, and create the database itself, you can now create the tables, the database scheme.
For changes to existing tables, we rely on Alembic. It uses revisions to perform the upgrades, but to know which upgrades are needed and which are already done, the current revision needs to be saved in the database. This will allow alembic to know and apply the new revision when running it.
In the alembic.ini file, one of the configuration key is most important: script_location which is the path to the versions folder containing all the alembic migration files. The sqlalchemy.url configuration key if missing will be replaced by the url filled in the configuration file of SourceLab.
To create the database tables, you need to run the script /usr/share/sourcelab/sourcelab_createdb.py and specify the configuration to use for SourceLab and for alembic.
For example:
python /usr/share/sourcelab/sourcelab_createdb.py -c /etc/sourcelab/sourcelab.cfg -i /etc/sourcelab/alembic.ini
This will tell /usr/share/sourcelab/sourcelab_createdb.py to use the database information specified in the file /etc/sourcelab/sourcelab.cfg and to stamp the database at the last alembic revision. It also creates the tables of NeoZen, which keeps the passwords and the login sessions, with NeoZen's own migrations.
Warning
SourceLab's default configuration is using sqlite. This is fine for development purpose but not for production use as sqlite does not support all the operations needed when updating the database schema. Do use PostgreSQL, MySQL or MariaDB in production.
For changes to existing tables, we rely on Alembic. It uses revisions to perform the upgrades, but to know which upgrades are needed and which are already done, the current revision needs to be saved in the database. This will allow alembic to know apply the new revision when running it.
In the alembic.ini file, one of the configuration key is most important: script_location which is the path to the versions folder containing all the alembic migration files. The sqlalchemy.url configuration key if missing will be replaced by the url filled in the configuration file of SourceLab.
Warning
Only use the --initial argument of sourcelab_createdb.py the first time: it would otherwise break upgrading the database schema with alembic.
Note
When install from source the script is called bin/createdb.py and not sourcelab_createdb.py.
The workers are Myxo services, placed in the processes of a layout, /etc/sourcelab/layout.toml. The unit sourcelab_worker runs its process worker, which must hold the services projects, repos, pull_requests and stats. Create Myxo's tables with myxo migrate /etc/sourcelab/layout.toml (createdb.py also does), then enable and start the worker services:
Set up virus scanning¶
SourceLab can automatically scan uploaded attachments for viruses using Clam. To set this up, first install clamav-data-empty, clamav-server, clamav-server-systemd and clamav-update.
Then edit /etc/freshclam.conf, removing the Example line and run freshclam once to get an up to date database.
Copy /usr/share/doc/clamav-server/clamd.conf to /etc/clamd.conf and edit that too, again making sure to remove the Example line. Make sure to set LocalSocket to a file in a directory that exists, and set User to an existing system user.
Then start the clamd service and set VIRUS_SCAN_ATTACHMENTS = True in the SourceLab configuration.