WHY do we need a GIT tool?
Git is a version control system that is used for tracking changes in computer files and coordinating work on those files among multiple people.
It is useful because it allows developers to keep track of the history of their code, easily collaborate with other developers, and revert to older versions of the code if needed.
Additionally, it can help teams work more efficiently by allowing them to review, discuss, and merge changes quickly and easily.
The Gitea Project
- The Gitea Project offers a versatile open-source git server, and you can explore more about it through these links:
Gitea - Your own Private, Fast, Reliable Devops Platform that we will run with Docker.
SelfHosting Gitea
Enter Gitea, the tool that we are going to use, together with Docker to have Git version control.
SelfHosting Gitea
One recurrent topic that has to be addressed in the first place is how to setup docker in our machine.
Pre-Requisites!! Just Get Docker ๐๐
Important step and quite recommended for any SelfHosting Project - Get Docker Installed
It will be one command, this one, if you are in Linux:
apt-get update && sudo apt-get upgrade && curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh && docker version
And install also Docker-compose with:
apt install docker-compose -y
Gitea Docker Stack
The configuration file that we will use today to SelfHost Gitea with Docker is:
version: "3"
networks:
gitea:
external: false
services:
server:
image: gitea/gitea:1.14.2
container_name: gitea
environment:
- USER_UID=998
- USER_GID=100
- GITEA__database__DB_TYPE=mysql
- GITEA__database__HOST=db:3306
- GITEA__database__NAME=gitea
- GITEA__database__USER=gitea
- GITEA__database__PASSWD=gitea
restart: always
networks:
- gitea
volumes:
- /srv/confs/gitea:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3033:3000"
- "2234:22"
depends_on:
- db
db:
image: mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=gitea
- MYSQL_USER=gitea
- MYSQL_PASSWORD=gitea
- MYSQL_DATABASE=gitea
networks:
- gitea
volumes:
- /srv/databases/gitea/mysql:/var/lib/mysql
You will create an user and password the first time you visit
localhost:3033
Deploy with CLI
Providing that the previous steps are clear, we can jump to our terminal and use:
sudo nano docker-compose.yml
This will open a text editor, where we can paste the following configuration file:
To save, use CTRL+O, then CTRL+X to exit.
Then just deploy the service with:
sudo docker-compose up -d
You are ready to use Gitea!
The Gitea service will be running in 0.0.0.0:3033
or localhost:3033
if you use the configuration file as it is provided.
If you have deployed it in one device at home, you can use it from any other connected at the same router, just use the internal IP of the device in which you made the deployment.
Check your Device Home IP Address ๐
You can check that in Linux with:
hostname -I
Conclusion
Where is the code stored? Here: /srv/confs/gitea/git/repositories
for each defined user.
sudo find /srv/confs/gitea -type d -name "repositories" #this helped :)
#sudo find /mnt/portainer_backup/srv/confs/gitea -type d -name "repositories"
To create a working copy from giteas stored files, just use the clone command: git clone path/to/gitea/git/username/reponame.git
as per:
mkdir -p /mnt/external_500gb/Z_SelfH_Backup/test/gitea
cp /mnt/external_500gb/Z_SelfH_Backup/gitea/confs/git/repositories/fossengineer/py_stocks.git /mnt/external_500gb/Z_SelfH_Backup/test/gitea/.git
## All that matters are these .git files!!!!
git clone path/to/gitea/git/username/reponame.git #generate the working files as per this
#git clone /mnt/external_500gb/Z_SelfH_Backup/gitea/confs/git/repositories/fossengineer/py_stocks.git
Copy all the repositories folder to a save place:
mkdir -p /media/abc/Z_backup_cont/gitea
sudo cp -r /mnt/portainer_backup/srv/confs/gitea/git/repositories /media/abc/Z_backup_cont/gitea/
Gitea with Client GUI
How to BackUp Gitea
sudo fdisk -l #get the drive
sudo mkdir /mnt/external_500gb
sudo mount /dev/sda1 /mnt/external_500gb #mount the drive
#/mnt/external_500gb/Z_SelfH_Backup
sudo fdisk -l #get the drive
sudo mkdir /mnt/external_500gb
sudo mount /dev/sda1 /mnt/external_500gb #mount the drive
sudo mkdir -p /mnt/external_500gb/Z_SelfH_Backup/gitea/mysql/
sudo mkdir -p /mnt/external_500gb/Z_SelfH_Backup/gitea/confs/
sudo cp -r /mnt/portainer_backup/srv/databases/gitea/mysql/* /mnt/external_500gb/Z_SelfH_Backup/gitea/mysql/
sudo cp -r /mnt/portainer_backup/srv/confs/gitea/* /mnt/external_500gb/Z_SelfH_Backup/gitea/confs/
---
## FAQ
You will need a IDE, and you can use a **F/OSS version of VSCode with Flatpak**:
```sh
#sudo apt install git
sudo add-apt-repository ppa:flatpak/stable
sudo apt update
sudo apt install flatpak
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
#flatpak install flathub com.visualstudio.code
flatpak install flathub com.vscodium.codium
Or with snap:
sudo apt install snapd
#sudo snap install code --classic
Or with your WebToP or VsCode in a container:
version: "2.1"
services:
code-server:
image: lscr.io/linuxserver/code-server:latest
container_name: code-server
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Paris
#- PROXY_DOMAIN=code-server.my.domain #optional
#- DEFAULT_WORKSPACE=/config/workspace #optional
#- PASSWORD=password #UI Pass - optional
#- SUDO_PASSWORD=password #optional #IMPORTANT TO INSTALL PYTHON AND OTHERS!!
volumes:
- /home/Docker/vscode/config:/config
ports:
- 8443:8443
restart: unless-stopped
networks:
nginx_nginx_network:
networks:
nginx_nginx_network:
external: true
GIT 101 Commands
Git Error: fatal: the remote end hung up unexpectedly ๐
Increase the GIT Buffer Size:
git config --global http.postBuffer 524288000 # Sets buffer to 500 MB
How to configure GIT user and mail
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
How to Login to VSCode to Github
How to use Gitea with HTTPs
If you are interested in deploying a separated NGINX instance with Docker, I already created a guide for that here.