/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
1
===========================
2
Serving Bazaar with FastCGI
3
===========================
4
2018.4.2 by Andrew Bennetts
Add security warning to http_smart_server.txt.
5
**This feature is EXPERIMENTAL and is NOT SECURE.  It will allow access to
6
arbitrary files on your server.**
7
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
8
This document describes one way to setup a Bazaar HTTP smart server, using
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
9
Apache 2.0 and FastCGI or mod_python.
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
10
11
Example
12
=======
13
14
You have a webserver already publishing `/srv/example.com/www/code` as
15
`http://example.com/code/...` with plain HTTP.  It contains bzr branches and
16
directories like `/srv/example.com/www/code/branch-one` and
2018.4.2 by Andrew Bennetts
Add security warning to http_smart_server.txt.
17
`/srv/example.com/www/code/my-repo/branch-two`.  You want to provide read-only
18
smart server access to these directories in addition to the existing HTTP
19
access.
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
20
21
Configuring Apache 2.0
22
----------------------
23
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
24
FastCGI
25
~~~~~~~
26
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
27
First, configure mod_fastcgi, e.g. by adding lines like these to your
28
httpd.conf::
29
30
    LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so
31
    FastCgiIpcDir /var/lib/apache2/fastcgi
32
    
33
In our example, we're already serving `/srv/example.com/www/code` at
34
`http://example.com/code`, so our existing Apache configuration would look
35
like::
36
37
    Alias /code /srv/example.com/www/code
38
    <Directory /srv/example.com/www/code>
39
        Options Indexes
40
        # ...
41
    </Directory>
42
43
We need to change it to handle all requests for URLs ending in `.bzr/smart`.  It
44
will look like::
45
46
    Alias /code /srv/example.com/www/code
47
    <Directory /srv/example.com/www/code>
48
        Options Indexes, FollowSymLinks
49
        RewriteEngine On
50
        RewriteBase /code
51
        RewriteRule ^(.*)/\.bzr/smart$ /srv/example.com/scripts/bzr-smart.fcgi
52
    </Directory>
53
    
2018.4.5 by Andrew Bennetts
Improvement thanks to John's review.
54
    # bzr-smart.fcgi isn't under the DocumentRoot, so Alias it into the URL
55
    # namespace so it can be executed.
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
56
    Alias /srv/example.com/scripts/bzr-smart.fcgi /srv/example.com/scripts/bzr-smart.fcgi
57
    <Directory /srv/example.com/scripts>
58
        Options ExecCGI
59
        <Files bzr-smart.fcgi>
60
            SetHandler fastcgi-script
61
        </Files>
62
    </Directory>
63
    
64
This instructs Apache to hand requests for any URL ending with `/.bzr/smart`
65
inside `/code` to a Bazaar smart server via FastCGI.
66
67
Refer to the mod_rewrite_ and mod_fastcgi_ documentation for further
68
information.
69
70
.. _mod_rewrite: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
71
.. _mod_fastcgi: http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html
72
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
73
mod_python
74
~~~~~~~~~~
75
76
First, configure mod_python, e.g. by adding lines like these to your
77
httpd.conf::
78
79
    LoadModule python_module /usr/lib/apache2/modules/mod_python.so
80
81
Define the rewrite rules with mod_rewrite the same way as for FastCGI, except
82
change::
83
84
    RewriteRule ^(.*)/\.bzr/smart$ /srv/example.com/scripts/bzr-smart.fcgi
85
86
to::
87
88
    RewriteRule ^(.*)/\.bzr/smart$ /srv/example.com/scripts/bzr-smart.py
89
90
Like with mod_fastcgi, we also define how our script is to be handled::
91
92
    Alias /srv/example.com/scripts/bzr-smart.py /srv/example.com/scripts/bzr-smart.py
93
    <Directory /srv/example.com/scripts>
94
        <Files bzr-smart.py>
95
            PythonPath "sys.path+['/srv/example.com/scripts']"
