How to setup a self-hosted web-based lightweight GIT server

Guide to setup a self-hosted gitea server for hosting your own GIT projects

Posted by J├╝rgen on 23 March 2023

GIT Server

Currently I'm working on a few user-space tools for controlling the RGB LEDs on a Skikk Loki laptop from Linux. In an upcoming article I want to reference these tools. In order to do so, I want to setup a web-based GIT server to which I can provide links to. So In this article I will describe how to setup a web-based GIT server and how to configure and use it.

GITEA

I've been looking into a few available options, and the one I chose is gitea. This is an interface very much like github, but it's very lightweight, which is a requirement from my perspective, since hardware resources are limited.

gitea supports several databases, for small deployments sqlite would suffice, but since I have a multi-purpose PostgreSQL standing by, that will be the configured database. GITEA__server__PROTOCOL is set to http while GITEA__server__ROOT_URL is set to https because SSL is offloaded to a haproxy proxy, GITEA__service__DISABLE_REGISTRATION is set to true in order to prevent from other people registering for accounts.


version: '3'
services:
  server:
    deploy:
      mode: replicated
      replicas: 1
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 5s
      resources:
        limits:
          cpus: '1.0'
          memory: 1024M
    image: gitea/gitea:1.18.5
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - APP_NAME=Git jurgenhaan.nl
      - GITEA__server__PROTOCOL=http
      - GITEA__server__DOMAIN=git.jurgenhaan.nl
      - GITEA__server__ROOT_URL=https://git.jurgenhaan.nl
      - GITEA__database__DB_TYPE=postgres
      - GITEA__database__HOST=192.168.0.7:5432
      - GITEA__database__NAME=gitea
      - GITEA__database__USER=gitea
      - GITEA__database__PASSWD=...
      - GITEA__service__DISABLE_REGISTRATION=true
    volumes:
      - ./gitea:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "30080:3000"
      - "30022:22"

Configure

After deploying the stack on my docker swarm (note that you'll need to create the ./gitea directory and properly set it's ownership/access), creating the necessary haproxy config and generating a LetsEncryptCertificate, the instance can be accessed through the public URL. Here some extra configuration can be done. If you don't care for a working SMTP setup, better create your admin account here, since registration will be hard without a working mail-server (not to mention that registration is disabled). If you choose not to create your admin, the first account that's registered will be your admin, but you'll need to enable registration.

When everything is setup correctly, finalize the installation, after which your setup can be used. I suggest setting up 2FA for security. Note though that with 2FA, you cannot push over https, since authentication cannot be done, you'll need to use SSH authentication.