wiki-grav/pages/02.linux/gitea/default.en.md

106 lines
2.7 KiB
Markdown
Raw Normal View History

---
title: Gitea
visible: true
---
[toc]
2022-12-16 11:46:32 +01:00
## Pre-Setup
2022-12-16 11:46:32 +01:00
Create a gitea user
2022-12-16 11:46:32 +01:00
`# useradd -m git`
`# mkdir /etc/gitea`
2022-12-16 11:46:32 +01:00
`# chown git:git -R /etc/gitea`
2022-08-05 15:53:59 +02:00
Create the .ssh directory for the git user
2022-12-16 11:46:32 +01:00
`$ sudo -u git mkdir -p /home/git/.ssh`
2022-08-05 15:53:59 +02:00
2022-12-16 11:46:32 +01:00
Get the user id of git with `id git`
2022-08-05 15:53:59 +02:00
## Podman
### Network and Pod
2022-12-16 11:46:32 +01:00
2022-08-05 15:53:59 +02:00
`# podman network create net_gitea`
2022-12-16 11:46:32 +01:00
`# podman pod create --name pod_gitea --network net_gitea -p 127.0.0.1:5432:5432 -p 3000:3000 -p 127.0.0.1:2222:22`
2022-08-05 15:53:59 +02:00
#### Port Mappings
2022-12-16 11:46:32 +01:00
2022-08-05 15:53:59 +02:00
```
5432 (localhost): Postgres Database
3000: Gitea WebUI
2222 (localhost): Gitea SSH
```
### Database
2022-12-16 11:46:32 +01:00
```sh
2022-08-05 15:53:59 +02:00
# podman run --name giteadb \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-e POSTGRES_USER=gitea \
-e POSTGRES_PASSWORD=gitea \
-e POSTGRES_DB=gitea \
-v /mnt/postgres:/var/lib/postgresql/data \
--pod pod_gitea \
2022-11-20 18:49:37 +01:00
-d docker.io/postgres:14
2022-08-05 15:53:59 +02:00
```
2022-10-10 19:01:27 +02:00
### Application
2022-12-16 11:46:32 +01:00
```sh
2022-08-05 15:53:59 +02:00
# podman run --name gitea \
-e USER_UID=(uid) \
-e USER_GID=(gid) \
-e GITEA__database__DB_TYPE=postgres \
-e GITEA__database__HOST=giteadb:5432 \
-e GITEA__database__NAME=gitea \
-e GITEA__database__USER=gitea \
-e GITEA__database__PASSWD=gitea \
-v /mnt/gitea:/data \
-v /home/git/.ssh/:/data/git/.ssh \
-v /etc/timezone:/etc/timezone:ro \
-v /etc/localtime:/etc/localtime:ro \
2022-08-05 15:53:59 +02:00
--pod pod_gitea \
-d docker.io/gitea/gitea:latest
```
2022-08-05 15:53:59 +02:00
**NOTE:** gitea's /data directory must not contain permissions too open. Otherwise the SSH redirection set up below will fail.
2022-12-16 11:46:32 +01:00
`0750` for directories and `0640` has been shown to work
The next few lines are used to set up ssh-redirection to gitea if it is used to clone a repo.
2022-08-05 15:53:59 +02:00
> See also the [official documentation](https://docs.gitea.io/en-us/install-with-docker/#sshing-shim-with-authorized_keys)
2022-08-05 15:53:59 +02:00
Create SSH Keys for gitea
`$ sudo -u git ssh-keygen -t rsa -b 4096 -C "Gitea Host Key"`
`$ sudo -u git cat /home/git/.ssh/id_rsa.pub | sudo -u git tee -a /home/git/.ssh/authorized_keys`
2022-12-16 11:46:32 +01:00
`$ sudo -u git chmod 600 /home/git/.ssh/authorized_keys`
2022-12-16 11:46:32 +01:00
```sh
$ cat <<"EOF" | sudo tee /usr/local/bin/gitea
#!/bin/sh
ssh -p 2222 -o StrictHostKeyChecking=no git@127.0.0.1 "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@"
EOF
```
2022-08-05 15:53:59 +02:00
2022-12-16 11:46:32 +01:00
`# chmod +x /usr/local/bin/gitea`
We've now finished setting up the ssh-redirection.
After that, connect to the Server on port 3000 to finish the installation
2022-12-16 11:46:32 +01:00
The first registered user will be made admin
## Management CLI
2022-12-16 11:46:32 +01:00
Gitea comes with a management cli. To access it, change into the Container first and su into the user "git".
`# podman exec -it gitea bash`
2022-12-16 11:46:32 +01:00
`# su git`
### User Management
2022-12-16 11:46:32 +01:00
List users:
2022-12-16 11:46:32 +01:00
`$ gitea admin user list`
Change user password:
2022-12-16 11:46:32 +01:00
`$ gitea admin user change-password -u (user) -p (password)`