GitWeb
Published on October 20, 2014.
GitWeb é o “servidor” padrão para o Git. Neste post você encontra como configurá-lo na sua máquina (porque eu sempre tive dificuldade em fazê-lo).
A configuração aqui apresentada precisa de inúmeras melhorias para funcionar adequadamente.
Instalação
Você precisa instalar:
- servidor http (iremos utilizar o Nginx)
- git e git-daemon
- gitweb
- fcgiwrap e spawn-fcgi
No Debian:
# apt-get install nginx git git-daemon-run gitweb fcgiwrap spawn-fcgi
No ArchLinux:
# pacman -S nginx git fcgiwrap spawn-fcgi
# yaourt -S gitweb
Configuração do Git Daemon
O objetivo do Git Daemon é permitir que pessoas clonem seus repositórios utilizando:
$ git clone git://git.seu.dominio/repositorio-de-teste.git
Para que as pessoas clonem utilizando :
$ git clone git@git.seu.dominio:repositorio-de-teste.git
é preciso que elas possuam a senha do usuário git ou outra forma de
autenticação (e.g. SSH Keys).
Se estiver utilizando systemd, edite o arquivo
/usr/lib/systemd/system/git-daemon@.service trocando /srv/git pelo
endereço onde seus repositórios Git estão localizados em :
ExecStart=-/usr/lib/git-core/git-daemon --inetd --base-path=/srv/git
Depois é só inicializar o daemon:
# systemctl start git-daemon.socket
Você provavelmente vai querer executar:
# systemctl enable git-daemon.socket
para que o servidor seja iniciado após o boot adequadamente.
Se estiver utilizando init script, você precisa alterar o arquivo
/etc/sv/git-daemon/run para ajustar o --base-path. Depois do ajuste,
você deve reiniciar o daemon.
Você talvez queira adicionar a opção --export-all para exportar todos
os repositórios Git.
Configuração Nginx
Para você conseguir testar, adicione:
127.0.1.1 git.seu.dominio nome-da-sua-maquina
em /etc/hosts.
Crie o arquivo /etc/nginx/sites-enabled/git contendo:
server {
server_name git.seu.dominio;
root /usr/share/gitweb;
location / {
index gitweb.cgi;
include fastcgi_params;
gzip off;
fastcgi_param DOCUMENT_ROOT /usr/share/gitweb/;
fastcgi_param SCRIPT_NAME gitweb.cgi;
fastcgi_param GITWEB_CONFIG /etc/conf.d/gitweb.conf;
if ($uri ~ "/gitweb.cgi") {
fastcgi_pass unix:/var/run/fcgiwrap.sock;
}
}
}
Verifique se todos os caminhos são válidos. No Debian você deve utilizar :
fastcgi_pass unix:/var/run/fcgiwrap.socket;
Configurando fcgiwrap
Se estiver utilizando systemd, altere o arquivo
/usr/lib/systemd/system/fcgiwrap.service para:
[Unit]
Description=Simple server for running CGI applications over FastCGI
After=syslog.target network.target
[Service]
Type=forking
Restart=on-abort
PIDFile=/var/run/fcgiwrap.pid
ExecStart=/usr/bin/spawn-fcgi -s /var/run/fcgiwrap.sock -P
/var/run/fcgiwrap.pid -u http -g http -- /usr/sbin/fcgiwrap
ExecStop=/usr/bin/kill -15 $MAINPID
[Install]
WantedBy=multi-user.target
Atualizando configurações
Se estiver utilizando systemd, :
# systemctl start nginx fcgiwrap
Você provavelmente vai querer executar:
# systemctl enable nginx fcgiwrap
para que o servidor seja iniciado após o boot adequadamente.
Se estiver utilizando init script, :
# service nginx restart
# service fcgiwrap restart
Configurando GitWeb
Altere o arquivo /etc/conf.d/gitweb.conf:
# path to git projects (<project>.git)
$projectroot = "/srv/git";
# directory to use for temp files
$git_temp = "/tmp";
# name of your site
$site_name = "Git Projects";
# label for the "home link" at the top of all pages.
$home_link_str = "git://git.seu.dominio";
# stylesheet to use
#@stylesheets = ("static/gitweb.css");
# javascript code for gitweb
#$javascript = "static/gitweb.js";
# logo to use
#$logo = "static/git-logo.png";
# the 'favicon'
#$favicon = "static/git-favicon.png";
# git-diff-tree(1) options to use for generated patches
#@diff_opts = ("-M");
@diff_opts = ();
Criando um repositório
Crie um repositório Git dentro de /srv/git:
# cd /srv/git
# git init --bare repositorio-de-teste.git
Testando
Abra git.seu.dominio no seu navegador web. Você deve encontrar o seu
repositorio-de-teste.git listado.
Referências
Tags: