Install Gitea
Gitea is my favorite choice when self-hosting my own git server with nice web ui.
It is written in go which means that it consumes very little resources (especially RAM).
Check official site and documentation.
The simplest way to install it and maintain it is by using 'vanilla' docker compose setup even in a production.
Let's begin:
Requirements
- Linux Server (Your favorite distro)
- 2 CPU cores and 1GB RAM is typically sufficient for small teams/projects (from official docs)
- Docker Installed
docker-compose.yml
Create docker-compose.yml
networks:
gitea:
external: false
services:
server:
image: gitea/gitea:1.22.2
container_name: gitea
environment:
- USER_UID=1000
- USER_GID=1000
- GITEA__database__DB_TYPE=mysql
- GITEA__database__HOST=db:3306
- GITEA__database__NAME=gitea
- GITEA__database__USER=gitea
- GITEA__database__PASSWD=giteapass
- GITEA__mailer__ENABLED=true
- GITEA__mailer__FROM=${GITEA__mailer__FROM:?GITEA__mailer__FROM not set}
- GITEA__mailer__PROTOCOL=smtps
- GITEA__mailer__SMTP_ADDR=${GITEA__mailer__SMTP_ADDR:?GITEA__mailer__SMTP_ADDR not set}
- GITEA__mailer__SMTP_PORT=${GITEA__mailer__SMTP_PORT:?GITEA__mailer__SMTP_PORT not set}
- GITEA__mailer__USER=${GITEA__mailer__USER:-apikey}
- GITEA__mailer__PASSWD="""${GITEA__mailer__PASSWD:?GITEA__mailer__PASSWD not set}"""
- GITEA__security__SECRET_KEY=YejWZbfYNiXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- GITEA__security__INTERNAL_TOKEN=eyJhbGciXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- USER_UID=1000
- USER_GID=1000
restart: always
networks:
- gitea
volumes:
- ./gitea:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "222:22"
depends_on:
db:
condition: service_healthy
db:
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
image: mysql:8
restart: always
environment:
- MYSQL_ROOT_PASSWORD=gitea
- MYSQL_USER=gitea
- MYSQL_PASSWORD=giteapass
- MYSQL_DATABASE=gitea
- MYSQL_ROOT_PASSWORD=urrootpass
networks:
- gitea
volumes:
- ./mysql:/var/lib/mysql
I've chosen to use mysql but postgres is good option too.
Generate secrets for this part:
...
services:
server:
environment:
- GITEA__security__SECRET_KEY=[value returned by generate secret SECRET_KEY]
- GITEA__security__INTERNAL_TOKEN=[value returned by generate secret INTERNAL_TOKEN]
docker run -it --rm gitea/gitea:1 gitea generate secret SECRET_KEY
docker run -it --rm gitea/gitea:1 gitea generate secret INTERNAL_TOKEN
Add generated secrets.
Run commands:
docker compose pull
docker-compose up -d
Additional Configuration
All additional setup such as adding mail notifications and changing SSH ports can be done in app.ini file (gitea/conf/app.ini)
If you plan to change listening ssh port make sure to edit app.ini and add START_SSH_SERVER = true,
[server]
APP_DATA_PATH = /data/gitea
DOMAIN = git.example.com
SSH_DOMAIN = git.example.com
HTTP_PORT = 3000
ROOT_URL = https://git.example.com/
DISABLE_SSH = false
SSH_PORT = 2223
SSH_LISTEN_PORT = 2223
START_SSH_SERVER = true
LFS_START_SERVER = true
LFS_JWT_SECRET = -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
OFFLINE_MODE = true
Mail setup example:
[mailer]
PASSWD = """mail_password"""
PROTOCOL = smtps
ENABLED = true
FROM = [email protected]
SMTP_PORT = 587
USER = [email protected]
SMTP_ADDR = mail.example.com
Backup and restore
It is super easy to maintain this simple setup.
- Backup example using tar
gitea-folder is an example where all of your gitea files and folders are. Therefore we are 'taring' everything including database.
sudo tar cvfj gitea-$(date +%F).tar.gz gitea-folder
- Restore example using tar
sudo tar --same-owner -xvf gitea-$(date +%F).tar.gz