Table of Contents

Middleware

Gitea



What is Gitea


How to install Gitea for TEST

$ mkdir gitea
$ cd gitea
$ wget -O gitea https://dl.gitea.io/gitea/1.12.2/gitea-1.12.2-linux-amd64
$ chmod +x gitea
$ ./gitea web

Browser with http://x.x.x.x:3000
Configuration :
Database : SQLite3


How to install Gitea With MySQL

Create User

useradd gitea


MySQL

$ mysql -u root -p

mysql> CREATE USER 'gitea' IDENTIFIED BY 'gitea';

mysql> CREATE DATABASE giteadb CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';

mysql> GRANT ALL PRIVILEGES ON giteadb.* TO 'gitea';
mysql> FLUSH PRIVILEGES;


Gitea

$ wget -O gitea https://dl.gitea.io/gitea/1.12.2/gitea-1.12.2-linux-amd64
$ chmod +x gitea
# cp gitea /usr/local/bin/gitea
# adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git
# mkdir -p /var/lib/gitea/{custom,data,log}
# chown -R git:git /var/lib/gitea/
# chmod -R 750 /var/lib/gitea/
# mkdir /etc/gitea
# chown root:git /etc/gitea
# chmod 770 /etc/gitea
/etc/systemd/system/gitea.service

https://github.com/go-gitea/gitea/blob/main/contrib/systemd/gitea.service

[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
###
# Don't forget to add the database service requirements
###
#
#Requires=mysql.service
#Requires=mariadb.service
#Requires=postgresql.service
#Requires=memcached.service
#Requires=redis.service
#
###
# If using socket activation for main http/s
###
#
#After=gitea.main.socket
#Requires=gitea.main.socket
#
###
# (You can also provide gitea an http fallback and/or ssh socket too)
#
# An example of /etc/systemd/system/gitea.main.socket
###
##
## [Unit]
## Description=Gitea Web Socket
## PartOf=gitea.service
##
## [Socket]
## Service=gitea.service
## ListenStream=<some_port>
## NoDelay=true
##
## [Install]
## WantedBy=sockets.target
##
###

[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
# If using Unix socket: tells systemd to create the /run/gitea folder, which will contain the gitea.sock file
# (manually creating /run/gitea doesn't work, because it would not persist across reboots)
#RuntimeDirectory=gitea
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
# If you want to bind Gitea to a port below 1024, uncomment
# the two values below, or use socket activation to pass Gitea its ports as above
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
###

[Install]
WantedBy=multi-user.target


Configuration

Disable self-user registration

/etc/gitea/app.ini

DISABLE_REGISTRATION = true
ENABLE_OPENID_SIGNUP = false


Relax password restrictions

/etc/gitea/app.ini

[security]
PASSWORD_COMPLEXITY = off


Gitea's ssh

/etc/gitea/app.ini

DISABLE_SSH      = false
SSH_PORT         = 10022
START_SSH_SERVER = true


App.ini protection

# chmod 750 /etc/gitea
# chmod 640 /etc/gitea/app.ini


Backup / Restore

https://docs.gitea.io/en-us/backup-and-restore/

Backup

./gitea dump -c /path/to/app.ini
or
./gitea dump -c /path/to/app.ini -w /var/lib/gite/data
or
sudo -u git /usr/local/bin/gitea dump -c /etc/gitea/app.ini

You may need in app.ini:

[server]
APP_DATA_PATH = /var/lib/gitea/data


Restore

unzip gitea-dump-1610949662.zip
cd gitea-dump-1610949662
mv data/conf/app.ini /etc/gitea/conf/app.ini
mv data/* /var/lib/gitea/data/
mv log/* /var/lib/gitea/log/
mv repos/* /var/lib/gitea/repositories/
chown -R gitea:gitea /etc/gitea/conf/app.ini /var/lib/gitea

# mysql
mysql --default-character-set=utf8mb4 -u$USER -p$PASS $DATABASE <gitea-db.sql
# sqlite3
sqlite3 $DATABASE_PATH <gitea-db.sql
# postgres
psql -U $USER -d $DATABASE < gitea-db.sql

service gitea restart