1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
|
Installation
============
This document describes the necessary steps to configure Patchwork in a
development environment. If you are interested in deploying Patchwork in a
production environment, refer to `the deployment guide
</deployment/installation>`__ instead.
To begin, you should clone Patchwork:
.. code-block:: shell
$ git clone git://github.com/getpatchwork/patchwork.git
.. _installation-docker:
Docker-Based Installation
-------------------------
Patchwork provides a Docker-based environment for quick configuration of a
development environment. This is the preferred installation method. To
configure Patchwork using Docker:
#. Install `docker`_ and `docker-compose`_.
#. Create a ``.env`` file in the root directory of the project and store your
``UID`` attribute there.
.. code-block:: shell
$ echo "UID=$UID" > .env
#. Build the images. This will download over 200MB from the internet:
.. code-block:: shell
$ docker-compose build
#. Run ``docker-compose up``:
.. code-block:: shell
$ docker-compose up
This will be visible at http://localhost:8000/.
To run a shell within this environment, run:
.. code-block:: shell
$ docker-compose run --rm web --shell
To run ``django-manage`` commands, such as ``createsuperuser`` or ``migrate``,
run:
.. code-block:: shell
$ docker-compose run --rm web python manage.py createsuperuser
To access the SQL command-line client, run:
.. code-block:: shell
$ docker-compose run --rm web python manage.py dbshell
To run unit tests against the system Python packages, run:
.. code-block:: shell
$ docker-compose run --rm web python manage.py test
To run unit tests for multiple versions using ``tox``, run:
.. code-block:: shell
$ docker-compose run --rm web tox
To reset the database before any of these commands, add ``--reset`` to the
command line after ``web`` and before any other arguments. Conversely, to
backup the database at any stage, run:
.. code-block:: shell
$ docker exec DATABASECONTAINER /usr/bin/mysqldump -u DATABASEUSER \
--password=DATABASEPASSWORD DATABASE > backup.sql
where ``DATABASECONTAINER`` is found by ``docker ps -a`` and the other settings
are the same as those defined in ``patchwork/settings/dev.py``. To restore this
again, run:
.. code-block:: shell
$ docker-compose run --rm web python manage.py dbshell
mysql> use DATABASE;
mysql> set autocommit=0; source backup.sql; commit;
mysql> exit;
Any local edits to the project files made locally are immediately visible to
the Docker container, and so should be picked up by the Django auto-reloader.
For more information on Docker itself, please refer to the `docker`_ and
`docker-compose`_ documentation.
.. note::
If using SELinux, you will need to create a custom SELinux rule to allow the
Docker process to access your working directory. Run:
.. code-block:: shell
$ chcon -RT svirt_sandbox_file_t $PATCHWORK_DIR
where `$PATCHWORK_DIR` is the absolute patch to the `patchwork` folder
created when you cloned the repo. For more information, see `man docker
run`.
.. note::
If you see an error like the below::
ERROR: Couldn't connect to the Docker daemon at http+docker://localunixsocket - is it running?
ensure you have correctly installed Docker, added your user to the `docker`
group, and started the daemon, per the `docker documentation <docker>`_.
.. note::
If you see an error like the below::
You must define UID in .env
Ensure you have created a ``.env`` file in the root of your project
directory and stored the ``UID`` attribute there. For more information on
why this is necessary, refer to this `docker-compose issue`__.
__ https://github.com/docker/compose/issues/2380
.. _docker: https://docs.docker.com/compose/install/
.. _docker-compose: https://docs.docker.com/engine/installation/linux/
Manual Installation
-------------------
Manual installation can be used where use of Docker is not possible
or desired.
Install Required Packages
~~~~~~~~~~~~~~~~~~~~~~~~~
There are a number of different requirements for developing Patchwork:
* Python and libraries
* A supported database (RDBMS)
These are detailed below.
Python Requirements
^^^^^^^^^^^^^^^^^^^
To develop Python-based software you first need Python. Patchwork supports both
Python 2.7 and Python 3.3+. One of these will be installed by default on many
installations, though they can also be installed manually using the `python` or
`python3` packages.
It's a good idea to use `virtual environments`__ to develop Python software.
Virtual environments are "instances" of your system Python without any of the
additional Python packages installed. They are useful to develop and possibly
deploy Patchwork against a "well known" set of dependencies, but they can also
be used to test Patchwork against several versions of Django.
If you do not have `virtualenv` installed then you should install it now. This
can be installed using the `python-virtualenv` or `python3-virtualenv`
packages. Alternatively you can install these using `pip`.
It is also helpful to install `tox` which is used for running tests in
Patchwork. This can be installed using the `python-tox` or `python3-tox`
packages, or via `pip`.
__ https://virtualenv.readthedocs.io/en/latest/
Database Requirements
^^^^^^^^^^^^^^^^^^^^^
If not already installed, you may need to install an RDBMS. You can use either
MariaDB/MySQL or PostgreSQL for this purpose. You should also install the
development headers, known as `libmysqlclient-dev` or `libpq-dev` respectively
on Debian-based Debian-based distros like Ubuntu and `mysql-devel` or
`postgresql-devel` on RHEL-based distros.
.. note::
While Django provides support for `multiple database backends`__, Patchwork
itself is only tested against MySQL/MariaDB and PostgreSQL. Should you wish
to use a different backend, ensure you validate this first (and perhaps
upstream any changes you may find necessary).
.. note::
You may be tempted to use SQLite to develop Patchwork. We'd advise against
doing this. SQLite supports a subset of the functionality of "full" RDBMS
like MySQL: for example, case-sensitive matching of Unicode `is not
supported`__. You will find some tests provided by Patchwork fail and some
patches you develop may fail in production due to these differences.
__ https://docs.djangoproject.com/en/1.8/ref/databases/
__ https://www.sqlite.org/faq.html#q18
Example Installation
^^^^^^^^^^^^^^^^^^^^
An example for installing all these packages and the MySQL RDBMS on Ubuntu
15.04 is given below:
.. code-block:: shell
$ sudo apt-get install python python-pip python-dev python-virtualenv \
python-tox mysql-server libmysqlclient-dev
If you have an existing MariaDB/MySQL installation and have installed `pip`
already/are using Python 3.4+ then you can install all packages using `pip`:
.. code-block:: shell
$ sudo pip install virtualenv tox
If you wish to use Python 3 then simply replace `python` with `python3` in the
above command.
Configure Virtual Environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. note::
If you are interested in simply :ref:`testing Patchwork <testing>`, many of
the below steps are not required. tox will automatically install
dependencies and use virtual environments when testing.
Once these requirements are installed, you should create and activate a new
virtual environment. This can be done like so:
.. code-block:: shell
$ virtualenv .venv
$ source .venv/bin/activate
(.venv)$
.. note::
If you installed a Python 3.x-based virtual environment package, adjust the
executable indicated above as necessary, e.g. `virtualenv-3.4`.
Now install the packages. Patchwork provides three requirements files.
`requirements-dev.txt`
Packages required to configure a development environment
`requirements-prod.txt`
Packages required for deploying Patchwork in production
`requirements-test.txt`
Packages required to run tests
We're going to install the first of these, which can be done like so:
.. code-block:: shell
(.venv)$ cd patchwork
(.venv)$ pip install -r requirements-dev.txt
.. note::
Once configured this does not need to be done again *unless* the
requirements change, e.g. Patchwork requires an updated version of Django.
Initialize the Database
~~~~~~~~~~~~~~~~~~~~~~~
One installed, the database must be configured. We will assume you have root
access to the database for these steps.
To begin, export your database credentials as follows:
.. code-block:: shell
(.venv)$ db_user=root
(.venv)$ db_pass=password
Now, create the database. If this is your first time configuring the database,
you must create a `patchwork` user (or similar) along with the database
instance itself. The commands below will do this, dropping existing databases
if necessary:
.. code-block:: shell
(.venv)$ mysql -u$db_user -p$db_pass << EOF
DROP DATABASE IF EXISTS patchwork;
CREATE DATABASE patchwork CHARACTER SET utf8;
GRANT ALL PRIVILEGES ON patchwork.* TO 'patchwork'@'localhost'
IDENTIFIED BY 'password';
EOF
.. note::
The `patchwork` username and `password` password are the defaults expected
by the provided `dev` settings files. If using something different,
export the `PW_TEST_DB_USER` and `PW_TEST_DB_PASS` variables described in
the :ref:`Environment Variables <dev-envvar>` section below. Alternatively,
you can create your own settings file with these variables hardcoded and
change the value of `DJANGO_SETTINGS_MODULE` as described below.
Load Initial Data
~~~~~~~~~~~~~~~~~
Before continuing, we need to tell Django where it can find our configuration.
Patchwork provides a default development `settings.py` file for this purpose.
To use this, export the `DJANGO_SETTINGS_MODULE` environment variable as
described below:
.. code-block:: shell
(.venv)$ export DJANGO_SETTINGS_MODULE=patchwork.settings.dev
Alternatively you can provide your own `settings.py` file and provide the path
to that instead.
Once done, we need to create the tables in the database. This can be done using
the `migrate` command of the `manage.py` executable:
.. code-block:: shell
(.venv)$ ./manage.py migrate
Next, you should load the initial fixtures into Patchwork. These initial
fixtures provide.
`default_tags.xml`
The tags that Patchwork will extract from mails. For example: `Acked-By`,
`Reviewed-By`
`default_states.xml`
The states that a patch can be in. For example: `Accepted`, `Rejected`
`default_projects.xml`
A default project that you can then upload patches for
These can be loaded using the `loaddata` command:
.. code-block:: shell
(.venv)$ ./manage.py loaddata default_tags default_states default_projects
You should also take the opportunity to create a "superuser". You can do this
using the aptly-named `createsuperuser` command:
.. code-block:: shell
(.venv)$ ./manage.py createsuperuser
Import Mailing List Archives
----------------------------
Regardless of your installation method of choice, you will probably want to
load some real emails into the system. This can be done manually, however it's
generally much easier to download an archive from a Mailman instance and load
these using the `parsearchive` command. You can do this like so:
.. code-block:: shell
(.venv)$ mm_user=<myusername>
(.venv)$ mm_pass=<mypassword>
(.venv)$ mm_host=https://lists.ozlabs.org
(.venv)$ mm_url=$mm_host/private/patchwork.mbox/patchwork.mbox
(.venv)$ curl -F username=$mm_user -F password=$mm_pass -k -O $mm_url
where `mm_user` and `mm_pass` are the username and password you have registered
with on the Mailman instance found at `mm_host`.
.. note::
We provide instructions for downloading archives from the Patchwork mailing
list, but almost any instance of Mailman will allow downloading of archives
as seen above; simply change the `pw_url` variable defined. You can find
more informations about this `here`__.
Load these archives into Patchwork. Depending on the size of the downloaded
archives this may take some time:
.. code-block:: shell
(.venv)$ ./manage.py parsearchive --list-id=patchwork.ozlabs.org \
patchwork.mbox
Finally, run the server and browse to the IP address of your board using your
browser of choice:
.. code-block:: shell
(.venv)$ ./manage.py runserver 0.0.0.0:8000
Once finished, you can kill the server (`Ctrl` + `C`) and exit the virtual
environment:
.. code-block:: shell
(.venv)$ deactivate
$
Should you wish to re-enter this environment, simply source the `activate`
script again.
__ http://blog.behnel.de/posts/indexp118.html
Django Debug Toolbar
--------------------
Patchwork installs and enables the 'Django Debug Toolbar' by default. However,
by default this is only displayed if you are developing on localhost. If
developing on a different machine, you should configure an SSH tunnel such
that, for example, `localhost:8000` points to `[DEV_MACHINE_IP]:8000`.
.. _dev-envvar:
Environment Variables
---------------------
The following environment variables are available to configure settings when
using the provided `dev` settings file.
`PW_TEST_DB_NAME=patchwork`
Name of the database
`PW_TEST_DB_USER=patchwork`
Username to access the database with
`PW_TEST_DB_PASS=password`
Password to access the database with<
`PW_TEST_DB_TYPE=mysql`
Type of database to use. Options: 'mysql', 'postgres'
|