/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5053.3.1 by Agustin Henze - TiN
Add example for mod_wsgi and other little corrections
1
Serving Bazaar with Apache
2
==========================
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
3
2293.1.6 by Brad Crittenden
post review changes
4
This document describes one way to set up a Bazaar HTTP smart server,
5053.3.1 by Agustin Henze - TiN
Add example for mod_wsgi and other little corrections
5
using Apache 2.0 and FastCGI or mod_python or mod_wsgi.
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
6
2601.1.2 by James Westby
Add a reference to the main smart server documentation.
7
For more information on the smart server, and other ways to configure it
8
see the main `smart server documentation`_.
9
3104.2.5 by Ian Clatworthy
fix some broken links and make doc more Windows user friendly
10
.. _smart server documentation: #running-a-smart-server
2601.1.2 by James Westby
Add a reference to the main smart server documentation.
11
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
12
Example
2977.1.1 by Ian Clatworthy
First cut at new look User Guide including chapters 1 and 2
13
-------
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
14
15
You have a webserver already publishing `/srv/example.com/www/code` as
16
`http://example.com/code/...` with plain HTTP.  It contains bzr branches and
17
directories like `/srv/example.com/www/code/branch-one` and
2018.4.2 by Andrew Bennetts
Add security warning to http_smart_server.txt.
18
`/srv/example.com/www/code/my-repo/branch-two`.  You want to provide read-only
19
smart server access to these directories in addition to the existing HTTP
20
access.
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
21
22
Configuring Apache 2.0
23
----------------------
24
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
25
FastCGI
26
~~~~~~~
27
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
28
First, configure mod_fastcgi, e.g. by adding lines like these to your
29
httpd.conf::
30
31
    LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so
32
    FastCgiIpcDir /var/lib/apache2/fastcgi
4853.1.1 by Patrick Regan
Removed trailing whitespace from files in doc directory
33
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
34
In our example, we're already serving `/srv/example.com/www/code` at
35
`http://example.com/code`, so our existing Apache configuration would look
36
like::
37
38
    Alias /code /srv/example.com/www/code
39
    <Directory /srv/example.com/www/code>
40
        Options Indexes
41
        # ...
42
    </Directory>
43
44
We need to change it to handle all requests for URLs ending in `.bzr/smart`.  It
45
will look like::
46
47
    Alias /code /srv/example.com/www/code
48
    <Directory /srv/example.com/www/code>
2706.1.1 by Martin Albisetti
updated smart server documentation
49
        Options Indexes FollowSymLinks
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
50
        RewriteEngine On
51
        RewriteBase /code
2190.1.2 by John Arbash Meinel
Need the correct rewrite rule to get .bzr at the root of the exposed directory.
52
        RewriteRule ^(.*/|)\.bzr/smart$ /srv/example.com/scripts/bzr-smart.fcgi
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
53
    </Directory>
4853.1.1 by Patrick Regan
Removed trailing whitespace from files in doc directory
54
2018.4.5 by Andrew Bennetts
Improvement thanks to John's review.
55
    # bzr-smart.fcgi isn't under the DocumentRoot, so Alias it into the URL
56
    # namespace so it can be executed.
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
57
    Alias /srv/example.com/scripts/bzr-smart.fcgi /srv/example.com/scripts/bzr-smart.fcgi
58
    <Directory /srv/example.com/scripts>
59
        Options ExecCGI
60
        <Files bzr-smart.fcgi>
61
            SetHandler fastcgi-script
62
        </Files>
63
    </Directory>
4853.1.1 by Patrick Regan
Removed trailing whitespace from files in doc directory
64
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
65
This instructs Apache to hand requests for any URL ending with `/.bzr/smart`
66
inside `/code` to a Bazaar smart server via FastCGI.
67
68
Refer to the mod_rewrite_ and mod_fastcgi_ documentation for further
69
information.
70
71
.. _mod_rewrite: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
72
.. _mod_fastcgi: http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html
73
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
74
mod_python
75
~~~~~~~~~~
76
77
First, configure mod_python, e.g. by adding lines like these to your
78
httpd.conf::
79
80
    LoadModule python_module /usr/lib/apache2/modules/mod_python.so
