Gogs

From ArchWiki

Gogs (Go Git Service) is a Self Hosted Git service, which was written in the Go programming language.

Installation

Before installing the Gogs package (gogsAUR or gogs-gitAUR for the development version), you need to choose a database backend if you are planning to host Gogs on the same machine as the database:

Each package provides multiple options for configuring the backend/storage for the service, see #Configuration

If you plan to use SSH to interact with your repositories, make sure to add the gogs user to the AllowUsers entry in /etc/ssh/sshd_config.

First start

After starting gogs.service, you can access the running service over the url http://[server]:3000. At first load, you will be redirected to the installation page where you can configure some options.

In order to be able to save changes made using the initial configuration page the permissions of the configuration directory (owned by root) will have to be modified (either temporary or permanently), for example:

# chown -R gogs:gogs /etc/gogs/

You also need to create a drop-in file to allow gogs.service to change /etc/gogs contents:

/etc/systemd/system/gogs.service.d/writable-etc.conf
[Service]
ReadWritePaths=/etc/gogs

Then do a daemon-reload and restart gogs.service. After installing you can revert these changes to improve security.

In the configuration file /etc/gogs/app.ini, you can change more values (for example the port number).

Configuration

This article or section needs expansion.

Reason: Configuration of SMTP, oAuth, logging, caching (Discuss in Talk:Gogs)

The Gogs configuration file is located at /etc/gogs/app.ini. When you want to edit a configuration option, you need to edit this file and restart the Gogs service before changes will take effect.

SSH

In order to interact with the git repositories using ssh, and to be able to use the uploaded public keys:

  • set SSH_ROOT_PATH in /etc/gogs/app.ini to /var/lib/gogs/.ssh (see also documentation), and ensure that DISABLE_SSH is false.
  • Add gogs to AllowUsers in /etc/ssh/sshd_config.
  • create /var/lib/gogs/.ssh and hand over ownership to the gogs user:
> mkdir -p /var/lib/gogs/.ssh
> chown -R gogs:gogs /var/lib/gogs/.ssh

Public keys will be added by the gogs user to /var/lib/gogs/.ssh/authorized_keys

Since when installing gogsAUR your gogs user will have a /sbin/nologin shell, so you need to put in a /bin/bash shell:

# usermod -s /bin/bash gogs

.gitignore and license files

A set of gitignore and license files are included in the package and are stored at /usr/share/gogs/conf/gitignore and /usr/share/gogs/conf/license respectively.

You can get or create your own .gitignore files here.

Database

SQLite

Install sqlite and select SQLite on the installation page. Use an absolute path in /etc/gogs/app.ini (PATH variable in the [database] section) for the SQLite database file. To be consistent with the other settings, use /var/lib/gogs/data/gogs.db (see also issue 4298).

PostgreSQL

Install postgresql and select Postgresql on the installation page.

# su - postgres -c 
# createuser -P gogs
# createdb -O gogs gogs

MariaDB

Install mariadb and setup a user and database:

# CREATE DATABASE `ishouldchangethisdatabasename` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# CREATE USER 'ishouldchangethisusername'@'localhost' IDENTIFIED BY 'ishouldchangethispassword';
# GRANT ALL ON `ishouldchangethisdatabasename`.* TO 'ishouldchangethisusername'@'localhost';

On the installation page select mysql and insert your configured user, password and database name.

Theme

The current package (gogs-git* and gogs>=0.4.2) support custom themes. The location for Gogs themes is /usr/share/themes/gogs/. Gogs comes with one default theme, but you can easily create a own theme. Just copy the default theme directory and change whatever you want. In the public directory is every javascript, stylesheet and font file and in the template directory are the HTML templates. The current selected theme can be changed over the app.ini configuration parameter STATIC_ROOT_PATH. Changed it with the absolute path to the new theme.

Restart after Upgrade

Gogs needs to be restarted after every upgrade because the paths of javascript/css assets will change and therefore break the website. To automate this the following pacman hook can be inserted at /etc/pacman.d/hooks/gogs.hook:

[Trigger]
Type = Path
Operation = Upgrade
Target = usr/share/gogs/gogs
[Action]
Description = Restart gogs...
When = PostTransaction
Exec = /usr/bin/systemctl try-restart gogs.service

SSH port

The factual accuracy of this article or section is disputed.

Reason: The cap change will get overridden after an update. Why not use AmbientCapabilities and CapabilitiesBoundingSet via a drop-in file? (Discuss in Talk:Gogs)

If you are using a non-default port for your SSH server, you will get not-so-pretty clone URLs. You can make gogs start its own SSH server, listening on port 22.

Allow gogs binary to bind privileged ports:

# setcap CAP_NET_BIND_SERVICE=+eip /usr/share/gogs/gogs

Configure gogs SSH server in /etc/gogs/app.ini:

START_SSH_SERVER       = true
SSH_PORT               = 22
SSH_LISTEN_PORT        = 22

See also