1
Serving Bazaar with Apache
1
Serving Breezy with Apache
2
2
==========================
4
This document describes one way to set up a Bazaar HTTP smart server,
4
This document describes one way to set up a Breezy HTTP smart server,
5
5
using Apache 2.0 and FastCGI or mod_python or mod_wsgi.
7
7
For more information on the smart server, and other ways to configure it
13
13
You have a webserver already publishing `/srv/example.com/www/code` as
14
`http://example.com/code/...` with plain HTTP. It contains bzr branches and
14
`http://example.com/code/...` with plain HTTP. It contains branches and
15
15
directories like `/srv/example.com/www/code/branch-one` and
16
16
`/srv/example.com/www/code/my-repo/branch-two`. You want to provide read-only
17
17
smart server access to these directories in addition to the existing HTTP
47
47
Options Indexes FollowSymLinks
50
RewriteRule ^(.*/)?\.bzr/smart$ /srv/example.com/scripts/bzr-smart.fcgi
50
RewriteRule ^(.*/)?\.bzr/smart$ /srv/example.com/scripts/brz-smart.fcgi
53
# bzr-smart.fcgi isn't under the DocumentRoot, so Alias it into the URL
53
# brz-smart.fcgi isn't under the DocumentRoot, so Alias it into the URL
54
54
# namespace so it can be executed.
55
Alias /srv/example.com/scripts/bzr-smart.fcgi /srv/example.com/scripts/bzr-smart.fcgi
55
Alias /srv/example.com/scripts/brz-smart.fcgi /srv/example.com/scripts/brz-smart.fcgi
56
56
<Directory /srv/example.com/scripts>
58
<Files bzr-smart.fcgi>
58
<Files brz-smart.fcgi>
59
59
SetHandler fastcgi-script
63
This instructs Apache to hand requests for any URL ending with `/.bzr/smart`
64
inside `/code` to a Bazaar smart server via FastCGI.
63
This instructs Apache to hand requests for any URL ending with `/.brz/smart`
64
inside `/code` to a Breezy smart server via FastCGI.
66
66
Refer to the mod_rewrite_ and mod_fastcgi_ documentation for further
80
80
Define the rewrite rules with mod_rewrite the same way as for FastCGI, except
83
RewriteRule ^(.*/)?\.bzr/smart$ /srv/example.com/scripts/bzr-smart.fcgi
83
RewriteRule ^(.*/)?\.bzr/smart$ /srv/example.com/scripts/brz-smart.fcgi
87
RewriteRule ^(.*/)?\.bzr/smart$ /srv/example.com/scripts/bzr-smart.py
87
RewriteRule ^(.*/)?\.bzr/smart$ /srv/example.com/scripts/brz-smart.py
89
89
Like with mod_fastcgi, we also define how our script is to be handled::
91
Alias /srv/example.com/scripts/bzr-smart.py /srv/example.com/scripts/bzr-smart.py
91
Alias /srv/example.com/scripts/brz-smart.py /srv/example.com/scripts/brz-smart.py
92
92
<Directory /srv/example.com/scripts>
94
94
PythonPath "sys.path+['/srv/example.com/scripts']"
95
95
AddHandler python-program .py
96
PythonHandler bzr-smart::handler
96
PythonHandler brz-smart::handler
100
This instructs Apache to hand requests for any URL ending with `/.bzr/smart`
101
inside `/code` to a Bazaar smart server via mod_python.
100
This instructs Apache to hand requests for any URL ending with `/.brz/smart`
101
inside `/code` to a Breezy smart server via mod_python.
103
NOTE: If you don't have bzrlib in your PATH, you will be need to change the
103
NOTE: If you don't have breezy in your PATH, you will be need to change the
106
106
PythonPath "sys.path+['/srv/example.com/scripts']"
110
PythonPath "['/path/to/bzr']+sys.path+['/srv/example.com/scripts']"
110
PythonPath "['/path/to/brz']+sys.path+['/srv/example.com/scripts']"
113
113
Refer to the mod_python_ documentation for further information.
121
121
First, configure mod_wsgi, e.g. enabling the mod with a2enmod wsgi.
122
We need to change it to handle all requests for URLs ending in `.bzr/smart`. It
122
We need to change it to handle all requests for URLs ending in `.brz/smart`. It
125
WSGIScriptAliasMatch ^/code/.*/\.bzr/smart$ /srv/example.com/scripts/bzr.wsgi
125
WSGIScriptAliasMatch ^/code/.*/\.bzr/smart$ /srv/example.com/scripts/brz.wsgi
127
127
#The three next lines allow regular GETs to work too
133
133
WSGIApplicationGroup %{GLOBAL}
136
This instructs Apache to hand requests for any URL ending with `/.bzr/smart`
137
inside `/code` to a Bazaar smart server via WSGI, and any other URL inside
136
This instructs Apache to hand requests for any URL ending with `/.brz/smart`
137
inside `/code` to a Breezy smart server via WSGI, and any other URL inside
138
138
`/code` to be served directly by Apache.
140
140
Refer to the mod_wsgi_ documentation for further information.
142
142
.. _mod_wsgi: http://code.google.com/p/modwsgi/
145
145
------------------
150
150
We've configured Apache to run the smart server at
151
`/srv/example.com/scripts/bzr-smart.fcgi`. This is just a simple script we need
151
`/srv/example.com/scripts/brz-smart.fcgi`. This is just a simple script we need
152
152
to write to configure a smart server, and glue it to the FastCGI gateway.
153
153
Here's what it looks like::
156
from bzrlib.transport.http import wsgi
156
from breezy.transport.http import wsgi
158
158
smart_server_app = wsgi.make_app(
159
159
root='/srv/example.com/www/code',
176
176
We've configured Apache to run the smart server at
177
`/srv/example.com/scripts/bzr-smart.py`. This is just a simple script we need
177
`/srv/example.com/scripts/brz-smart.py`. This is just a simple script we need
178
178
to write to configure a smart server, and glue it to the mod_python gateway.
179
179
Here's what it looks like::
182
from bzrlib.transport.http import wsgi
182
from breezy.transport.http import wsgi
184
184
smart_server_app = wsgi.make_app(
185
185
root='/srv/example.com/www/code',
197
197
The `modpywsgi` module can be found at
198
198
http://ice.usq.edu.au/svn/ice/trunk/apps/ice-server/modpywsgi.py. It was
199
199
part of pocoo_. You sould make sure you place modpywsgi.py in the same
200
directory as bzr-smart.py (ie. /srv/example.com/scripts/).
200
directory as brz-smart.py (ie. /srv/example.com/scripts/).
202
202
.. _pocoo: http://dev.pocoo.org/projects/pocoo/
208
208
We've configured Apache to run the smart server at
209
`/srv/example.com/scripts/bzr.wsgi`. This is just a simple script we need
209
`/srv/example.com/scripts/brz.wsgi`. This is just a simple script we need
210
210
to write to configure a smart server, and glue it to the WSGI gateway.
211
211
Here's what it looks like::
213
from bzrlib.transport.http import wsgi
213
from breezy.transport.http import wsgi
215
215
def application(environ, start_response):
216
216
app = wsgi.make_app(
226
Now you can use `bzr+http://` URLs or just `http://` URLs, e.g.::
226
Now you can use `brz+http://` URLs or just `http://` URLs, e.g.::
228
bzr log bzr+http://example.com/code/my-branch
228
brz log brz+http://example.com/code/my-branch
230
230
Plain HTTP access should continue to work::
232
bzr log http://example.com/code/my-branch
232
brz log http://example.com/code/my-branch
234
234
Advanced configuration
235
235
----------------------
237
Because the Bazaar HTTP smart server is a WSGI application, it can be used with
237
Because the Breezy HTTP smart server is a WSGI application, it can be used with
238
238
any 3rd-party WSGI middleware or server that conforms the WSGI standard. The
239
239
only requirements are:
241
241
* to construct a `SmartWSGIApp`, you need to specify a **root transport** that it
243
* each request's `environ` dict must have a **'bzrlib.relpath'** variable set.
243
* each request's `environ` dict must have a **'breezy.relpath'** variable set.
245
245
The `make_app` helper used in the example constructs a `SmartWSGIApp` with a
246
246
transport based on the `root` path given to it, and calculates the
247
'bzrlib.relpath` for each request based on the `prefix` and `path_var`
247
'breezy.relpath` for each request based on the `prefix` and `path_var`
248
248
arguments. In the example above, it will take the 'REQUEST_URI' (which is set
249
by Apache), strip the '/code/' prefix and the '/.bzr/smart' suffix, and set that
250
as the 'bzrlib.relpath', so that a request for '/code/foo/bar/.bzr/smart' will
251
result in a 'bzrlib.relpath' of 'foo/bzr'.
249
by Apache), strip the '/code/' prefix and the '/.brz/smart' suffix, and set that
250
as the 'breezy.relpath', so that a request for '/code/foo/bar/.brz/smart' will
251
result in a 'breezy.relpath' of 'foo/brz'.
253
253
It's possible to configure a smart server for a non-local transport, or that
254
254
does arbitrary path translations, etc, by constructing a `SmartWSGIApp`
255
directly. Refer to the docstrings of `bzrlib.transport.http.wsgi` and the `WSGI
255
directly. Refer to the docstrings of `breezy.transport.http.wsgi` and the `WSGI
256
256
standard`_ for further information.
258
258
.. _WSGI standard: http://www.python.org/dev/peps/pep-0333/
265
265
easiest way to do this, is to just supply ``readonly=False`` to the
266
266
``wsgi.make_app()`` call. But be careful, because the smart protocol does
267
267
not contain any Authentication. So if you enable write support, you will
268
want to restrict access to ``.bzr/smart`` URLs to restrict who can
268
want to restrict access to ``.brz/smart`` URLs to restrict who can
269
269
actually write data on your system, e.g. in apache it looks like::
284
284
require authentication and use a writable server, and plain HTTP allow
285
285
read-only access.
287
If bzr gives an error like this when accessing your HTTPS site::
287
If brz gives an error like this when accessing your HTTPS site::
289
bzr: ERROR: Connection error: curl connection error (server certificate verification failed.
289
brz: ERROR: Connection error: curl connection error (server certificate verification failed.
290
290
CAfile:/etc/ssl/certs/ca-certificates.crt CRLfile: none)
292
292
You can workaround it by using ``https+urllib`` rather than ``http`` in your