81
82
Define the rewrite rules with mod_rewrite the same way as for FastCGI, except
83
change::
84
2190.1.2 by John Arbash Meinel
Need the correct rewrite rule to get .bzr at the root of the exposed directory.
85
    RewriteRule ^(.*/|)\.bzr/smart$ /srv/example.com/scripts/bzr-smart.fcgi
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
86
87
to::
88
2190.1.2 by John Arbash Meinel
Need the correct rewrite rule to get .bzr at the root of the exposed directory.
89
    RewriteRule ^(.*/|)\.bzr/smart$ /srv/example.com/scripts/bzr-smart.py
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
90
91
Like with mod_fastcgi, we also define how our script is to be handled::
92
93
    Alias /srv/example.com/scripts/bzr-smart.py /srv/example.com/scripts/bzr-smart.py
94
    <Directory /srv/example.com/scripts>
95
        <Files bzr-smart.py>
96
            PythonPath "sys.path+['/srv/example.com/scripts']"
97
            AddHandler python-program .py
2190.1.1 by John Arbash Meinel
Update the documentation so the smart server actually works with mod python.
98
            PythonHandler bzr-smart::handler
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
99
        </Files>
100
    </Directory>
101
102
This instructs Apache to hand requests for any URL ending with `/.bzr/smart`
103
inside `/code` to a Bazaar smart server via mod_python.
104
2706.1.3 by Aaron Bentley
Style tweakage and NEWS
105
NOTE: If you don't have bzrlib in your PATH, you will be need to change the
106
following line::
2706.1.1 by Martin Albisetti
updated smart server documentation
107
108
            PythonPath "sys.path+['/srv/example.com/scripts']"
109
2706.1.3 by Aaron Bentley
Style tweakage and NEWS
110
To::
2706.1.1 by Martin Albisetti
updated smart server documentation
111
112
            PythonPath "['/path/to/bzr']+sys.path+['/srv/example.com/scripts']"
113
114
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
115
Refer to the mod_python_ documentation for further information.
116
117
.. _mod_python: http://www.modpython.org/
118
119
5053.3.1 by Agustin Henze - TiN
Add example for mod_wsgi and other little corrections
120
mod_wsgi
121
~~~~~~~~
122
123
First, configure mod_wsgi, e.g. enabling the mod with a2enmod wsgi.
124
We need to change it to handle all requests for URLs ending in `.bzr/smart`.  It
125
will look like::
126
127
    WSGIScriptAliasMatch ^/code/.*/\.bzr/smart$ /srv/example.com/scripts/bzr.wsgi
128
5053.3.2 by Agustin Henze - TiN
Small fixes Andrew Bennetts
129
    #The three next lines allow regular GETs to work too
5053.3.1 by Agustin Henze - TiN
Add example for mod_wsgi and other little corrections
130
    RewriteEngine On
5053.3.2 by Agustin Henze - TiN
Small fixes Andrew Bennetts
131
    RewriteCond %{REQUEST_URI} !^/code/.*/\.bzr/smart$
132
    RewriteRule ^/code/(.*/\.bzr/.*)$ /srv/example.com/www/code/$1 [L]
5053.3.1 by Agustin Henze - TiN
Add example for mod_wsgi and other little corrections
133
134
    <Directory /srv/example.com/www/code>
135
        WSGIApplicationGroup %{GLOBAL}
136
    </Directory>
137
138
This instructs Apache to hand requests for any URL ending with `/.bzr/smart`
5053.3.3 by Agustin Henze - TiN
Added suggestions for Andrew Bennetts and revised the entire document
139
inside `/code` to a Bazaar smart server via WSGI, and any other URL inside
140
`/code` to be served directly by Apache.
5053.3.1 by Agustin Henze - TiN
Add example for mod_wsgi and other little corrections
141
142
Refer to the mod_wsgi_ documentation for further information.
143
144
.. _mod_wsgi: http://code.google.com/p/modwsgi/
145
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
146
Configuring Bazaar
147
------------------
148
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
149
FastCGI
150
~~~~~~~
151
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
152
We've configured Apache to run the smart server at
153
`/srv/example.com/scripts/bzr-smart.fcgi`.  This is just a simple script we need
154
to write to configure a smart server, and glue it to the FastCGI gateway.
155
Here's what it looks like::
156
157
    import fcgi
