Recently, I accidentally found out that BitBucket, where my Mercurial repositories are located, stops supporting Mercurial: itโs no longer possible to create new repositories, and existing ones will be deleted from 1.06.2020. Possible options: go to Git, choose one of the other services , or set up Mercurial hosting on your server. I have a server, I donโt want to give up Mercurial and change my habits, I didnโt like the alternatives to BitBucket either, so I chose the last option. The task seems to be simple, only the server is under Windows, and it seems that during the setup process I managed to step on the maximum possible rake. Hope this article helps someone avoid this and save some time.
Various options for organizing Mercurial hosting are described in the documentation . They can be divided into 3 groups:
- hg serve - i.e. Mercurial itself starts in server mode.
- HgWeb.cgi is the official script included in the Mercurial distribution.
- Solutions from external developers are more functional, but with their limitations and often paid.
HG SERVE
The simplest and most logical is the 1st option. According to the documentation, Mercurial has a built-in web server that runs HgWeb - this is what works when we run hg serve . This server does not know how to do authentication, i.e. can not request user login / password, but can do authorization, i.e. give / not give this or that type of access to repositories in accordance with access settings. If we need private repositories, then for authentication we can use Nginx as a proxy server that will request a password. Setting up such a circuit is described here .
For convenience, hg serve is launched in the form of a service using winsw , a utility that allows you to run any command in the form of a service (in this case, this is generally a bat file). However, to launch it is possible to do without a service, and, for example, create a task in the Task Scheduler with the trigger "At system startup" - such a task will be launched at system startup. But this is a less reliable option: in case of failure the task will not be restarted, and there will be no information about this in the logs.
Be careful with the configuration files (hgweb.conf / hgrc):
- Their contents are case sensitive: if, for example, you write
[Web]
instead [web]
, it wonโt work. - The equal sign must be surrounded by spaces: if you write
push_ssl=false
, it wonโt work, you need to write push_ssl = false
.
, Mercurial push , "Hello world", . Nginx :
client_max_body_size 500M;
proxy_read_timeout 120s;
, , .
hgweb.conf . ( ), : /.hg/hgrc , , , .
, Mercurial , Nginx. : Mercurial , Nginx . Nginx :
proxy_set_header REMOTE_USER $remote_user;
:
proxy_set_header X-Forwarded-User $remote_user;
:( HgWeb, ENV('REMOTE_USER'), โ .
, Nginx 2 ( ) hg serve, hgweb.conf
. , hgweb.conf
( ) . , . .
HgWeb.cgi
, Python- HgWeb. Mercurial , . , (CGI) , โ WSGI FCGI.
Nginx CGI, WSGI WSGI- ( Windows ), FCGI โ FastCGI. Python, , Python , Mercurial โ 2.7. , 2.7. HgWeb Python Flup, , ( Python 2.7). :
pip install flup==1.0.3.dev-20110405
hgweb.fcgi โ ( ) , ( ):
WSGIServer(application, bindAddress=("127.0.0.1",5500)).run()
Nginx:
location / {
auth_basic "My Repos";
auth_basic_user_file passwd;
include fastcgi.conf;
fastcgi_split_path_info ^()(.*)$;
fastcgi_param SCRIPT_NAME "";
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param AUTH_USER $remote_user;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_pass 127.0.0.1:5500;
}
location /static/ {
root e:/Mercurial/templates;
}
fastcgi.conf
, fastcgi location
. PATH_INFO
โ . url , PATH_INFO.
:
python hgweb.fcgi
!
hg serve, HgWeb . winsw. bat-:
@echo off
if "%1"=="start" (goto :start)
:stop
taskkill /F /IM python-hg.exe /T
goto :end
:start
"c:\Python27\python-hg.exe" e:\Mercurial-5.3\hgweb.fcgi
:end
, python.exe
python-hg.exe
taskkill
.
: "Local System" โ ! , .
, HgWeb ( hg serve) . : , , Nginx location
. :
location /Base/ {
include fastcgi.conf;
fastcgi_split_path_info ^()(.*)$;
fastcgi_param SCRIPT_NAME "";
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param AUTH_USER "pub";
fastcgi_param REMOTE_USER "pub";
fastcgi_pass 127.0.0.1:5500;
}
โ Base
.
, . ( , Python , , :-)