Gitea

From ArchWiki
Jump to: navigation, search

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Missing Apache/Caddy proxy example (Discuss in Talk:Gitea#)

Gitea is a community managed fork of Gogs, lightweight code hosting solution written in Go and published under the MIT license.

Installation

Install the gitea or gitea-gitAUR package.

Gitea requires the use of a database backend, the following are supported:

Configuration

The user configuration file is located at /etc/gitea/app.ini. Do not edit the main configuration file (/var/lib/gitea/conf/app.ini), since this file is included in the binary and will be overwritten on each update.

Gitea repository data will be saved into /var/lib/gitea/repos/, or if using gitea-gitAUR into /home/gitea/gitea-repositories. It is possible to overrule this location in /etc/gitea/app.ini.

See the Gitea docs for more configuration examples.

PostgreSQL

Install and configure PostgreSQL.

Choose between TCP or UNIX Socket, and jump to the corresponding section.

Note: When Gitea and PostgreSQL are on the same machine, you should use a Unix socket, as it is faster and more secure.

With TCP socket

Create the new user while connecting to the server as postgres user (you will be prompted for a password for the new user):

[postgres]$ createuser -P gitea

Create the Gitea database, owned by gitea user:

[postgres]$ createdb -O gitea gitea

PostgreSQL#Configure PostgreSQL to be accessible from remote hosts

Verify it works:

$ psql --host=ip_address --dbname=gitea --username=gitea --password

Configure Gitea:

/etc/gitea/app.ini
DB_TYPE             = postgres
HOST                = hostadress:port
NAME                = gitea
USER                = gitea
; Use PASSWD = `your password` for quoting if you use special characters in the password.
PASSWD              = password

With Unix socket

Create the new user while connecting to the server as postgres user:

[postgres]$ createuser git

Create the Gitea database, owned by git user:

[postgres]$ createdb -O git gitea

Setup the Unix socket by adding the following line to /var/lib/postgres/data/pg_hba.conf:

local    gitea           git           peer

Restart postgresql.service.

Verify it works:

[git]$ psql --dbname=gitea --username=git

Configure Gitea:

/etc/gitea/app.ini
DB_TYPE             = postgres
HOST                = /run/postgresql/
NAME                = gitea
USER                = git
PASSWD              =

MariaDB/MySQL

Note: MySQL socket support can be enabled by using /var/run/mysqld/mysqld.sock as the listen address.
Warning: Gitea does not work with MariaDB < 10.2 out of the box (workaround), and the mariadb package is hold on 10.1 to keep compatibility with depending packages.

The following is an example of setting up MariaDB, setting your desired password:

$ mysql -u root -p
mysql> CREATE DATABASE `gitea` DEFAULT CHARACTER SET `utf8mb4` COLLATE `utf8mb4_unicode_ci`;
mysql> CREATE USER `gitea`@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON `gitea`.* TO `gitea`@`localhost`;
mysql> \q

Try connecting to the new database with the new user:

$ mysql -u gitea -p -D gitea

Configure MariaDB on first run or update app.ini:

/etc/gitea/app.ini
DB_TYPE  = mysql
HOST     = 127.0.0.1:3306 ; or /var/run/mysqld/mysqld.sock
NAME     = gitea
USER     = gitea
PASSWD   = password

Usage

Start/enable gitea.service, the webinterface should listen on http://localhost:3000.

When running Gitea for the first time it should redirect to http://localhost:3000/install.

Note: You might want to configure a reverse proxy to access remotely, e.g. nginx.
Note: If you want Gitea to listen on all interfaces, set HTTP_ADDR = 0.0.0.0 in /etc/gitea/app.ini.

Tips and tricks

Enable SSH Support

Make sure SSH is properly configured and running.

Setup your domain

You might want to set SSH_DOMAIN, e.g.:

/etc/gitea/app.ini
SSH_DOMAIN                 = git.domain.tld

Setup git user

Note: The package gitea-gitAUR uses gitea as user/user group instead of git. Users should only have to eventually #Configure SSH.

Set the home directory to gitea datadir (necessary to find users keys) and the shell to bash (for gitea commands to be properly executed) for git:

# usermod -d /var/lib/gitea/ -s /usr/bin/bash git

Configure SSH

If you use AllowUsers in your SSH configuration, add AllowUsers git (or AllowUsers gitea when using gitea-gitAUR) to it, e.g.:

/etc/ssh/sshd_config
...
AllowUsers archie git
...

Restart sshd.service if you use it (nothing to do if you use sshd.socket).

Disable HTTP protocol

By default, the ability to interact with repositories by HTTP protocol is enabled. You may want to disable HTTP-support if using SSH, by setting DISABLE_HTTP_GIT to true.

Configure nginx as reverse proxy

The following is an example of using nginx as reverse proxy for Gitea over unix socket (you need to provide the SSL certificate):

/etc/nginx/servers-available/gitea.conf
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name git.domain.tld;

    ssl_certificate /path/to/fullchain.pem;
    ssl_certificate_key /path/to/privkey.pem;

    location / {
        proxy_pass http://unix:/run/gitea/gitea.socket;
    }
}

Update the [server] section of app.ini:

/etc/gitea/app.ini
[server]
PROTOCOL                   = unix
DOMAIN                     = git.domain.tld
ROOT_URL                   = https://git.domain.tld
HTTP_ADDR                  = /run/gitea/gitea.socket
LOCAL_ROOT_URL             =
Note: You do not need to activate any SSL certificate options in /etc/gitea/app.ini.

Finally update the cookie section - set COOKIE_SECURE to true.

Binding on restricted ports

If you use the built-in SSH server and want Gitea to bind it on port 22, or if you want to bind Gitea webserver directly on ports 80/443 (that is in a setup without proxy), you will need to add a drop-in systemd unit override:

/etc/systemd/system/gitea.service.d/override.conf
[Service]
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
PrivateUsers=false

Enable Dark Theme

In the ui section, you can set the DEFAULT_THEME to arc-green for making the web interface use a dark background.

Troubleshooting

Database error on startup after upgrade to 1.5.0

A problem can appear after the upgrade to 1.5.0. The service will not start, and the following error is present in the logs:

/var/log/gitea/gitea.log
2018/08/21 16:11:12 [...itea/routers/init.go:60 GlobalInit()] [E] Failed to initialize ORM engine: migrate: do migrate: Sync2: Error 1071: Specified key was too long; max key length is 767 bytes

To fix this problem, run the following command as the `root` user on your MySQL/MariaDB server

$ mysql -u root -p
MariaDB> set global innodb_large_prefix = `ON`;

gitea should stop complaining about key size and startup properly.

See also