209 lines
4.9 KiB
Markdown
209 lines
4.9 KiB
Markdown
|
---
|
||
|
title: Howto Gitea
|
||
|
categories: sysadmin git forge
|
||
|
...
|
||
|
|
||
|
* Site officiel : <https://gitea.io/>
|
||
|
|
||
|
|
||
|
[Gitea](https://gitea.io/) est un fork de gogs, une solution d'hébergement de code avec git.
|
||
|
|
||
|
|
||
|
## Installation
|
||
|
|
||
|
Malheureusement, gitea n'est pas distribué sous forme de paquet Debian. Une alternative est donc d'utiliser directement les binaires produits par les développeurs de Gitea. Ils sont récupérables sur <https://dl.gitea.io/gitea/>.
|
||
|
|
||
|
~~~
|
||
|
# cd /usr/local/bin
|
||
|
# wget https://dl.gitea.io/gitea/1.5.2/gitea-1.5.2-linux-amd64
|
||
|
# chmod +x gitea-1.5.2-linux-amd64
|
||
|
# ln -s gitea-1.5.2-linux-amd64 gitea
|
||
|
|
||
|
# mkdir /etc/gitea/
|
||
|
|
||
|
# gitea --version
|
||
|
Gitea version 1.5.2 built with: bindata, sqlite
|
||
|
~~~
|
||
|
|
||
|
**Note** : Même si gitea peut fonctionner de manière autonome avec SQLite, à partir d'une certaine taille/utilisation, il est préférable de basculer vers un moteur de base de données tel que [HowtoMySQL]() ou [HowtoPostgreSQL]() et d'ajouter [HowtoRedis]() pour le cache/sessions.
|
||
|
|
||
|
|
||
|
## Configuration
|
||
|
|
||
|
Dans la suite de cette documentation, on se place dans le cas d'une instance simple, fonctionnant avec l'utilisateur **git**. On part du principe que : MySQL est déjà installé, et que le compte pour l'application existe déjà.
|
||
|
|
||
|
Au final, on va se retrouver avec la hiérarchie suivante :
|
||
|
|
||
|
~~~
|
||
|
$ tree /home/git
|
||
|
├── internals
|
||
|
│ ├── custom << Fichiers de customisation de l'interface web de gitea
|
||
|
│ └── data << Toutes les données de gitea (autres que les dépôts git)
|
||
|
│ ├── avatars
|
||
|
│ ├── indexers
|
||
|
│ ├── lfs
|
||
|
│ └── sessions
|
||
|
│
|
||
|
├── log << Journaux applicatifs
|
||
|
│ ├── gitea.log
|
||
|
│ ├── http.log
|
||
|
│ ├── serv.log
|
||
|
│ └── xorm.log
|
||
|
│
|
||
|
└── repositories << Données des dépôts git
|
||
|
└── foo
|
||
|
└── hello_world.git
|
||
|
|
||
|
~~~
|
||
|
|
||
|
Lors de la première exécution de gitea, une page d'installation va demander tous les paramètres nécessaires pour initialiser l'instance. Celle-ci va aussi permettre de créer le premier compte administrateur.
|
||
|
|
||
|
### /etc/gitea/git.ini
|
||
|
|
||
|
On doit initialiser le fichier de configuration de gitea avec les commandes suivantes.
|
||
|
A noter qu'on ne laisse les droits d'écritures uniquement pour l'installation.
|
||
|
|
||
|
|
||
|
~~~
|
||
|
# touch /etc/gitea/git.ini
|
||
|
# chown root:git /etc/gitea/git.ini
|
||
|
# chmod g+rw /etc/gitea/git.ini
|
||
|
~~~
|
||
|
|
||
|
On ajoute aussi quelques réglages initiaux, pour que l'interface de gitea soit directement fonctionnelle :
|
||
|
|
||
|
~~~
|
||
|
# cat /etc/gitea/git.ini
|
||
|
APP_NAME = Gitea
|
||
|
RUN_USER = git
|
||
|
RUN_MODE = prod
|
||
|
|
||
|
[server]
|
||
|
PROTOCOL = unix
|
||
|
DOMAIN = gitea.example.org
|
||
|
HTTP_ADDR = /home/git/gitea.sock
|
||
|
UNIX_SOCKET_PERMISSION = 660
|
||
|
OFFLINE_MODE = true
|
||
|
SSH_DOMAIN = gitea.example.org
|
||
|
ROOT_URL = https://gitea.example.org/
|
||
|
~~~
|
||
|
|
||
|
|
||
|
### systemd
|
||
|
|
||
|
~~~
|
||
|
# cat /etc/systemd/system/gitea@.service
|
||
|
|
||
|
[Unit]
|
||
|
Description=Gitea (Git with a cup of tea)
|
||
|
After=syslog.target
|
||
|
After=network.target
|
||
|
After=mysqld.service
|
||
|
|
||
|
[Service]
|
||
|
User=git
|
||
|
Group=git
|
||
|
|
||
|
Type=simple
|
||
|
RestartSec=2s
|
||
|
Restart=always
|
||
|
|
||
|
WorkingDirectory=/home/git
|
||
|
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/git.ini
|
||
|
Environment=GITEA_WORK_DIR=/home/git/internals
|
||
|
|
||
|
|
||
|
[Install]
|
||
|
WantedBy=multi-user.target
|
||
|
~~~
|
||
|
|
||
|
### MySQL
|
||
|
|
||
|
~~~
|
||
|
# mysqladmin create git
|
||
|
# mysql
|
||
|
mysql> GRANT ALL PRIVILEGES ON git.* TO 'git'@localhost IDENTIFIED BY 'PASSWORD';
|
||
|
~~~
|
||
|
|
||
|
Côté gitea.ini, la base de donnée MySQL se configure avec la section ci-dessous.
|
||
|
|
||
|
**Note** : La page d'installation va remplir cette section de la configuration automatiquement.
|
||
|
|
||
|
~~~
|
||
|
[database]
|
||
|
DB_TYPE = mysql
|
||
|
HOST = /run/mysqld/mysqld.sock
|
||
|
NAME = git
|
||
|
USER = git
|
||
|
PASSWD = PASSWORD
|
||
|
~~~
|
||
|
|
||
|
### Nginx
|
||
|
|
||
|
~~~
|
||
|
# cat /etc/nginx/sites-enabled/git
|
||
|
upstream gitea_git {
|
||
|
server unix:/home/git/gitea.sock;
|
||
|
}
|
||
|
|
||
|
server {
|
||
|
listen 0.0.0.0:80;
|
||
|
listen [::]:80;
|
||
|
listen 0.0.0.0:443 ssl http2;
|
||
|
listen [::]:443 ssl http2;
|
||
|
|
||
|
server_name gitea.evolix.org;
|
||
|
|
||
|
include /etc/nginx/ssl/git.conf;
|
||
|
include /etc/nginx/letsencrypt.conf;
|
||
|
|
||
|
if ( $scheme = http ) {
|
||
|
return 301 https://$server_name$request_uri;
|
||
|
}
|
||
|
|
||
|
location / {
|
||
|
proxy_pass http://gitea_git;
|
||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||
|
proxy_set_header X-Forwarded-For $remote_addr;
|
||
|
proxy_read_timeout 10;
|
||
|
}
|
||
|
}
|
||
|
~~~
|
||
|
|
||
|
### Redis
|
||
|
|
||
|
*TODO*
|
||
|
|
||
|
|
||
|
## Avancé
|
||
|
|
||
|
### Multiples instances
|
||
|
|
||
|
On peut très bien faire du multi-instance. On peut ainsi basculer sur une unité systemd avec paramètre comme :
|
||
|
|
||
|
~~~
|
||
|
# cat /etc/systemd/system/gitea@.service
|
||
|
|
||
|
[Unit]
|
||
|
Description=Gitea (Git with a cup of tea) for %i
|
||
|
After=syslog.target
|
||
|
After=network.target
|
||
|
After=mysqld.service
|
||
|
|
||
|
[Service]
|
||
|
User=%i
|
||
|
Group=%i
|
||
|
|
||
|
Type=simple
|
||
|
RestartSec=2s
|
||
|
Restart=always
|
||
|
|
||
|
WorkingDirectory=/home/%i
|
||
|
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/%i.ini
|
||
|
Environment=GITEA_WORK_DIR=/home/%i/internals
|
||
|
|
||
|
[Install]
|
||
|
WantedBy=multi-user.target
|
||
|
~~~
|
||
|
|