158
    from bzrlib.transport.http import wsgi
159
160
    smart_server_app = wsgi.make_app(
3702.3.1 by Jonathan Lange
Update the location of modpywsgi and the location of pocoo.
161
        root='/srv/example.com/www/code',
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
162
        prefix='/code/',
2190.1.4 by John Arbash Meinel
Add ability to enable writeable bzr+http access.
163
        path_var='REQUEST_URI',
3708.1.3 by Marius Kruger
note extra options to wsgi.make_app in docs
164
        readonly=True,
4853.1.1 by Patrick Regan
Removed trailing whitespace from files in doc directory
165
        load_plugins=True,
3708.1.3 by Marius Kruger
note extra options to wsgi.make_app in docs
166
        enable_logging=True)
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
167
168
    fcgi.WSGIServer(smart_server_app).run()
4853.1.1 by Patrick Regan
Removed trailing whitespace from files in doc directory
169
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
170
The `fcgi` module can be found at http://svn.saddi.com/py-lib/trunk/fcgi.py.  It
171
is part of flup_.
172
173
.. _flup: http://www.saddi.com/software/flup/
174
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
175
mod_python
176
~~~~~~~~~~
177
178
We've configured Apache to run the smart server at
179
`/srv/example.com/scripts/bzr-smart.py`.  This is just a simple script we need
180
to write to configure a smart server, and glue it to the mod_python gateway.
181
Here's what it looks like::
182
183
    import modpywsgi
184
    from bzrlib.transport.http import wsgi
185
186
    smart_server_app = wsgi.make_app(
3702.3.1 by Jonathan Lange
Update the location of modpywsgi and the location of pocoo.
187
        root='/srv/example.com/www/code',
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
188
        prefix='/code/',
2190.1.4 by John Arbash Meinel
Add ability to enable writeable bzr+http access.
189
        path_var='REQUEST_URI',
3708.1.3 by Marius Kruger
note extra options to wsgi.make_app in docs
190
        readonly=True,
4853.1.1 by Patrick Regan
Removed trailing whitespace from files in doc directory
191
        load_plugins=True,
3708.1.3 by Marius Kruger
note extra options to wsgi.make_app in docs
192
        enable_logging=True)
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
193
2190.1.1 by John Arbash Meinel
Update the documentation so the smart server actually works with mod python.
194
    def handler(request):
195
        """Handle a single request."""
196
        wsgi_server = modpywsgi.WSGIServer(smart_server_app)
197
        return wsgi_server.run(request)
4853.1.1 by Patrick Regan
Removed trailing whitespace from files in doc directory
198
3702.3.1 by Jonathan Lange
Update the location of modpywsgi and the location of pocoo.
199
The `modpywsgi` module can be found at
5053.3.1 by Agustin Henze - TiN
Add example for mod_wsgi and other little corrections
200
http://ice.usq.edu.au/svn/ice/trunk/apps/ice-server/modpywsgi.py. It was
3702.3.1 by Jonathan Lange
Update the location of modpywsgi and the location of pocoo.
201
part of pocoo_. You sould make sure you place modpywsgi.py in the same
202
directory as bzr-smart.py (ie. /srv/example.com/scripts/).
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
203
3702.3.1 by Jonathan Lange
Update the location of modpywsgi and the location of pocoo.
204
.. _pocoo: http://dev.pocoo.org/projects/pocoo/
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
205
5053.3.1 by Agustin Henze - TiN
Add example for mod_wsgi and other little corrections
206
207
mod_wsgi
208
~~~~~~~~
209
210
We've configured Apache to run the smart server at
211
`/srv/example.com/scripts/bzr.wsgi`.  This is just a simple script we need
212
to write to configure a smart server, and glue it to the WSGI gateway.
213
Here's what it looks like::
214
215
    from bzrlib.transport.http import wsgi
216
217
    def application(environ, start_response):
218
        app = wsgi.make_app(
219
            root="/srv/example.com/www/code/",
220
            prefix="/code",
5053.3.3 by Agustin Henze - TiN
Added suggestions for Andrew Bennetts and revised the entire document
221
            readonly=True,
5053.3.1 by Agustin Henze - TiN
Add example for mod_wsgi and other little corrections
222
            enable_logging=False)
