Skip to content

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 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

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 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 package.

Create a systemd service that wraps cgit with FastCGI.

# systemctl edit --full --force cgit.service
[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
# 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.

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 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 Used this blog to help configure cgitrc, gitolite.rc

Luke Hsiao Used the git user creation command from this blog.

Omar Polo (yumh) Used this blog to help configure cgitrc for hidden repos.

Bryan Brattlof Not much used here, kept as reference.