A Docker Compose file for Gitea - Git with a cup of tea (gitea.io).
Data will be saved in separate Docker volumes to enable easy upgrades!
- Docker
- Docker Compose
-
Copy .env.dist to .env and make your modifications. Below is an example
.env
file:POSTGRES_DB=gitea POSTGRES_USER=gitea POSTGRES_PASSWORD=gitea USER_UID=1000 USER_GID=1000 DB_TYPE=postgres DB_HOST=gitea-db:5432 DB_NAME=gitea DB_USER=gitea DB_PASSWD=gitea ROOT_URL=http://localhost:3000/ RUNNER_REGISTRATION_TOKEN_1=xyz123etc RUNNER_REGISTRATION_TOKEN_2=abc456etc
-
Start the Docker containers:
docker-compose up -d
-
After starting the containers, open the Gitea installer in your browser: http://localhost:3000 and complete the setup form according to your
.env
settings.- Set
gitea-db:5432
in the Database Host field and configure the rest using the PostgreSQL credentials defined in the.env
file.
- Set
-
Once the setup is completed, register a new user using the link in the navigation bar.
The first registered user will have admin privileges.
VARIABLE | Description | DEFAULT |
---|---|---|
POSTGRES_DB | PostgreSQL database name | gitea |
POSTGRES_USER | PostgreSQL database user | gitea |
POSTGRES_PASSWORD | PostgreSQL database password | gitea |
USER_UID | Gitea user UID | 1000 |
USER_GID | Gitea user GID | 1000 |
DB_TYPE | Database type | postgres |
DB_HOST | Database host | gitea-db:5432 |
DB_NAME | Gitea database name | gitea |
DB_USER | Gitea database user | gitea |
DB_PASSWD | Gitea database password | gitea |
ROOT_URL | Gitea root URL | http://localhost:3000/ |
RUNNER_REGISTRATION_TOKEN_1 | Gitea runner 1 registration token | |
RUNNER_REGISTRATION_TOKEN_2 | Gitea runner 2 registration token |
- Copy docker-gitea.service.dist to docker-gitea.service.
- Adjust WorkingDirectory in the service file if needed.
- Create a symbolic link:
ln -s docker-gitea.service /etc/systemd/system/docker-gitea.service
- Start the service:
systemctl start docker-gitea
- (Optional) Enable autostart at boot:
systemctl enable docker-gitea
This setup includes a script to backup Gitea data to an rsync.net account. This is separate from the database backup, which is handled by the cron-backups repository and scripts.
-
Ensure you have an rsync.net account.
-
Add the following variables to your
.env
file:RSYNC_USERNAME=your_rsync_username RSYNC_SERVER=your_rsync_server SSH_KEY_PATH=/path/to/your/ssh/private/key
-
Make sure your SSH public key is added to your rsync.net account.
To run the backup manually:
- Ensure you're in the same directory as the
gitea-data-sync.sh
script. - Run the script:
./gitea-data-sync.sh
This will sync the Gitea data volume to your rsync.net account.
To automate the backup process, you can set up a cron job:
-
Open your crontab file:
crontab -e
-
Add a line to run the script daily at 2 AM (adjust the time as needed):
0 2 * * * /path/to/your/gitea-data-sync.sh
Remember to replace /path/to/your/gitea-data-sync.sh
with the actual path to the script.
To restore from the backup:
-
Stop the Gitea container:
docker-compose stop gitea
-
Remove the existing Gitea data volume:
docker volume rm docker-compose-gitea_gitea-data
-
Create a new empty volume:
docker volume create docker-compose-gitea_gitea-data
-
Use rsync to copy the data from rsync.net to the new volume:
rsync -avz -e ssh your_rsync_username@your_rsync_server:gitea/data/ /var/snap/docker/common/var-lib-docker/volumes/docker-compose-gitea_gitea-data/_data/
-
Start the Gitea container:
docker-compose start gitea
Note: Adjust the paths as necessary for your specific setup.
This updated README.md
now reflects the PostgreSQL setup, .env
file usage, and the addition of backing up Gitea data using the gitea-data-sync.sh
script.