]> git.ozlabs.org Git - patchwork/blob - docs/INSTALL
tox: Update versions of Django to be tested
[patchwork] / docs / INSTALL
1 Deploying Patchwork
2
3 Patchwork uses the django framework - there is some background on deploying
4 django applications here:
5
6  http://www.djangobook.com/en/2.0/chapter12/
7
8 You'll need the following (applications used for patchwork development are
9 in brackets):
10
11   * A python interpreter
12   * django >= 1.5
13   * A webserver (apache)
14   * mod_python or flup
15   * A database server (postgresql, mysql)
16   * relevant python modules for the database server (e.g: python-mysqldb)
17
18
19 1. Database setup
20
21     At present, I've tested with PostgreSQL and (to a lesser extent) MySQL
22     database servers. If you have any (positive or negative) experiences with
23     either, email me.
24
25     For the following commands, a $ prefix signifies that the command should be
26     entered at your shell prompt, and a > prefix signifies the command-line
27     client for your sql server (psql or mysql)
28
29     Create a database for the system, add accounts for two system users: the
30     web user (the user that your web server runs as) and the mail user (the
31     user that your mail server runs as). On Ubuntu these are
32     www-data and nobody, respectively.
33
34     As an alternative, you can use password-based login and a single database
35     account. This is described further down.
36
37     For PostgreSQL (ident-based)
38
39         $ createdb patchwork
40         $ createuser www-data
41         $ createuser nobody
42
43         - postgres uses the standard UNIX authentication, so these users
44           will only be accessible for processes running as the same username.
45           This means that no passwords need to be set.
46
47     For PostgreSQL (password-based)
48
49         $ createuser -PE patchwork
50         $ createdb -O patchwork patchwork
51
52         Once that is done, you need to tell Django about the new Database
53         settings, using local_settings.py (see below) to override the defaults
54         in settings.py:
55
56         DATABASES = {
57             'default': {
58                 'ENGINE': 'django.db.backends.postgresql_psycopg2',
59                 'HOST': 'localhost',
60                 'PORT': '',
61                 'USER': 'patchwork',
62                 'PASSWORD': 'my_secret_password',
63                 'NAME': 'patchwork',
64             },
65         }
66
67     For MySQL:
68         $ mysql
69         > CREATE DATABASE patchwork CHARACTER SET utf8;
70         > CREATE USER 'www-data'@'localhost' IDENTIFIED BY '<password>';
71         > CREATE USER 'nobody'@'localhost' IDENTIFIED BY '<password>';
72
73         Once that is done, you need to tell Django about the new Database
74         settings, using local_settings.py (see below) to override the defaults
75         in settings.py:
76
77         DATABASES = {
78             'default': {
79                 'ENGINE': 'django.db.backends.mysql',
80                 'HOST': 'localhost',
81                 'PORT': '',
82                 'USER': 'patchwork',
83                 'PASSWORD': 'my_secret_password',
84                 'NAME': 'patchwork',
85                 'TEST_CHARSET': 'utf8',
86             },
87         }
88
89         TEST_CHARSET is used when creating tables for the test suite. Without
90         it, tests checking for the correct handling of non-ASCII characters
91         fail.
92
93
94 2. Django setup
95
96     Set up some initial directories in the patchwork base directory:
97
98       mkdir -p lib/packages lib/python
99
100     lib/packages is for stuff we'll download; lib/python is to add
101     to our python path. We'll symlink python modules into lib/python.
102
103     At the time of release, patchwork depends on django version 1.5 or
104     later. Your distro probably provides this. If not, do a:
105
106       cd lib/packages
107       git clone https://github.com/django/django.git -b stable/1.5.x
108       cd ../python
109       ln -s ../packages/django/django ./django
110
111     The patchwork/settings/*.py files contain default settings for patchwork,
112     you'll need to configure settings for your own setup.
113
114     Rather than editing these files (which will cause conflicts when you
115     update the base patchwork code), create a file 'production.py', based on
116     the example:
117
118        cp patchwork/settings/production.example.py \
119           patchwork/settings/production.py
120
121     and override or add settings as necessary. You'll need to define the
122     following:
123
124       SECRET_KEY
125       ADMINS
126       DATABASES
127       TIME_ZONE
128       LANGUAGE_CODE
129       DEFAULT_FROM_EMAIL
130       NOTIFICATION_FROM_EMAIL
131
132     You can generate the SECRET_KEY with the following python code:
133
134       import string, random
135       chars = string.letters + string.digits + string.punctuation
136       print repr("".join([random.choice(chars) for i in range(0,50)]))
137
138     If you wish to enable the XML-RPC interface, add the following to
139     your local_settings.py file:
140
141       ENABLE_XMLRPC = True
142
143     Then, get patchwork to create its tables in your configured database:
144
145      PYTHONPATH=lib/python ./manage.py syncdb
146
147     and initialise the static content:
148
149      PYTHONPATH=lib/python ./manage.py collectstatic
150
151     You'll also need to load the initial tags and states into the
152     patchwork database:
153
154      PYTHONPATH=lib/python ./manage.py loaddata default_tags default_states
155
156     Finally, add privileges for your mail and web users. This is only needed if
157     you use the ident-based approach. If you use password-based database
158     authentication, you can skip this step.
159
160     Postgresql:
161       psql -f lib/sql/grant-all.postgres.sql patchwork
162
163     MySQL:
164       mysql patchwork < lib/sql/grant-all.mysql.sql
165
166
167 3. Apache setup
168
169     Example apache configuration files are in lib/apache2/.
170
171     wsgi:
172
173         django has built-in support for WSGI, which supersedes the fastcgi
174         handler. It is thus the preferred method to run patchwork.
175
176         The necessary configuration for Apache2 may be found in
177
178          lib/apache2/patchwork.wsgi.conf.
179
180         You will need to install/enable mod_wsgi for this to work:
181
182          a2enmod wsgi
183          apache2ctl restart
184
185
186      mod_python:
187
188         An example apache configuration file for mod_python is in:
189
190           lib/apache2/patchwork.mod_python.conf
191
192         However, mod_python and mod_php may not work well together. So, if your
193         web server is used for serving php files, the fastcgi method may suit
194         instead.
195
196
197     fastcgi:
198
199         django has built-in support for fastcgi, which requires the
200         'flup' python module. An example configuration is in:
201
202           lib/apache2/patchwork.fastcgi.conf
203
204         - this also requires the mod_rewrite apache module to be loaded.
205
206         Once you have apache set up, you can start the fastcgi server with:
207
208           cd /srv/patchwork/
209           ./manage.py runfcgi method=prefork \
210                               socket=/srv/patchwork/var/fcgi.sock \
211                               pidfile=/srv/patchwork/var/fcgi.pid
212
213
214 4. Configure patchwork
215     Now, you should be able to administer patchwork, by visiting the
216     URL:
217
218       http://your-host/admin/
219
220     You'll probably want to do the following:
221
222       * Set up your projects
223       * Configure your website address (in the Sites) section
224
225     
226 5. Subscribe a local address to the mailing list
227
228     You will need an email address for patchwork to receive email on - for
229     example - patchwork@, and this address will need to be subscribed to the
230     list. Depending on the mailing list, you will probably need to confirm the
231     subscription - temporarily direct the alias to yourself to do this.
232
233
234 6. Setup your MTA to deliver mail to the parsemail script
235
236     Your MTA will need to deliver mail to the parsemail script in the email/
237     directory. (Note, do not use the parsemail.py script directly). Something
238     like this in /etc/aliases is suitable for postfix:
239
240       patchwork: "|/srv/patchwork/patchwork/bin/parsemail.sh"
241
242     You may need to customise the parsemail.sh script if you haven't installed
243     patchwork in /srv/patchwork.
244
245     Test that you can deliver a patch to this script:
246
247      sudo -u nobody /srv/patchwork/patchwork/bin/parsemail.sh < mail
248
249
250 7. Set up the patchwork cron script
251
252     Patchwork uses a cron script to clean up expired registrations, and
253     send notifications of patch changes (for projects with this enabled).
254
255     Something like this in your crontab should work:
256
257       # m h  dom mon dow   command
258       */10 * * * * cd patchwork; ./manage.py cron
259
260
261     - the frequency should be the same as the NOTIFICATION_DELAY_MINUTES
262     setting, which defaults to 10 minutes.
263
264
265 8. Optional: Configure your VCS to automatically update patches
266
267     The tools directory of the patchwork distribution contains a file
268     named post-receive.hook which is an example git hook that can be
269     used to automatically update patches to the Accepted state when
270     corresponding comits are pushed via git.
271
272     To install this hook, simply copy it to the .git/hooks directory on
273     your server, name it post-receive, and make it executable.
274
275     This sample hook has support to update patches to different states
276     depending on which branch is being pushed to. See the STATE_MAP
277     setting in that file.
278
279     If you are using a system other than git, you can likely write a
280     similar hook using pwclient to update patch state. If you do write
281     one, please contribute it.
282
283
284 Some errors:
285
286 * __init__() got an unexpected keyword argument 'max_length'
287
288  - you're running an old version of django. If your distribution doesn't
289    provide a newer version, just download and extract django into
290    lib/python/django
291
292 * ERROR: permission denied for relation patchwork_...
293
294  - the user that patchwork is running as (ie, the user of the web-server)
295    doesn't have access to the patchwork tables in the database. Check that
296    your web-server user exists in the database, and that it has permissions
297    to the tables.
298
299 * pwclient fails for actions that require authentication, but a username
300   and password is given in ~/.pwclientrc. Server reports "No authentication
301   credentials given".
302
303  - if you're using the FastCGI interface to apache, you'll need the
304    '-pass-header Authorization' option to the FastCGIExternalServer
305    configuration directive.