Gitea Setup

Posted on 2021-01-16

Step-by-step account of setting-up gitea.

Context:

Often I want to share and/or collaborate with someone on a document that is part of a project, like this website for example. The someone may be both far away and also think that git is just a curse word, not a VCS.

So joint working has involved a chain of emails, or dumping stuff into a google doc or, my least favourite, dictating edits over the phone. In all cases, I end up doing some kind of manual version control, and it feels pretty inefficient.

The necessary functionality of hosting content, browsing directories, and editing text files is available, for example, on github. Github doesn’t require knowledge of git really, but it does require an account. Git-lab also provides the functionality, and can be self hosted, but both seem like using a hammer to crack a nut.

Gitea has many bells and whistles that I’m not looking for, but has lower resource usage than gitlab. And maybe I’ll find a use for the bells and whistles at some stage?

Sources

Gitea’s docs are pretty thorough. Below is essentially my “annotated” version of their instructions.

There’s also this walk-through complete with screenshots, on setting up gogs, from which gitea was originally forked.

Install

On the remote machine as root…

Set-up some variables

export GITEA_VERSION=1.13.1
export GITEA_NAME=gitea-$GITEA_VERSION-linux-amd64

Download and make executable

wget -O gitea https://dl.gitea.io/gitea/$GITEA_VERSION/$GITEA_NAME
chmod +x gitea

Verify with gpg (which is installed with the gnupg package - wasn’t on the system). Add the key for gitea

gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2

Fetch the key associated with the download

wget https://dl.gitea.io/gitea/$GITEA_VERSION/$GITEA_NAME.asc

And verify

gpg --verify $GITEA_NAME.asc gitea

Should display a reassuring message. (I’d be lying if I claimed I really understood quite how or why…)

Prep

Git is installed

Add new user git with suggested options verbatim

adduser \
   --system \
   --shell /bin/bash \
   --gecos 'Git Version Control' \
   --group \
   --disabled-password \
   --home /home/git \
   git

and setting-up the directory structure

mkdir -p /var/lib/gitea/{custom,data,log}
chown -R git:git /var/lib/gitea/
chmod -R 750 /var/lib/gitea/
mkdir /etc/gitea
chown root:git /etc/gitea
chmod 770 /etc/gitea

The docs note that after installation/configuration /etc/gitea can (and should) be set to read-only.

Move gitea to global location

cp gitea /usr/local/bin/gitea

Gitea as a Linux service

Source

Get gitea.service template file.

wget -O /etc/systemd/system/gitea.service https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service

For now I’ll use sqlite3 so don’t need to configure a db, and there are no other options that need changing from default.

Enable and start the gitea service

sudo systemctl enable gitea --now

The docs continue by adding the service to supervisor. Install

sudo apt install supervisor

Create log directories

mkdir /home/git/gitea/log/supervisor

Add gitea’s template config to supervisor

curl https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/supervisor/gitea >> /etc/supervisor/supervisord.conf

And start the supervisor as a service

sudo systemctl enable supervisor --now

Reverse proxy with nginx

Source

I already have nginx setup with a sever already on 80. I did look at trying to use the DNS to point at a specific port on the server, but that seems like a no-go.

Instead I added an extra location line in the /etc/nginx/sites-available/blog config file.

server {
    listen 80;
    ... 
    location /git/ { # Note: Trailing slash
        proxy_pass http://localhost:3000/; # Note: Trailing slash	
    }
    ... 

nginx requires a reload on an up-date.

There are more suggestions on ways to optimize performance, but they can wait for now.

At this point, there is a line

Then set [server] ROOT_URL = http://git.example.com/git/ in your configuration.

It took me a long time to figure out that meant /etc/gitea/app.ini.

In this file I also set the variables HTTP_ADDR = 127.0.0.1, as it seemed to be accessable via 0.0.0.0 without that.

Finally

Change the permissions on the config file

chmod 750 /etc/gitea
chmod 640 /etc/gitea/app.ini

First thoughts…

It has a strangely familiar design. Very easy to navigate as a result. Had a little trial run with a non techy collaborator, who seemed pretty comfortable with the processes of browsing, editing, and committing.

We’ll revisit this again at a later date.