diyhosting/gitea.html

106 lines
5.2 KiB
HTML

<!DOCTYPE html>
<html lang=en>
<head>
<title>Setting up Gitea &ndash; diyhosting.bhh.sh</title>
<!--# include file=".nav.html" -->
</head>
<body>
<header><h1>Setting up Gitea</h1></header>
<nav></nav>
<main>
<img class=titleimg src="pix/gitea.svg">
<p>Gitea allows you to self-host your git repositories similar to <a href="git.html">bare repositories</a>, but comes with additional features that you might know from GitHub, such as issues, pull requests or multiple users. Its advantage over GitLab&mdash;another Free Software GitHub clone&mdash;is that it is much more lightweight and easier to setup.</p>
<p>Head over to <a href="https://gitea.com">gitea.com</a> to see what it looks like in practice.</p>
<p>Although Gitea is lighter than Gitlab, if you have a VPS with only 512MB of RAM, you will probably have to upgrade. Gitea is more memory-intensive than having just a bare git repository.</p>
<h2>Installing Gitea</h2>
<p>First install a few dependencies:</p>
<pre><code>apt install curl sqlite3</code></pre>
<p>Unfortunately, Gitea itself is not in the official Debian repos, so we will add a third-party repository for it.</p>
<p>Add the repo's gpg key to apt's trusted keys:</p>
<pre><code>curl -sL -o /etc/apt/trusted.gpg.d/morph027-gitea.asc https://packaging.gitlab.io/gitea/gpg.key</code></pre>
<p>Then add the actual repository to apt:</p>
<pre><code>echo "deb [arch=amd64] https://packaging.gitlab.io/gitea gitea main" > /etc/apt/sources.list.d/morph027-gitea.list</code></pre>
<p>Now we can install Gitea:<p>
<pre><code>apt update
apt install gitea</code></pre>
<p>Since apt automatically enables and starts the Gitea service, it should already be running on port <code>3000</code> on your server!</p>
<h2>Setting up a Nginx reverse proxy</h2>
<p>You should know how to generate SSL certificates and use Nginx by now. Add this to your Nginx config to proxy requests made to your git subdomain to Gitea running on port 3000:</p>
<pre><code>
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/ssl/nginx/<strong>git.example.org</strong>.crt;
ssl_certificate_key /etc/ssl/nginx/<strong>git.example.org</strong>.key;
server_name <strong>git.example.org</strong>;
location / {
proxy_pass http://localhost:3000/; # The / is important!
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
</pre></code>
<p>And reload Nginx:</p>
<pre><code>systemctl reload nginx</code></pre>
<h2>Setting up Gitea</h2>
<p>If everything worked fine you should now see a setup screen when you go to your configured domain in the browser. The options should be pretty self-explanatory, it is only important to select SQLite3 and to replace the base url and SSH server domain with your own.</p>
<dl>
<dt>Database Type:</dt>
<dd>SQLite3</dd>
<dt>SSH Server Domain:</dt>
<dd><strong>git.example.org</strong></dd>
<dt>Gitea Base URL:</dt>
<dd><strong>git.example.org</strong></dd>
</dl>
<p>These and other settings can be changed in a configuration file later so don't worry about making wrong decisions right now.</p>
<p>After clicking the install button you should now be able to log into your Gitea instance with the account you just created! Explore the settings for more things to do, such as setting up your SSH keys.</p>
<p>If Gitea does not load fully and has random errors, it is possible that you need to increase your available memory on your VPS. This can usually be done on your VPS-provider's website without too much trouble.</p>
<h2>A few extras</h2>
<h3>Automatically create a new repo on push</h3>
<p>This is an incredibly useful feature for me. Open up <code>/etc/gitea/app.ini</code> and add <code>DEFAULT_PUSH_CREATE_PRIVATE = true</code> to the <code>repository</code> section like so:</p>
<img src=pix/gitea-push-create.png>
<br>
<p>If you now add a remote to a repository like this</p>
<pre><code>git remote add origin 'ssh://gitea@git.<strong>example.org</strong>/<strong>username</strong>/<strong>coolproject</strong>.git'</code></pre>
<p>and push, Gitea will automatically create a private <code>coolproject</code> repository in your account!</p>
<h3>Change tab-width</h3>
<p>By default Gitea displays tabs 8 spaces wide, however I prefer 4 spaces. We can change this!</p>
<pre><code>mkdir -p /var/lib/gitea/custom/templates/custom/</code></pre>
<p>And write this into <code>/var/lib/gitea/custom/templates/custom/header.tmpl</code>:</p>
<pre><code>&ltstyle&gt
.tab-size-8 {
tab-size: 4 !important;
-moz-tab-size: 4 !important;
}
&lt/style&gt</code></pre>
<h2>Contribution</h2>
<ul>
<li><a href="https://phire.cc">phire</a></li>
</ul>
</main>
<!--# include file=".footer.html" -->
</body>
</html>