Gitea

From Alpine Linux
Jump to navigation Jump to search

Gitea is a community managed lightweight code hosting solution written in Go. It is a fork of Gogs.

Note: This guide is not for installing Gitea in Docker. If you want to install Gitea in a Docker container, follow the official documentation

Installation

First, Enable the Community Repository

Then install the gitea package:

apk add gitea

Setting up the Database

Note: These instructions are for MariaDB. If you would like to set up another database, follow the official documentation

Install the MariaDB and mariadb-client packages:

apk add mariadb mariadb-client

Set up the MariaDB installation and secure it:

mysql_install_db --user=mysql --datadir=/var/lib/mysql service mariadb start rc-update add mariadb mysql_secure_installation

Create the gitea database and a user with access to it:

Note: Everything after the mysql -u root -p should be typed in the MariaDB prompt (looks like MariaDB [(none)]>)
Note: Replace the above username 'giteauser' and password 'giteapassword' with something secure. Remember these settings. You will need them later when setting up Gitea.

mysql -u root -p CREATE DATABASE gitea DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; GRANT ALL ON gitea.* TO 'giteauser'@'localhost' IDENTIFIED BY 'giteapassword'; FLUSH PRIVILEGES; EXIT

If you want, you can uninstall the mariadb-client now as it's not needed anymore:

apk del mariadb-client

In /etc/gitea/app.ini, replace the contents of the [database] section with the following:

DB_TYPE = mysql
HOST = /var/run/mysqld/mysqld.sock
NAME = gitea			; The database name set with 'CREATE DATABASE'
USER = giteauser		; The database user
PASSWD = giteapassword		; The password for the database user

Configurations

The Gitea service can be configured using /etc/conf.d/gitea:

Description Configuration Variable Default Value
User to run Gitea under GITEA_USER gitea
Gitea working directory GITEA_WORK_DIR /var/lib/gitea/
Gitea configuration file GITEA_CONF /etc/gitea/app.ini

Some additional settings in /etc/gitea/app.ini:

Description Configuration Variable Default Value
Gitea customization directory Cannot be configured /var/lib/gitea/custom/
Web files STATIC_ROOT_PATH /usr/share/webapps/gitea/
Data files APP_DATA_PATH /var/lib/gitea/data/
Git repository storage directory ROOT /var/lib/gitea/git/
Log directory ROOT_PATH /var/log/gitea/
Note: Gitea has a built-in web server, so there is no need to configure one. However, you can set up a reverse proxy.
Note: To customize the look and feel of Gitea, find the correct path in /usr/share/webapps/gitea/ and make the same path in /var/lib/gitea/custom/. For example, to add a new Gitea theme, create the /var/lib/gitea/custom/public/css/ directory, then add the css for the theme there.

Controlling and starting gitea

You should not start Gitea without setting certain environment variables and passing some options, since it won't know where to store data and logs, so it is recommended to start gitea using the init script:

service gitea start

To add Gitea to the default runlevel (such that it runs automatically on every boot):

rc-update add gitea

To stop the Gitea service:

service gitea stop

Running Gitea without the init script

If (for whatever reason), you would like to start Gitea without using the initscript, you should first stop the Gitea service:

service gitea stop

Then, run Gitea with this command (as the gitea user):

GITEA_WORK_DIR=/var/lib/gitea gitea web --config /etc/gitea/app.ini

This will use the correct configuration file and write to the correct directories.

Post installation

Tango-view-fullscreen.png
This material needs expanding ...

Please feel free to help us complete it.

After installing Gitea, go to http://localhost:3000 and start the post-installation process.

Setting up SSH Git access

Do not try to be clever and use ssh-copy-id, as it will not have the correct command set.

As an example, if this is the public key:

ssh-ed25519 ******************************************************************** **********@gmail.com

The line in .ssh/authorized_keys needs to be:

command="/usr/bin/gitea --config=/etc/gitea/app.ini serv key-2",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-ed25519 ******************************************************************** **********@gmail.com

In order to do this, generate a SSH key, then go to the Gitea settings panel and click the Add Key button, then paste in your public key.

Now, once you've added your private key to the SSH agent, you can use SSH with Gitea like you normally would with GitHub, GitLab, etc.