Build Your Own Git Server & CI/CD with Gitea: Lightweight, Fast, and Completely Private

Ubuntu tutorial - IT technology blog
Ubuntu tutorial - IT technology blog

Why Gitea + Gitea Actions is the “Golden” Choice for Low-Spec VPS?

If you’ve ever felt the sting in your wallet from upgrading RAM just to run GitLab, or if you’re concerned about privacy when hosting code on the Cloud, Gitea is the answer. GitLab typically consumes at least 4GB-8GB of RAM to operate stably. In contrast, Gitea only uses about 100MB-150MB of RAM in standby mode. I tested this on a 1 vCPU – 1GB RAM Hetzner VPS; the system ran smoothly even with a 5-person team pushing code continuously.

The biggest turning point came with version 1.19 when Gitea introduced Gitea Actions. It is nearly 100% compatible with GitHub Actions’ .yaml configuration files. You can migrate your old workflows to your own server without spending a dime on licensing or worrying about “free minute” limits.

Getting Started: Setting Up the PostgreSQL Database

Although Gitea supports SQLite for convenience, I recommend using PostgreSQL from the start. It makes data backups safer and handles concurrent tasks much better as your project grows.

# Update the system
sudo apt update && sudo apt upgrade -y

# Install PostgreSQL
sudo apt install postgresql postgresql-contrib -y

# Create a dedicated database and user for Gitea
sudo -u postgres psql -c "CREATE DATABASE giteadb;"
sudo -u postgres psql -c "CREATE USER gitea WITH ENCRYPTED PASSWORD 'SuperSecretPassword';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE giteadb TO gitea;"

Don’t forget to create a dedicated system user to run the service. This helps isolate permissions and protects the server in case of application vulnerabilities:

sudo adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password git

Installing Gitea via Binary

Instead of using Docker, I prefer installing directly from a binary file to save resources and make network debugging easier. This approach gives you full control over the running processes.

# Download the latest Gitea version
wget -O /tmp/gitea https://dl.gitea.com/gitea/1.21.4/gitea-1.21.4-linux-amd64

# Grant permissions and move to the executable directory
sudo chmod +x /tmp/gitea
sudo mv /tmp/gitea /usr/local/bin/gitea

# Create directory structure for code and logs
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R git:git /var/lib/gitea/
sudo chmod -R 750 /var/lib/gitea/
sudo mkdir -p /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea

Next, set up Gitea to start automatically with Ubuntu using Systemd. Create a service file at /etc/systemd/system/gitea.service, then enable the service:

sudo systemctl enable --now gitea

Now, open your browser and go to http://Your-Server-IP:3000. The installation interface will appear. Simply fill in the PostgreSQL information you created in the previous step.

Activating CI/CD with Act Runner

Gitea Actions requires a separate component called Act Runner to execute jobs. Think of it as a “worker” always on standby to receive build commands from Gitea.

First, go to Site Administration -> Actions -> Runners in the web UI to obtain a Registration Token. Then, perform the following in the terminal:

# Download Act Runner
wget -O act_runner https://dl.gitea.com/act_runner/main/act_runner-main-linux-amd64
sudo chmod +x act_runner

# Register the runner with the system
./act_runner register --instance http://localhost:3000 --token <YOUR_TOKEN> --no-interactive

After successful registration, set it up to run as a background service to ensure your CI/CD system is ready 24/7.

Verification: Running Your First Pipeline

To test it out, create a new repository and add a .gitea/workflows/test.yaml file. This file will instruct the server to print a notification whenever new code is pushed:

name: Gitea Actions Demo
on: [push]
jobs:
  Check-System:
    runs-on: ubuntu-latest
    steps:
      - run: echo "CI/CD system is working perfectly!"
      - run: node -v

If the Actions tab shows a green checkmark, congratulations! You have an automation system that’s just as good as the big players.

Optimization Tips to Prevent Server Freezing

  • Combine Docker with the Runner: Even if Gitea runs as a binary, the Act Runner should use Docker. This helps create a clean build environment and leaves no junk files after each run.
  • Configure Swap: For a 1GB RAM VPS, create 2GB of Swap. When running npm install or building Docker images, RAM usage often spikes, which can easily cause Out-Of-Memory (OOM) errors.
  • Reverse Proxy: Don’t use port 3000 directly. Install Nginx and use Let’s Encrypt for HTTPS. This is crucial for protecting your source code on the internet.

Running Gitea myself gives me complete control over my data. No more worrying about private repo limits or service price hikes. For outsource projects or small startups, this is the most balanced solution between cost and performance.

Share: