Project

General

Profile

User manual » History » Version 5

koszko, 04/28/2022 12:38 PM
document deployment with WSGI+Apache2

1 1 koszko
# User manual
2
3
{{toc}}
4
5
## Installation
6 4 koszko
7 1 koszko
### Using Python wheel
8
9 4 koszko
You can install Hydrilla server and(or) builder using .whl files from the [[Releases]] page. Please consider [[hachette:Verifying signatures|verifying the downloads]] using provided cryptographic signatures.
10
11
#### Installing dependencies
12
13
##### Python3
14
15
Hydrilla requires Python interpreter in at least version 3.7. You'd typically use Python3 as provided by you operating system distribution. For example, on Debian-based systems (including Trisquel) you can install it with:
16
``` shell
17
sudo apt install python3
18
```
19
20
##### pip
21
22
Pip is the package manager for Python. While not a direct dependency of Hydrilla, it is needed to utilize .whl files. You most likely also want to install pip as provided by your distro, e.g. for APT-based ones:
23
``` shell
24
sudo apt install python3-pip
25
```
26
27
##### Python libraries
28
29
Hydrilla relies on the following Python packages:
30
31
* `jsonschema`
32
* `click`
33
* `flask` (needed for Hydrilla server only)
34
* `reuse` (optional, only needed for Hydrilla builder to generate SPDX report)
35
36
If you don't have those dependencies installed, pip will automatically pull them from [PyPI](https://pypi.org) (except for reuse which would need to be installed separately with a command like `python3 -m pip install reuse`).
37
38
Nevertheless, you are encouraged to instead install the respective packages from your operating system's official repositories because those usually have stricter policies on stability, security and free licensing. In case of APT-based distributions the packages to install would be `python3-jsonschema`, `python3-click`, `python3-flask` and `reuse`[^reuse].
39
40
[^reuse]: Reuse tool was first packaged for Debian Bookworm and is not yet available in Debian Bullseye nor in Trisquel Nabia.
41
42
#### Installing Hydrilla
43
44
Let's assume you want to install version 1.0 of Hydrilla server. First, download and verify both[^server_depends_on_builder] `hydrilla.builder-1.0-py3-none-any.whl` and `hydrilla-1.0-py3-none-any.whl`. Then, run:
45
``` shell
46
python3 -m pip install path/to/downloaded/hydrilla.builder-1.0-py3-none-any.whl path/to/downloaded/hydrilla-1.0-py3-none-any.whl
47
```
48
49
[^server_depends_on_builder]: Hydrilla server also depends on Hydrilla builder.
50
51
This will install Hydrilla **for the current user**. The commands `hydrilla` and `hydrilla-builder` will be made available in `~/.local/bin/`.
52
53
#### Installing in virtualenv
54
55
If for example you don't want pip to install things under `~/.local/`, you might choose to create a virtual Python environment. First, make sure you have the `virtualenv` tool installed[^virtualenv_tool] (for example from APT package `python3-virtualenv`). Then, choose the folder in which you'd like to install the environment and run:
56
``` shell
57
virtualenv -p python3 --system-site-packages path/to/chosen/folder
58
```
59
60
[^virtualenv_tool]: Since Python 3.3 a virtual environment can also be created without this tool.
61
62
The `--system-site-packages` flag is not strictly necessary for it to work but is needed if you want packages inside the virtual environment to be able to see globally-installed dependencies.
63
64
Once the environment is created, you need to enter it by sourcing a script created by the virtualenv command, e.g.:
65
``` shell
66
source path/to/chosen/folder/bin/activate
67
```
68
69
Afterwards, the `python3 -m pip` commands you enter in this shell will install packages inside this virtual environment. You can learn more about Python virtual environments from online tutorials and the [virtualenv documentation](https://virtualenv.pypa.io).
70 1 koszko
71
### Using APT
72
73 3 koszko
Hydrilla APT repository is hosted at https://hydrillarepos.koszko.org/apt/ and is signed with Wojtek's PGP key (fingerprint **E9727060E3C5637C8A4F4B424BC5221C5A79FD1A**). It is expected to work with modern releases of most APT-based distributions (including Debian bullseye and Trisquel nabia).
74
75
This APT repository can be used to install Hydrilla server and builder system-wide and to later update the installation. It has to be said that this also requires you to trust Wojtek's repository with your system's safety (a malicious APT repository could easily take over a system that uses it).
76
77
If you've decided you want to install the APT repository on your system, the easiest way to do so is by copy-pasting the following script into your POSIX shell (and then confirming with your password). You can of course modify it according to your needs.
78
79
``` shell
80
__install_hydrilla_apt_repo() {
81
    local TMP="$1"
82
    local LISTS="$(cat <<EOF
83
deb     https://hydrillarepos.koszko.org/apt/ koszko main
84
deb-src https://hydrillarepos.koszko.org/apt/ koszko main
85
EOF
86
)"
87
88
    if ! wget -O "$TMP/koszko-keyring.gpg" https://hydrillarepos.koszko.org/apt/koszko-keyring.gpg; then
89
	echo "Error! Failed to download keyring file!" >&2
90
	return 1
91
    elif ! gpg --no-default-keyring --keyring "$TMP/koszko-keyring.gpg" --list-key E9727060E3C5637C8A4F4B424BC5221C5A79FD1A; then
92
	echo "Error! Invalid keyring file! Someone might be doing something nasty!" >&2
93
	return 1
94
    elif ! sudo cp "$TMP/koszko-keyring.gpg" /etc/apt/trusted.gpg.d/; then
95
	echo "Error!" >&2
96
	return 1
97
    elif ! printf %s "$LISTS" | sudo tee /etc/apt/sources.list.d/hydrillarepos.list > /dev/null; then
98
	echo "Error!" >&2
99
	return 1
100
    fi
101
102
    sudo apt-get update
103
}
104
105
install_hydrilla_apt_repo() {
106
    local TMP="$(mktemp -d)"
107
    __install_hydrilla_apt_repo "$TMP"
108
    local RESULT="$?"
109
110
    rm -r "$TMP"
111
112
    return "$RESULT"
113
}
114
115
install_hydrilla_apt_repo
116
```
117
118
This snippet is idempotent (i.e. it can be run multiple times and the effect will be as if it was run once). In addition, it executes `apt-get update` command at the end so that your APT is immediately aware of the new repository and its contents.
119
120
After installing the repository you can install Hydrilla builder and server using the following commands:
121
``` shell
122
sudo apt install python3-hydrilla.builder
123
```
124
``` shell
125
sudo apt install python3-hydrilla # this alone will also pull the builder as a dependency
126
```
127
128
The packages install their modules under `/usr/lib/python3/dist-packages/` which is seen by Python3 interpreters installed from APT. The `hydrilla` and `hydrilla-builder` commands get placed in `/usr/bin/`.
129
130
In addition, the `python3-hydrilla` package also includes sample WSGI script and Apache2 config files for Hydrilla under `/usr/share/doc/python3-hydrilla/examples/`.
131 1 koszko
132
## Understanding the concepts
133
134
*TODO*
135
136
## Running
137
138
### With development server
139
140
*TODO*
141
142
### With Apache2
143
144 5 koszko
This section describes how to configure an Apache2 virtual host to serve a Hydrilla repository. This guide is mostly meant to be useful to people running their own web servers.
145
146
You're going to need:
147
148
* root access on the machine[^rootless_hosting] (for writing to `/etc/apache2/sites-available/` directory)
149
* Apache2 with `mod_wsgi` installed and enabled
150
* Hydrilla installed
151
152
[^rootless_hosting]: If you want to run a Hydrilla server on shared hosting without root access, this might be achievable using a .htaccess file but is not documented right now.
153
154
First, choose a directory where you want to store your serveable Haketilo packages. The default is `/var/lib/hydrilla/malcontent`. You can override this by saving the following file as `/etc/hydrilla/config.json`:
155
``` javascript
156
{
157
    // Path to directory from which Hydrilla will load packages metadata and serve files.
158
    "malcontent_dir": "/your/chosen/dir"
159
}
160
```
161
162
Fill the directory with some package files. You might for example clone the [source package example repository](https://git.koszko.org/hydrilla-source-package-example/) and build it with something along the lines of:
163
``` shell
164
sudo hydrilla-builder -s path/to/cloned/hydrilla-source-package-example/ -d /var/lib/hydrilla/malcontent/
165
```
166
167
Once done, grab Hydrilla's [sample WSGI script](https://git.koszko.org/pydrilla/tree/doc/examples/hydrilla.wsgi) and save it in your chosen location (the suggested one is `/var/lib/hydrilla/wsgi/hydrilla.wsgi`). Follow the comments in this script to modify it according to your needs.
168
169
Now, get the [sample Apache2 configuration](https://git.koszko.org/pydrilla/tree/doc/examples/hydrilla.example.com.tls.conf) (there is also [one for TLS-less deployment](https://git.koszko.org/pydrilla/tree/doc/examples/hydrilla.example.com.conf)), also modify it according to your needs (in particular, you'll likely want to change `hydrilla.example.com` to some real domain of yours) and save under `/etc/apache2/sites-available/your.chosen.config.name.conf`.
170
171
You can now enable the configuration with:
172
``` shell
173
sudo a2ensite your.chosen.config.name
174
```
175
176
You also need to reload or restart the Apache daemon for the configuration to be picked up (the command to do that varies between init systems). Once you do so, you can verify that the server is running properly. Consider running something like the following (replacing `hydrilla.example.com` with the domain name you used):
177
``` shell
178
# The following assume that Hydrilla is loaded with the sample Haketilo package
179
curl http://hydrilla.example.com/mapping/helloapple.json
180
# -v flag will let us verify that the "Content-Type: application/json" header is present
181
curl -v http://hydrilla.example.com/resource/hello-message/2021.11.10
182
curl -v http://hydrilla.example.com/query?url=https://hydrillabugs.koszko.org/a/b/c
183
```
184
185
If everything is working as expected (i.e. JSON documents are properly served by Hydrilla&Apache2), you can start populating the "malcontent directory" with built packages of your choice.