Cgit: Difference between revisions

From Alpine Linux
(trimmed newlines in Cat templates)
Line 10: Line 10:


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


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


=== Run cgit using spawn-fcgi and fcgiwrap ===
=== Run cgit using spawn-fcgi and fcgiwrap ===
Line 28: Line 24:
{{Cmd|ln -s /etc/init.d/spawn-fcgi /etc/init.d/spawn-fcgi.cgit}}
{{Cmd|ln -s /etc/init.d/spawn-fcgi /etc/init.d/spawn-fcgi.cgit}}
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:
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>
{{Cat|/etc/conf.d/spawn-fcgi.cgit|<nowiki>FCGI_PORT=1234
FCGI_PORT=1234
FCGI_PROGRAM=/usr/bin/fcgiwrap
FCGI_PROGRAM=/usr/bin/fcgiwrap
</nowiki>
</nowiki>}}
}}
Start the newly created service.
Start the newly created service.
{{Cmd|rc-service spawn-fcgi.cgit start}}
{{Cmd|rc-service spawn-fcgi.cgit start}}
Line 43: Line 37:


Create a cgit.conf file into the lighttpd directory with the following content:
Create a cgit.conf file into the lighttpd directory with the following content:
{{Cat|/etc/lighttpd/cgit.conf|<nowiki>
{{Cat|/etc/lighttpd/cgit.conf|<nowiki>server.modules += ("mod_redirect",
server.modules += ("mod_redirect",
                   "mod_alias",
                   "mod_alias",
                   "mod_cgi",
                   "mod_cgi",
Line 60: Line 53:
     "^/git/(.*)$" => "/cgit/cgit.cgi/$1",
     "^/git/(.*)$" => "/cgit/cgit.cgi/$1",
)
)
</nowiki>
</nowiki>}}
}}


Finally, add the following line to the lighttpd.conf file:
Finally, add the following line to the lighttpd.conf file:
{{Cat|/etc/lighttpd/lighttpd.conf|<nowiki>include "cgit.conf"
{{Cat|/etc/lighttpd/lighttpd.conf|<nowiki>include "cgit.conf"
</nowiki>
</nowiki>}}
}}


Restart the lighttpd service.
Restart the lighttpd service.
Line 81: Line 72:
The file should look something like this:
The file should look something like this:


{{Cat|/etc/nginx/conf.d/git.your_domain.com.conf|<nowiki>
{{Cat|/etc/nginx/conf.d/git.your_domain.com.conf|<nowiki>server {
server {
     server_name git.your_domain.com;
     server_name git.your_domain.com;
     root /usr/share/webapps/cgit;
     root /usr/share/webapps/cgit;
Line 94: Line 84:
         }
         }
}
}
</nowiki>
</nowiki>}}
}}
Restart the NGINX service.
Restart the NGINX service.
{{Cmd|rc-service nginx restart}}
{{Cmd|rc-service nginx restart}}

Revision as of 21:29, 2 July 2023

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

Create a new service by doing a symbolic link.

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

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

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_FILE $document_root/cgit.cgi; fastcgi_param PATH_INFO $uri; fastcgi_param QUERY_STRING $args; } }

Restart the NGINX service.

rc-service nginx restart