summaryrefslogblamecommitdiff
path: root/docs/server/cgit.md
blob: 72db5ed8c8474dbfca679edc7eda070c1943dea3 (plain) (tree)












































































































































                                                                                                                                                                                                         
# Cgit with gitolite and caddy

## Setup

Install dependencies.

	# apt install cgit python-is-python3 python3-pygments python3-markdown docutils-common groff perl

Make a git user.

	sudo adduser --system --shell /bin/bash --group --disabled-password --home /home/git git

Allow ssh passwordless login.

	usermod -p '*' username
	
## Gitolite

Install the [gitolite](https://gitolite.com/gitolite/install.html) package from the repository directly.

### Configuration with cgit

Configuration of gitolite is done by modifying `$HOME/.gitolite.rc`.

To work correctly with cgit, gitweb and cgit configuration options need to work with gitolite.

Change:

	GIT_CONFIG_KEYS  =>  '',
	
To:

	GIT_CONFIG_KEYS  =>  '.*',

To have permissions work correctly,

Change:

	UMASK  =>  0077,
	
To:

	UMASK  =>  0027,
	
In the `ENABLE` field, add gitweb and cgit to the list.

### Usage

Detailed usage of gitolite can be found [here](https://gitolite.com/gitolite/basic-admin.html)

### Repository ignore

After cgit is configured, cgit can be told to ignore a repo with this syntax.

	repo gitolite-admin
		config cgit.ignore=1

### Adding Hooks to gitolite

This [page](https://gitolite.com/gitolite/cookbook#adding-other-non-update-hooks) details how to add hooks to your repositories.

Example hook that updates a website every git push. Make sure this directory is owned by git.

	#!/bin/sh
	GIT_WORK_TREE=/desired/website/directory git checkout -f
	
	
## Cgit

### Running cgit with caddy

Install the [fcgiwrap](https://packages.debian.org/bookworm/fcgiwrap) package.

Create a systemd service that wraps cgit with FastCGI.

	# systemctl edit --full --force cgit.service
	
<!-- tsk -->

	[Unit]
	Description=CGI web interface to the Git SCM
	After=network.target
	
	[Service]
	Type=exec
	ExecStart=fcgiwrap -f -p "/usr/lib/cgit/cgit.cgi" -s tcp:127.0.0.1:8999
	
	[Install]
	WantedBy=multi-user.target
	
<!-- tsk -->

	# systemctl start cgit
	
Add cgit configuration to caddy.

	git.joshuayun.com {
        	handle_path /cgit-css/* {
        	        root * /usr/share/cgit/
        	        file_server
        	}

        	handle {
        	        reverse_proxy localhost:8999 {
        	                transport fastcgi {
        	                        env DOCUMENT_ROOT /usr/lib/cgit/
        	                        env SCRIPT_FILENAME /usr/lib/cgit/cgit.cgi
        	                }
        	        }
        	}
	}


## Cgit configuration

More detailed documentation can be found on the cgitrc(5) [manual](https://linux.die.net/man/5/cgitrc).

enable-git-config is used to allow for gitweb.* configurations in gitolite, e.g. description, owner.


	enable-git-config=1

project-list sets where cgit looks for projects, this list is the one updated by gitolite

	project-list=/home/git/projects.list
	
scan-path sets where the actual git repositories live

	scan-path=/home/git/repositories

## References

[SixFoisNeuf](https://www.sixfoisneuf.fr/posts/setting-up-cgit-with-caddy2/) Used this blog to run cgit using fcgiwrap rather than a caddy plugin. The entire cgit with caddy section was using his work.

[Mateja Maric](https://matejamaric.com/blog/git-server/) Used this blog to help configure cgitrc, gitolite.rc

[Luke Hsiao](https://luke.hsiao.dev/blog/cgit-caddy-gitolite/) Used the git user creation command from this blog.

[Omar Polo (yumh)](https://www.omarpolo.com/post/cgit-gitolite.html) Used this blog to help configure cgitrc for hidden repos.

[Bryan Brattlof](https://bryanbrattlof.com/cgit-nginx-gitolite-a-personal-git-server/) Not much used here, kept as reference.