96
            AddHandler python-program .py
97
            PythonHandler bzr-smart
98
        </Files>
99
    </Directory>
100
101
This instructs Apache to hand requests for any URL ending with `/.bzr/smart`
102
inside `/code` to a Bazaar smart server via mod_python.
103
104
Refer to the mod_python_ documentation for further information.
105
106
.. _mod_python: http://www.modpython.org/
107
108
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
109
Configuring Bazaar
110
------------------
111
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
112
FastCGI
113
~~~~~~~
114
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
115
We've configured Apache to run the smart server at
116
`/srv/example.com/scripts/bzr-smart.fcgi`.  This is just a simple script we need
117
to write to configure a smart server, and glue it to the FastCGI gateway.
118
Here's what it looks like::
119
120
    import fcgi
121
    from bzrlib.transport.http import wsgi
122
123
    smart_server_app = wsgi.make_app(
124
        root='/srv/example.com/code',
125
        prefix='/code/',
126
        path_var='REQUEST_URI')
127
128
    fcgi.WSGIServer(smart_server_app).run()
129
        
130
The `fcgi` module can be found at http://svn.saddi.com/py-lib/trunk/fcgi.py.  It
131
is part of flup_.
132
133
.. _flup: http://www.saddi.com/software/flup/
134
2180.2.1 by Andrew Bennetts
Describe smart server configuration with mod_python.
135
mod_python
136
~~~~~~~~~~
137
138
We've configured Apache to run the smart server at
139
`/srv/example.com/scripts/bzr-smart.py`.  This is just a simple script we need
140
to write to configure a smart server, and glue it to the mod_python gateway.
141
Here's what it looks like::
142
143
    import modpywsgi
144
    from bzrlib.transport.http import wsgi
145
146
    smart_server_app = wsgi.make_app(
147
        root='/srv/example.com/code',
148
        prefix='/code/',
149
        path_var='REQUEST_URI')
150
151
    modpywsgi.WSGIServer(smart_server_app).run()
152
        
153
The `modpywsgi` module can be found at http://trac.pocoo.org/wiki/ModPyWsgi.  It
154
is part of pocoo_.
155
156
.. _pocoo: http://trac.pocoo.org/wiki/
157
2018.4.1 by Andrew Bennetts
Add WSGI smart server.
158
Clients
159
-------
160
161
Now you can use `bzr+http://` URLs, e.g.::
162
163
    bzr log bzr+http://example.com/code/my-branch
164
165
Plain HTTP access should continue to work::
166
167
    bzr log http://example.com/code/my-branch
168
169
170
Advanced configuration
171
======================
172
173
Because the Bazaar HTTP smart server is a WSGI application, it can be used with
174
any 3rd-party WSGI middleware or server that conforms the WSGI standard.  The
175
only requirements are:
176
177
  * to construct a `SmartWSGIApp`, you need to specify a **root transport** that it
178
    will serve.
179
  * each request's `environ` dict must have a **'bzrlib.relpath'** variable set.
180
181
The `make_app` helper used in the example constructs a `SmartWSGIApp` with a
182
transport based on the `root` path given to it, and calculates the
183
'bzrlib.relpath` for each request based on the `prefix` and `path_var`
184
arguments.  In the example above, it will take the 'REQUEST_URI' (which is set
185
by Apache), strip the '/code/' prefix and the '/.bzr/smart' suffix, and set that
186
as the 'bzrlib.relpath', so that a request for '/code/foo/bar/.bzr/smart' will
187
result in a 'bzrlib.relpath' of 'foo/bzr'.
188
189
It's possible to configure a smart server for a non-local transport, or that
190
does arbitrary path translations, etc, by constructing a `SmartWSGIApp`
191
directly.  Refer to the docstrings of `bzrlib.transport.http.wsgi` and the `WSGI
192
standard`_ for further information.
193
194
.. _WSGI standard: http://www.python.org/dev/peps/pep-0333/
195