Files
web/content/blog/03-gitea.md
Jirka Stehlík ef8a22d55b
All checks were successful
Build and Publish Web / build (push) Successful in 15s
Improved category for block setup
2026-03-25 10:00:05 +01:00

163 lines
4.9 KiB
Markdown

---
date: '2026-03-24T18:48:40+01:00'
draft: false
title: 'Time for version control'
author: "Jirka"
tags: ["gitea", "self-hosted", "docker", "guide", "tutorial"]
categories: ["Blog setup"]
description: "Let's look at how to self host gitea on our infrastructure."
---
How would I share my projects with you, if I do not have any git hosting server? I don't know...
That is a reason, why we need to set up one! You can choose from more variant, but I decided for [Gitea](https://about.gitea.com/).
> [!WARNING]
> If you decide to follow my steps, please, be careful and use your head. I do not guarantee they will work for you and do so at your own risk.
## Self-hosting Gitea
Thanks to our earlier setup, next step is pretty simple.
All what we need to do is expand our docker setup, but I will do one more step, because we will need to share network between docker containers, I will add one more layer of docker compose, for holding the networks alive.
That said, I will continue with setup from [last article](./02-hosting-blog.md) about setting up whole server and WireGuard.
### Change docker layout
Let's start with stopping our containers for a while (execute commands in same folder as docker compose).
```bash
docker compose down
```
Create new folder for all the files, for example `web` and move all files into it.
```bash
mkdir web
mv * web
```
Now create new `docker-compose.yml` file with following content:
```yaml
networks:
proxy_network:
include:
- web/docker-compose.yml
```
What you can see is, that we used same network as in `docker-compose.yml` file, and included it. We will add all future `docker-compose.yml` files here. Thanks to that we can control all containers by one command and share network between them, without need to manually create persistent docker networks.
You can start containers again by:
```bash
docker compose up -d
```
And you should be back online.
### Add Gitea to stack
Create new directory `gitea` for Gitea and it's data an into it create new `docker-compose.yml` file with following content:
```yaml
networks:
gitea_internal:
proxy_network:
services:
gitea:
image: docker.gitea.com/gitea:latest
container_name: gitea
environment:
- USER_UID=${APP_UID}
- USER_GID=${APP_GID}
- GITEA__database__DB_TYPE=postgres
- GITEA__database__HOST=gitea_db:5432
- GITEA__database__NAME=${DB_NAME}
- GITEA__database__USER=${DB_USER}
- GITEA__database__PASSWD=${DB_PASSWORD}
restart: always
networks:
- gitea_internal
volumes:
- ./gitea:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "222:22"
depends_on:
- db
gitea_db:
image: docker.io/library/postgres:14
restart: always
environment:
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}
networks:
- gitea_internal
volumes:
- ./postgres:/var/lib/postgresql/data
```
And create file `.env` with secrets:
```text
DB_NAME=gitea
DB_USER=gitea_user
DB_PASSWORD="super secret password"
APP_UID=1000
APP_GID=1000
```
Note that we specified proxy network in compose file but did not use it yet. That is because we will do first Gitea setup locally and after that we will connect it to our web.
Now you can `cd ..` to upper directory and add new `docker-compose.yml` to upper `docker-compose.yml`. Just add following line:
```yaml
- gitea/docker-compose.yml
```
Now you can start Gitea by `docker compose up -d`.
After that, Gitea should be online. You should visit it, by going to `local_ip_address_of_server:3000` and finish first setup. This step is just up to you.
When you finish initial setup, we can add Gitea to our stack. Start by editing Gitea `docker-compose.yml`.
There you should remove line with ports and port definition under Gitea service and add proxy network under networks. Changed part of the file should look like this:
```yaml
gitea:
image: docker.gitea.com/gitea:latest
container_name: gitea
environment:
- USER_UID=${APP_UID}
- USER_GID=${APP_GID}
- GITEA__database__DB_TYPE=postgres
- GITEA__database__HOST=gitea_db:5432
- GITEA__database__NAME=${DB_NAME}
- GITEA__database__USER=${DB_USER}
- GITEA__database__PASSWD=${DB_PASSWORD}
restart: always
networks:
- gitea_internal
- proxy_network
volumes:
- ./gitea:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
depends_on:
- gitea_db
```
Last step is to change `Caddyfile` in `web` folder. All you need to do is add following lines:
```
git.jirkabuilds.dev {
reverse_proxy gitea:3000
}
```
If you have set up DNS correctly, after shutting the stack down and up the Gitea should be online.
And that's it!
---
This article is one from series about this blog and self-hosting. All connected articles can found [here](categories/blog-setup).