Apache ã使ã£ã¦ Bazaar ãµã¼ãã¼ããã¦ã ========================================= ãã®ããã¥ã¡ã³ãã§ã¯ã Apache 2.0 㨠FastCGI, mod_python, mod_wsgi ã® ã©ãããå©ç¨ã㦠Bazaar ã® HTTP ã¹ãã¼ããµã¼ãã¼ãã»ããã¢ããããæ¹æ³ã 説æãã¾ãã ã¹ãã¼ããµã¼ãã¼ã«é¢ãã詳細ãªæ å ±ã¨ãããè¨å®ããä»ã®æ¹æ³ã«é¢ãã¦ã¯ã `ã¹ãã¼ããµã¼ãã¼ã®ããã¥ã¡ã³ã <server.html>`_ ãåç §ãã¦ãã ããã ä¾ --- ãã¬ã¼ã³ãªHTTP㧠`/srv/example.com/www/code` ã `http://example.com/code/...` ã¨ã㦠ãã§ã«å ¬éãã¦ããã¨ãã¾ããããã¯bzrã®ãã©ã³ã㨠`/srv/example.com/www/code/branch-one` 㨠`/srv/example.com/www/code/my-repo/branch-two` ã®ãããªãã£ã¬ã¯ããªãå«ã¿ã¾ãã æ¢åã®HTTPå½¢å¼ã®ã¢ã¯ã»ã¹æ¨©éã«å ãã¦ãªã¼ããªã³ãªã¼ã®ã¹ãã¼ããµã¼ãã¼ã®ã¢ã¯ã»ã¹æ¨©éã ãããã®ãã£ã¬ã¯ããªã«æä¾ãããå ´åãèãã¾ãã Apache 2.0ãè¨å®ãã -------------------- FastCGI ~~~~~~~ æåã«ãmod_fastcgiãè¨å®ãã¾ãããã¨ãã°æ¬¡ã®è¡ãhttpd.confã«è¿½å ãã¾ã:: LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so FastCgiIpcDir /var/lib/apache2/fastcgi æã ã®ä¾ã§ã¯ã`http://example.com/code` 㧠`/srv/example.com/www/code` ããã§ã«æä¾ãã¦ããã®ã§ æ¢åã®Apacheã®è¨å®ã¯æ¬¡ã®ããã«ãªãã¾ã:: Alias /code /srv/example.com/www/code <Directory /srv/example.com/www/code> Options Indexes # ... </Directory> .bzr/smartã®å½¢å¼ã§çµããURLã«å¯¾ãããã¹ã¦ã®ãªã¯ã¨ã¹ããæ±ããã㫠次ã®ããã«å¤æ´ããå¿ è¦ãããã¾ã:: Alias /code /srv/example.com/www/code <Directory /srv/example.com/www/code> Options Indexes FollowSymLinks RewriteEngine On RewriteBase /code RewriteRule ^(.*/)?\.bzr/smart$ /srv/example.com/scripts/bzr-smart.fcgi </Directory> # bzr-smart.fcgiã¯DocumentRootã®å ã«åå¨ããªãã®ã§ãå®è¡ãããããã« # Aliasã¯ãããURLã®åå空éã®ã¨ã¤ãªã¢ã¹ã«ããã Alias /srv/example.com/scripts/bzr-smart.fcgi /srv/example.com/scripts/bzr-smart.fcgi <Directory /srv/example.com/scripts> Options ExecCGI <Files bzr-smart.fcgi> SetHandler fastcgi-script </Files> </Directory> ãã®è¨å®ã¯FastCGIãéã㦠`/code` å é¨ã® `/.bzr/smart` ã§çµããURLã«å¯¾ãã Bazaarã®ã¹ãã¼ããµã¼ãã¼ã¸ã®ãªã¯ã¨ã¹ããæ±ãããã«Apacheã«æ示ãã¾ãã 詳細ãªæ å ±ã¯ mod_rewrite_ 㨠mod_fastcgi_ ã®ããã¥ã¡ã³ããåç §ãã¦ãã ããã .. _mod_rewrite: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html .. _mod_fastcgi: http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html mod_python ~~~~~~~~~~ æåã«ã次ã®ãããªã³ã¼ãã httpd.conf ã«è¿½å ã㦠mod_python ãè¨å®ãã¾ã:: LoadModule python_module /usr/lib/apache2/modules/mod_python.so FastCGI ã¨åãæ¹æ³ã§ mod_rewrite ãç¨ãã¦æ¸ãæãã«ã¼ã«ãå®ç¾©ãã¾ã:: RewriteRule ^(.*/)?\.bzr/smart$ /srv/example.com/scripts/bzr-smart.fcgi å¤æ´ã¯æ¬¡ã®ããã«ãªãã¾ã:: RewriteRule ^(.*/)?\.bzr/smart$ /srv/example.com/scripts/bzr-smart.py mod_fastcgi ã®ããã«ãã¹ã¯ãªãããã©ã®ããã«æ±ãããã®ããå®ç¾©ãã¾ã:: Alias /srv/example.com/scripts/bzr-smart.py /srv/example.com/scripts/bzr-smart.py <Directory /srv/example.com/scripts> <Files bzr-smart.py> PythonPath "sys.path+['/srv/example.com/scripts']" AddHandler python-program .py PythonHandler bzr-smart::handler </Files> </Directory> ãã®è¨å®ã¯ mod_python ãéã㦠`/code` å é¨ã® `/.bzr/smart` ã§çµããURLã«å¯¾ãããªã¯ã¨ã¹ãã Bazaar ã®ã¹ãã¼ããµã¼ãã¼ã«æ¸¡ãããã«æ示ãã¾ãã 注: bzrlib ã PATH ã®ä¸ã«åå¨ããªãå ´åã次ã®è¡ãå¤æ´ããå¿ è¦ãããã¾ã:: PythonPath "sys.path+['/srv/example.com/scripts']" å¤æ´å¾ã¯æ¬¡ã®ããã«ãªãã¾ã:: PythonPath "['/path/to/bzr']+sys.path+['/srv/example.com/scripts']" 詳細ãªæ å ±ã¯ mod_python_ ã®ããã¥ã¡ã³ããåç §ãã¦ãã ããã .. _mod_python: http://www.modpython.org/ mod_wsgi ~~~~~~~~ æåã«ã a2enmod wsgi ãªã©ã§ mod_wsgi ãæå¹ã«ãã¦ããã¾ãã 次ã«ã `.bzr/smart` ã§çµããå ¨ã¦ã® URL ã«å¯¾ãããªã¯ã¨ã¹ãã mod_wsgi çµç± ã§å¦çããããã«è¨å®ãã¾ããè¨å®ä¾ã¯æ¬¡ã®ããã«ãªãã¾ãã :: WSGIScriptAliasMatch ^/code/.*/\.bzr/smart$ /srv/example.com/scripts/bzr.wsgi #The three next lines allow regular GETs to work too RewriteEngine On RewriteCond %{REQUEST_URI} !^/code/.*/\.bzr/smart$ RewriteRule ^/code/(.*/\.bzr/.*)$ /srv/example.com/www/code/$1 [L] <Directory /srv/example.com/www/code> WSGIApplicationGroup %{GLOBAL} </Directory> ãã®è¨å®ã§ã¯ã Apache 㯠`/code` 以ä¸ã® `/.bzr/smart` ã§çµãã URL 㫠対ããå ¨ã¦ã®ãªã¯ã¨ã¹ãã WSGI çµç±ã§ Bazaar ã®ã¹ãã¼ããµã¼ãã¼ã«æ¸¡ãã ãã以å¤ã®å ¨ã¦ã®ãªã¯ã¨ã¹ã㯠Apache ãç´æ¥æ±ãããã«ãã¦ãã¾ãã 詳細㯠mod_wsgi_ ã®ããã¥ã¡ã³ããåç §ãã¦ãã ããã .. _mod_wsgi: http://code.google.com/p/modwsgi/ Bazaarãè¨å®ãã ----------------- FastCGI ~~~~~~~ `/srv/example.com/scripts/bzr-smart.fcgi` ã§ã¹ãã¼ããµã¼ãã¼ãå®è¡ããããã«Apacheãè¨å®ãã¾ããã ããã¯ã¹ãã¼ããµã¼ãã¼ãè¨å®ããããã«æ¸ãå¿ è¦ã®ããåãªãã·ã³ãã«ãªã¹ã¯ãªãã㧠ãµã¼ãã¼ãFastCGIã®ã²ã¼ãã¦ã§ã¤ã«çµã³ã¤ãã¾ãã次ã®ããã«ãªãã¾ã:: import fcgi from bzrlib.transport.http import wsgi smart_server_app = wsgi.make_app( root='/srv/example.com/www/code', prefix='/code/', path_var='REQUEST_URI', readonly=True, load_plugins=True, enable_logging=True) fcgi.WSGIServer(smart_server_app).run() ã`fcgi` ã®ã¢ã¸ã¥ã¼ã«ã¯http://svn.saddi.com/py-lib/trunk/fcgi.pyã§è¦ã¤ããã¾ãã ãã㯠flup_ ã®ä¸é¨ã§ãã .. _flup: http://www.saddi.com/software/flup/ mod_python ~~~~~~~~~~ `/srv/example.com/scripts/bzr-smart.py` ã§ã¹ãã¼ããµã¼ãã¼ãå®è¡ããããã«Apacheãè¨å®ãã¾ããã ããã¯ã¹ãã¼ããµã¼ãã¼ãè¨å®ããããã«æ¸ãå¿ è¦ã®ããã·ã³ãã«ãªã¹ã¯ãªããã§ãµã¼ãã¼ãmod_pythonã® ã²ã¼ãã¦ã§ã¤ã«çµã³ã¤ãã¾ãã次ã®ããã«ãªãã¾ã:: import modpywsgi from bzrlib.transport.http import wsgi smart_server_app = wsgi.make_app( root='/srv/example.com/www/code', prefix='/code/', path_var='REQUEST_URI', readonly=True, load_plugins=True, enable_logging=True) def handler(request): """Handle a single request.""" wsgi_server = modpywsgi.WSGIServer(smart_server_app) return wsgi_server.run(request) `modpywsgi` ã¢ã¸ã¥ã¼ã«ã¯ http://ice.usq.edu.au/svn/ice/trunk/apps/ice-server/modpywsgi.py ã§è¦ã¤ããã¾ãã ãã㯠pocoo_ ã®ä¸é¨ã§ããã modpywsgi.py ã bzr-smart.py ã¨åããã£ã¬ã¯ã㪠(ããªãã¡/srv/example.com/scripts/)ã«è¨ç½®ãã¦ãããã¨ã確èªãã¦ãã ããã .. _pocoo: http://dev.pocoo.org/projects/pocoo/ mod_wsgi ~~~~~~~~ We've configured Apache to run the smart server at `/srv/example.com/scripts/bzr.wsgi`. This is just a simple script we need to write to configure a smart server, and glue it to the WSGI gateway. Here's what it looks like:: from bzrlib.transport.http import wsgi def application(environ, start_response): app = wsgi.make_app( root="/srv/example.com/www/code/", prefix="/code", readonly=True, enable_logging=False) return app(environ, start_response) ã¯ã©ã¤ã¢ã³ã ------------ ãã㧠`bzr+http://` å½¢å¼ã®URLããã ã® `http://` ã®URLãå©ç¨ã§ãã¾ã:: bzr log bzr+http://example.com/code/my-branch ãã¬ã¼ã³ãªHTTPå½¢å¼ã®ã¢ã¯ã»ã¹ãæç¶ãã¾ã:: bzr log http://example.com/code/my-branch é«åº¦ãªè¨å® ----------- Bazaarã®HTTPã¹ãã¼ããµã¼ãã¼ã¯WSGIã¢ããªã±ã¼ã·ã§ã³ãªã®ã§ã WSGIæ¨æºã«æºæ ãããµã¼ããã¼ãã£ã®WSGIã®ããã«ã¦ã§ã¢ãããã¯ãµã¼ãã¼ã§å©ç¨ã§ãã¾ãã å¯ä¸ã®è¦ä»¶ã¯ä»¥ä¸ã®ã¨ããã§ã: * `SmartWSGIApp` ãã³ã³ã¹ãã©ã¯ãããããã«ã¯ããããæä¾ãã **root transport** ãæå®ããå¿ è¦ãããã¾ãã * ããããã®ãªã¯ã¨ã¹ãã® `environ` dict 㯠**'bzrlib.relpath'** å¤æ°ã®è¨å®ãæããªããã°ãªãã¾ããã ãã®ä¾ã§ä½¿ããã¦ãã `make_app` ãã«ãã¼ã¯ ããã«æ¸¡ããã `root` ãã¹ã«åºã¥ãããã©ã³ã¹ãã¼ããä¼´ã `SmartWSGIApp` ãã³ã³ã¹ãã©ã¯ãããå¼æ° `prefix` ã¨`path_var` ã«åºã¥ãããããã®ãªã¯ã¨ã¹ãã«å¯¾ãã ã`bzrlib.relpath` ãç®åºãã¾ãã ä¸è¨ã®ä¾ã«ããã¦ããã㯠(Apacheã«ãã£ã¦è¨å®ããã)'REQUEST_URI' ãåããæ¥é è¾ã® '/code/' ã¨æ¥å°¾è¾ã® '/.bzr/smart' ãã¯ãåããããã 'bzrlib.relpath' ã¨ãã¦è¨å®ããã®ã§ã '/code/foo/bar/.bzr/smart' ã«å¯¾ãããªã¯ã¨ã¹ã㯠'foo/bzr' ã® 'bzrlib.relpath' ã«ãªãã¾ãã `SmartWSGIApp` ãç´æ¥ã³ã³ã¹ãã©ã¯ããããã¨ã§ããã¼ã«ã«ã§ã¯ãªããã©ã³ã¹ãã¼ãã«å¯¾ã㦠ã¹ãã¼ããµã¼ãã¼ãè¨å®ãããããã¯ä»»æä»»æã®ãã¹ã®å¤æãè¡ããã¨ã¯å¯è½ã§ãã 詳細ãªæ å ±ã«é¢ãã¦ã¯ `bzrlib.transport.http.wsgi` ã®docstrings㨠`WSGIæ¨æº`_ ãåç §ãã¦ãã ããã .. _WSGIæ¨æº: http://www.python.org/dev/peps/pep-0333/ HTTP ã¹ãã¼ããµã¼ãã¼çµç±ã§ push ãã ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HTTP ã¹ãã¼ããµã¼ãã¼ãéãã¦ãã¼ã¿ãããã·ã¥ãããã¨ã¯å¯è½ã§ãã ãããè¡ãããã®æãç°¡åãªæ¹æ³ã¯ã ``wsgi.make_app()`` ã³ã¼ã«ã« ``readonly=False`` ã æä¾ããã ãã§ãããã ããã¹ãã¼ããããã³ã«ã¯èªè¨¼æ©è½ãå«ã¾ããªãã®ã§æ³¨æãã¦ãã ããã æ¸ãè¾¼ã¿ã®ãµãã¼ããæå¹ã«ããå ´åã å®éã«ã·ã¹ãã ä¸ã®ãã¼ã¿ãæ¸ãè¾¼ã¿ã§ãã人ãå¶éããããã«ã ``.bzr/smart`` URLã¸ã®æ¨©éãå¶éããã¨ããã§ããããä¾ãã° Apache ã§æ¬¡ã®ãããªè¨å®ã ãã¾ãã :: <Location /code> AuthType Basic AuthName "example" AuthUserFile /srv/example.com/conf/auth.passwd <LimitExcept GET> Require valid-user </LimitExcept> </Location> ç¾æç¹ã§ã¯ãåãURLã«å¯¾ãã¦èªã¿è¾¼ã¿éå®ã®äººã¨èªã¿è¾¼ã¿ã¨æ¸ãè¾¼ã¿ã®äººã åãããã¨ã¯ã§ãã¾ããã (èªè¨¼ãè¡ã)HTTPã¬ã¤ã¤ã¼ã«ããã¦ããã¹ã¦ã¯åãªãPOSTãªã¯ã¨ã¹ãã ããã§ãã ããããªãããHTTPSã¢ã¯ã»ã¹ã®å ´åã«èªè¨¼ãå¿ è¦ãªæ¸ãè¾¼ã¿ãµã¼ãã¼ã使ãã ãã¬ã¼ã³ãªHTTPã¯èªã¿è¾¼ã¿éå®ã®ã¢ã¯ã»ã¹ã許å¯ãããã¨ã¯ã§ãã¾ãã HTTPS ãµã¤ãã«å¯¾ãã¦ã¢ã¯ã»ã¹ããã¨ãã« bzr ã次ã®ãããªã¨ã©ã¼ã表示ãã å ´å:: bzr: ERROR: Connection error: curl connection error (server certificate verification failed. CAfile:/etc/ssl/certs/ca-certificates.crt CRLfile: none) You can workaround it by using ``https+urllib`` rather than ``http`` in your URL, or by uninstalling pycurl. See `bug 82086`_ for more details. URL ã« ``https`` ã®ä»£ããã« ``https+urllib`` ã使ããã¨ã§åé¡ãåé¿ ã§ãã¾ãã 詳細ã«ã¤ãã¦ã¯ `bug 82086`_ ãåç §ãã¦ãã ããã .. _bug 82086: https://bugs.launchpad.net/bzr/+bug/82086 .. vim: ft=rst tw=74 et