Cgit: Difference between revisions

From Alpine Linux
m (→‎Installation: use pkg template.)
 
(19 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Draft}}
[https://git.zx2c4.com/cgit/ cgit] is a fast web-interface (CGI) for git written in the C programming language. It makes it possible for potential contributors to track and view project source code from the web instead of through a git client.


[http://hjemli.net/git/cgit/ cgit] is a CGI-application that was written in C and a web interface for git repositories provides.
== Installation ==
{{Note|It is very recommendable that you already have a directory with an active .git working in your server. If you don't have one, install [[gitolite]] or a similar program before going further.}}
Install the package that contains cgit and git.
{{Cmd|apk add {{pkg|cgit|arch=}} {{pkg|git|arch=}}}}


Running instance: [http://git.alpinelinux.org/ git.alpinelinux.org]
Open up /etc/cgitrc with your favorite editor, in this case is vim.
{{Cmd|vim /etc/cgitrc}}


== Lighttpd ==
If you want to show an specific repository your configuration should look something like this:
[[Lighttpd]]
{{Cat|/etc/cgitrc|<nowiki>virtual-root=/
repo.path=/var/lib/git/repositories/YOUR_GIT_REPO.git/
repo.url=CUSTOM_GIT_URL
</nowiki>}}


== cgit ==
If you want to scan and show all the repositories you have, your configuration should look something like this:
Install cgit
{{Cat|/etc/cgitrc|<nowiki>virtual-root=/
scan-path=/var/lib/git/repositories/
</nowiki>}}


{{cmd|apk add cgit git}}
=== Run cgit using spawn-fcgi and fcgiwrap ===
Install spawn-fcgi and fcgiwrap
{{Cmd|apk add fcgiwrap spawn-fcgi}}
Create a new service by doing a symbolic link.
{{Cmd|ln -s spawn-fcgi /etc/init.d/spawn-fcgi.cgit}}
{{Note|You should also modify the file and add -f after ${FCGI_PROGRAM} on line 99.  Otherwise you will have no log and problems will be impossible to debug.}}
Create a configuration file called spawn-fcgi.cgit in /etc/conf.d/ ; the service will run fcgiwrap automatically everytime is called. It should look exactly like this:
{{Cat|/etc/conf.d/spawn-fcgi.cgit|<nowiki>FCGI_PORT=1234
FCGI_PROGRAM=/usr/bin/fcgiwrap
</nowiki>}}
{{Note|You should consider using unix domain sockets instead.}}
Start the newly created service.
{{Cmd|rc-service spawn-fcgi.cgit start}}


Initialize a sample git repository
== Run cgit with a web service ==


{{cmd|git init --bare /var/git/sample.git}}
=== Configure Lighttpd to work with cgit ===
Install the package that contains lighttpd if you haven't already.
{{Cmd|apk add lighttpd}}


Edit the /etc/cgitrc file:
Create a cgit.conf file into the lighttpd directory with the following content:
{{cmd|vi /etc/cgitrc}}
{{Cat|/etc/lighttpd/cgit.conf|<nowiki>server.modules += ("mod_redirect",
                  "mod_alias",
                  "mod_cgi",
                  "mod_fastcgi",
                  "mod_rewrite" )


And make sure you have at least the following lines:
var.webapps  = "/usr/share/webapps/"
$HTTP["url"] =~ "^/cgit" {
    server.document-root = webapps
    server.indexfiles = ("cgit.cgi")
    cgi.assign = ("cgit.cgi" => "")
    mimetype.assign = ( ".css" => "text/css" )
}
url.redirect = (
    "^/git/(.*)$" => "/cgit/cgit.cgi/$1",
)
</nowiki>}}


{{Cat|/etc/cgitrc|
Finally, add the following line to the lighttpd.conf file:
scan-path=/var/git/  
{{Cat|/etc/lighttpd/lighttpd.conf|<nowiki>include "cgit.conf"
enable-git-config=1
</nowiki>}}
}}


Uncomment this line, if you want to store the repository in its own file
Restart the lighttpd service.
{{Cmd|rc-service lighttpd restart}}


include=/etc/cgitrepos
=== Configure NGINX to work with cgit pointing to a subdomain ===


Create the file
Install the package that contains NGINX if you haven't already.
{{Cmd|apk add nginx}}


{{cmd|touch /etc/cgitrepos}}
Create a custom configuration in the NGINX's conf.d directory.
 
{{Cmd|vim /etc/nginx/conf.d/git.your_domain.com.conf}}
Now add every repository
 
<pre>
repo.url=sample
repo.path=/var/git/sample.git
repo.desc=Sample master foo repository
repo.owner=sample@example.com
repo.readme=info/web/about.html
</pre>
 
If you want to group your repositories, add the every repository to a group.
 
repo.group=Sample group


The file should look something like this:


{{Cat|/etc/nginx/conf.d/git.your_domain.com.conf|<nowiki>server {
    server_name git.your_domain.com;
    root /usr/share/webapps/cgit;
    try_files $uri @cgit;
    location @cgit {
        include fastcgi_params;
        fastcgi_pass localhost:1234;
        fastcgi_param SCRIPT_FILENAME $document_root/cgit.cgi;
        fastcgi_param PATH_INFO $uri;
        fastcgi_param QUERY_STRING $args;
        }
}
</nowiki>}}
Restart the NGINX service.
{{Cmd|rc-service nginx restart}}


[[Category:Server]]
[[Category:Server]]
[[Category:Git]]
[[Category:Git]]

Latest revision as of 05:36, 4 March 2024

cgit is a fast web-interface (CGI) for git written in the C programming language. It makes it possible for potential contributors to track and view project source code from the web instead of through a git client.

Installation

Note: It is very recommendable that you already have a directory with an active .git working in your server. If you don't have one, install gitolite or a similar program before going further.

Install the package that contains cgit and git.

apk add cgit git

Open up /etc/cgitrc with your favorite editor, in this case is vim.

vim /etc/cgitrc

If you want to show an specific repository your configuration should look something like this:

Contents of /etc/cgitrc

virtual-root=/ repo.path=/var/lib/git/repositories/YOUR_GIT_REPO.git/ repo.url=CUSTOM_GIT_URL

If you want to scan and show all the repositories you have, your configuration should look something like this:

Contents of /etc/cgitrc

virtual-root=/ scan-path=/var/lib/git/repositories/

Run cgit using spawn-fcgi and fcgiwrap

Install spawn-fcgi and fcgiwrap

apk add fcgiwrap spawn-fcgi

Create a new service by doing a symbolic link.

ln -s spawn-fcgi /etc/init.d/spawn-fcgi.cgit

Note: You should also modify the file and add -f after ${FCGI_PROGRAM} on line 99. Otherwise you will have no log and problems will be impossible to debug.

Create a configuration file called spawn-fcgi.cgit in /etc/conf.d/ ; the service will run fcgiwrap automatically everytime is called. It should look exactly like this:

Contents of /etc/conf.d/spawn-fcgi.cgit

FCGI_PORT=1234 FCGI_PROGRAM=/usr/bin/fcgiwrap
Note: You should consider using unix domain sockets instead.

Start the newly created service.

rc-service spawn-fcgi.cgit start

Run cgit with a web service

Configure Lighttpd to work with cgit

Install the package that contains lighttpd if you haven't already.

apk add lighttpd

Create a cgit.conf file into the lighttpd directory with the following content:

Contents of /etc/lighttpd/cgit.conf

server.modules += ("mod_redirect", "mod_alias", "mod_cgi", "mod_fastcgi", "mod_rewrite" ) var.webapps = "/usr/share/webapps/" $HTTP["url"] =~ "^/cgit" { server.document-root = webapps server.indexfiles = ("cgit.cgi") cgi.assign = ("cgit.cgi" => "") mimetype.assign = ( ".css" => "text/css" ) } url.redirect = ( "^/git/(.*)$" => "/cgit/cgit.cgi/$1", )

Finally, add the following line to the lighttpd.conf file:

Contents of /etc/lighttpd/lighttpd.conf

include "cgit.conf"

Restart the lighttpd service.

rc-service lighttpd restart

Configure NGINX to work with cgit pointing to a subdomain

Install the package that contains NGINX if you haven't already.

apk add nginx

Create a custom configuration in the NGINX's conf.d directory.

vim /etc/nginx/conf.d/git.your_domain.com.conf

The file should look something like this:

Contents of /etc/nginx/conf.d/git.your_domain.com.conf

server { server_name git.your_domain.com; root /usr/share/webapps/cgit; try_files $uri @cgit; location @cgit { include fastcgi_params; fastcgi_pass localhost:1234; fastcgi_param SCRIPT_FILENAME $document_root/cgit.cgi; fastcgi_param PATH_INFO $uri; fastcgi_param QUERY_STRING $args; } }

Restart the NGINX service.

rc-service nginx restart