DEV Community

Brandon Rozek
Brandon Rozek

Posted on • Originally published at brandonrozek.com on

Mirroring with Gitea

Sites like Github, Gitlab, and BitBucket have nice UIs that make looking at commit diffs and issue tracking easier. However, this requires an internet connection. What if we can mirror the content from these sites locally? Gitea comes to the rescue!

Installation

Download gitea and make it executable.

wget -O gitea https://dl.gitea.io/gitea/1.13.0/gitea-1.13.0-linux-amd64
chmod +x gitea

Enter fullscreen mode Exit fullscreen mode

Create the stow directory

sudo mkdir /usr/local/stow/gitea-1.13.0

Enter fullscreen mode Exit fullscreen mode

Start by moving the executable to this directory

sudo mkdir /usr/local/stow/gitea-1.13.0/bin
sudo mv gitea-1.13.0-linux-amd64 \
        /usr/local/gitea-1.13.0/bin/

Enter fullscreen mode Exit fullscreen mode

Add a git user that gitea will use.

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

Enter fullscreen mode Exit fullscreen mode

Create directories gitea expects.

sudo mkdir -p /usr/local/stow/gitea-1.13.0/var/lib/gitea/{custom,data,log}
sudo chown -R git:git /usr/local/stow/gitea-1.13.0/var/lib/gitea
sudo chmod -R 750 /usr/local/stow/gitea-1.13.0/var/lib/gitea

sudo mkdir -p /usr/local/stow/gitea-1.13.0/etc/gitea
sudo chown root:git /usr/local/stow/gitea-1.13.0/etc/gitea
sudo chmod 770 /usr/local/stow/gitea-1.13.0/etc/gitea

Enter fullscreen mode Exit fullscreen mode

Stow gitea

cd /usr/local/stow
sudo stow gitea-1.13.0

Enter fullscreen mode Exit fullscreen mode

Systemd Service

Edit /usr/lib/systemd/system/gitea.service.

[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
Requires=nginx.service

[Service]
Type=simple
User=git
Group=git
WorkingDirectory=/usr/local/var/lib/gitea
ExecStart=/usr/local/bin/gitea web --config /usr/local/etc/gitea/app.ini
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/usr/local/var/lib/gitea

[Install]
WantedBy=multi-user.target

Enter fullscreen mode Exit fullscreen mode

Start and enable gitea.

sudo systemctl start gitea
sudo systemctl enable gitea

Enter fullscreen mode Exit fullscreen mode

Gitea Setup

Go to http://localhost:3000/install

Check “Enable Local Mode” For security, check “Disable Self-Registration” and “Require Sign-In to View Pages” Setup the “Administrator Account Settings”

Nginx Setup

Edit /etc/nginx/sites-available/gitea.conf

location /gitea/ {
    proxy_pass http://localhost:3000/;
    proxy_http_version 1.1;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr; 
    proxy_set_header Host $host;
}

Enter fullscreen mode Exit fullscreen mode

Enable the site

sudo ln -s \
        /etc/nginx/sites-available/gitea.conf \
        /etc/nginx/sites-enabled/
sudo systemctl restart nginx

Enter fullscreen mode Exit fullscreen mode

Apache HTTPD Setup

Edit /etc/httpd/conf.d/gitea.conf

<Location /gitea>
    ProxyPass http://localhost:3000 retry=0 timeout=5
    ProxyPassReverse http://localhost:3000
    ProxyPreserveHost On

    Order allow,deny
    Allow from all
</Location>

Enter fullscreen mode Exit fullscreen mode

Restart httpd

sudo systemctl restart httpd

Enter fullscreen mode Exit fullscreen mode

Mirroring

To mirror a repo, first click on the plus sign and select “New Migration”, then make sure to check the “This repository will be a mirror”.

Top comments (0)