About Gitea

Gitea is a lightweight Git hosting service, similar to platforms like GitHub and Gitee. It is an open-source project that can be deployed locally, making it especially suitable for personal use or small team collaborations. Gitea requires minimal CPU(Related articleDifferences and Analysis of RAM, ROM, ARM, MCU, and CPU)and memory resources, making it ideal for use on personal computers or servers with limited resources

Setting Up Gitea Locally

This guide demonstrates the setup process on Ubuntu 18.04.4 LTS using Docker containers. Docker allows applications and their dependencies to run in isolated environments, while Docker Compose is used to manage multiple containers seamlessly.

2.1 Installing Docker

Gitea will be hosted in a container to package the application and its dependencies into an isolated environment. This ensures portability and scalability. Install Docker with the following command:

sudo apt install docker.io

Verify the installation:

docker -v

Expected Output:

Docker version 20.10.21, build 20.10.21-0ubuntu1~18.04.3

2.2 Installing Docker Compose

Docker Compose simplifies the management of multiple containers. Below are two installation methods:

2.2.1 Online Installation

Download Docker Compose using either of the following commands:

  • From GitHub (global source):

    sudo curl -L https://github.com/docker/compose/releases/download/2.30.3/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  • From DaoCloud (domestic source):

    sudo curl -L https://get.daocloud.io/docker/compose/releases/download/2.30.3/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

If curl is not installed, install it first:

sudo apt install curl

After downloading, grant execution permissions:

sudo chmod +x /usr/local/bin/docker-compose

Verify the installation:

docker-compose -v

If issues arise (e.g., downloaded file is an HTML page), switch to the offline installation method

2.2.2 Offline Installation

Visit the Docker Compose release page to download the appropriate binary for your system architecture.
For this guide, the system is x86_64, and version 2.30.3 is used.

After downloading, rename and move the file to /usr/local/bin/:

sudo mv docker-compose-Linux-x86_64 /usr/local/bin/docker-composesudo chmod +x /usr/local/bin/docker-compose

Verify the installation:

docker-compose --version

Expected Output:

Docker Compose version v2.30.3

2.3 Configuring the docker-compose.yml File

Create a project directory to store the configuration files:

mkdir ~/gitea && cd ~/gitea

Inside this directory, create a docker-compose.yml file. This file defines two services: Gitea and MySQL. MySQL provides the database backend for Gitea.

docker-compose.yml File Example:

networks:  gitea:    external: falseservices:  server:    image: gitea/gitea:1.21.1    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=gitea    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  db:    image: mysql:8    container_name: mysql    restart: always    environment:      - MYSQL_ROOT_PASSWORD=gitea      - MYSQL_USER=gitea      - MYSQL_PASSWORD=gitea      - MYSQL_DATABASE=gitea    networks:      - gitea    ports:      - "3306:3306"    volumes:      - ./mysql:/var/lib/mysql

2.4 Starting Docker Containers

Launch the containers:

sudo docker-compose up -d

If there are timeout errors, update the Docker mirror settings in /etc/docker/daemon.json (create the file if it doesn't exist):

{  "registry-mirrors": ["https://docker-proxy.741001.xyz", "https://registry.docker-cn.com"]}

Reload and restart the Docker service:

sudo systemctl daemon-reloadsudo systemctl restart docker

Retry launching the containers:

sudo docker-compose up -d

Verify the status of the containers:

sudo docker ps

Expected Output:

CONTAINER ID   IMAGE                COMMAND                  ...   PORTS                 NAMES89825b4d35bb   gitea/gitea:1.21.1   "/usr/bin/entrypoint…"   ...   0.0.0.0:3000->3000   giteacd7ef47cc0a9   mysql:8              "docker-entrypoint.s…"   ...   0.0.0.0:3306->3306   mysql

2.5 Accessing the Gitea Service

Access the Gitea web interface using your browser:

http://192.168.xx.xx:3000

Follow the on-screen instructions for initial setup. The configuration should be automatically populated from the docker-compose.yml file. Click Install to complete the setup.

Once installed, register and log in to use Gitea. The first registered account will have administrator privileges.

Gitea supports features like version control, branch management, code review, and issue tracking. You can also migrate repositories from other platforms to Gitea for backup purposes.