223
        return app(environ, start_response)
224
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
225
Clients
226
-------
227
5053.3.2 by Agustin Henze - TiN
Small fixes Andrew Bennetts
228
Now you can use `bzr+http://` URLs or just `http://` URLs, e.g.::
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
229
230
    bzr log bzr+http://example.com/code/my-branch
231
232
Plain HTTP access should continue to work::
233
234
    bzr log http://example.com/code/my-branch
235
236
Advanced configuration
2977.1.1 by Ian Clatworthy
First cut at new look User Guide including chapters 1 and 2
237
----------------------
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
238
239
Because the Bazaar HTTP smart server is a WSGI application, it can be used with
240
any 3rd-party WSGI middleware or server that conforms the WSGI standard.  The
241
only requirements are:
242
243
  * to construct a `SmartWSGIApp`, you need to specify a **root transport** that it
244
    will serve.
245
  * each request's `environ` dict must have a **'bzrlib.relpath'** variable set.
246
247
The `make_app` helper used in the example constructs a `SmartWSGIApp` with a
248
transport based on the `root` path given to it, and calculates the
249
'bzrlib.relpath` for each request based on the `prefix` and `path_var`
250
arguments.  In the example above, it will take the 'REQUEST_URI' (which is set
251
by Apache), strip the '/code/' prefix and the '/.bzr/smart' suffix, and set that
252
as the 'bzrlib.relpath', so that a request for '/code/foo/bar/.bzr/smart' will
253
result in a 'bzrlib.relpath' of 'foo/bzr'.
254
255
It's possible to configure a smart server for a non-local transport, or that
256
does arbitrary path translations, etc, by constructing a `SmartWSGIApp`
257
directly.  Refer to the docstrings of `bzrlib.transport.http.wsgi` and the `WSGI
258
standard`_ for further information.
259
260
.. _WSGI standard: http://www.python.org/dev/peps/pep-0333/
261
2190.1.4 by John Arbash Meinel
Add ability to enable writeable bzr+http access.
262
5053.3.3 by Agustin Henze - TiN
Added suggestions for Andrew Bennetts and revised the entire document
263
Pushing over the http smart server
264
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2190.1.4 by John Arbash Meinel
Add ability to enable writeable bzr+http access.
265
266
It is possible to allow pushing data over the http smart server. The
267
easiest way to do this, is to just supply ``readonly=False`` to the
268
``wsgi.make_app()`` call. But be careful, because the smart protocol does
269
not contain any Authentication. So if you enable write support, you will
270
want to restrict access to ``.bzr/smart`` URLs to restrict who can
5053.3.3 by Agustin Henze - TiN
Added suggestions for Andrew Bennetts and revised the entire document
271
actually write data on your system, e.g. in apache it looks like::
272
273
    <Location /code>
274
        AuthType Basic
275
        AuthName "example"
276
        AuthUserFile /srv/example.com/conf/auth.passwd
277
        <LimitExcept GET>
278
            Require valid-user
279
        </LimitExcept>
280
    </Location>
281
282
At this time, it is not possible to allow some people to have read-only
283
access and others to have read-write access to the same urls. Because at
284
the HTTP layer (which is doing the Authenticating), everything is just a
285
POST request.  However, it would certainly be possible to have HTTPS
286
require authentication and use a writable server, and plain HTTP allow
287
read-only access.
288
289
If bzr gives an error like this when accessing your HTTPS site::
290
291
  bzr: ERROR: Connection error: curl connection error (server certificate verification failed.
292
  CAfile:/etc/ssl/certs/ca-certificates.crt CRLfile: none)
293
294
You can workaround it by using ``https+urllib`` rather than ``http`` in your
295
URL, or by uninstalling pycurl.  See `bug 82086`_ for more details.
5053.3.2 by Agustin Henze - TiN
Small fixes Andrew Bennetts
296
297
.. _bug 82086: https://bugs.launchpad.net/bzr/+bug/82086
2190.1.4 by John Arbash Meinel
Add ability to enable writeable bzr+http access.
298
4853.1.1 by Patrick Regan
Removed trailing whitespace from files in doc directory
299
..
2190.1.1 by John Arbash Meinel
Update the documentation so the smart server actually works with mod python.
300
   vim: ft=rst tw=74 et