diy code hosting with gitea and

Posted on
Updated on
1346 words, 7 minute read

Setting the Scene

Inspired by the Give Up Github campaign, I recently decided I wanted to spin up my own instance of Gitea. There are free (as in beer), free (as in freedom), public instances of Gitea and other FOSS-leaning code forges, but self-hosted Gitea struck me as a nice way to take even a bit more ownership over my own code.

I maintain a small PC running in my home as a server for a few services running via Proxmox, but I am really dissatisfied with my workflows for managing that box lately (picture SSHing into LXC containers and manually editing systemd configurations... yuck). I recently read a couple of different articles singing the praises of, a platform as a service (PaaS) that replicates most of the good parts of the classic Heroku developer experience. Further enticed by their ample free tier, I took the plunge and created a account.

Getting Started

First things first: in order to interact with, we primarily use the flyctl command line tool. It's available from a variety of sources:

# Nix
nix-shell --packages flyctl
nix-env --install --attr nixpkgs.flyctl

# macOS
brew install flyctl

# Linux + non-Homebrew users
curl -L | sh

# Windows users
iwr -useb | iex

flyctl can handle signing up for a account if you haven't done that, otherwise you can use it to sign in:

# Opens your browser to set up an account
# This step requires a credit card, in the event you exceed the free tier limits
# See for details
flyctl auth signup

# Opens your browser to sign in
flyctl auth login

Configuring Apps with flyctl

In order to avoid even the appearance of disorganization, we'll start off with a git repository for tracking our configurations:

mkdir fly-apps; cd fly-apps
git init
mkdir gitea; cd gitea

Next up, we create our app configuration and register it with flyctl takes care of this for us in a single command, flyctl launch. The command will prompt you interactively for some input, but here we'll just pass some flags directly:

flyctl launch \
  # use the official Gitea docker image \
  --image gitea/gitea:latest \
  # give our instance a unique name, this will be used to generate a development hostname like \
  --name gitea-mat-services \
  # region where the app runs, don't supply this option if you want to interactively choose a region \
  --region ewr \
  # don't immediately deploy, we need to edit our fly.toml first \

# don't forget to commit!
git add fly.toml
git commit -m "Add default generated configuration"

We will also need a volume for persisting git repositories:

# Create a 3GB volume
# Note: this will consume your entire free tier allotment for volume storage!
flyctl volumes create gitea_data
# Alternatively, create a smaller volume
flyctl volumes create gitea_data --size 1

Now our app is ready to deploy, but first we're going to make some changes to the fly.toml configuration that was generated for us. Gitea has their own post on which includes a sample configuration, and we can reference that to end up with something like the following:


+   GITEA____APP_NAME = " Gitea for me"
+   GITEA__database__DB_TYPE = "sqlite3"
+   GITEA__database__PATH = "/data/gitea/gitea.db"
+   GITEA__server__DOMAIN = ""
+   GITEA__server__SSH_DOMAIN = ""
+   GITEA__server__ROOT_URL = ""
+   GITEA__security__INSTALL_LOCK = "true" # Don't show installer
+   # GITEA__service__DISABLE_REGISTRATION = "true" # TODO: uncomment once you have created your first user

+ [mounts]
+   destination = "/data"
+   source = "gitea_data"


+ # ssh traffic
+ [[services]]
+   internal_port = 22
+   protocol = "tcp"
+   [[services.ports]]
+     port = 22

-   internal_port = 8080
+   internal_port = 3000

Don't forget to save your work!

git add fly.toml
git commit -m "Add Gitea specific configuration"


The stars are aligned. The witching hour has arrived. Let's deploy our app:

flyctl deploy

After flyctl does its thing, your Gitea instance should be up and running at https://<your-app-name>! For the extremely lazy, flyctl will do the work for you:

flyctl open

Now you can register your account! If you want to keep your Gitea instance private, uncomment the last line in the env section and rerun flyctl deploy after registering.

Bonus Round: Configuring Your Custom Domain with

Some, like myself, will not be satisfied accessing their Gitea instances with a URL. Thankfully, makes it a breeze to configure a secure custom domain with the help of LetsEncrypt. and flyctl seem to offer tooling for managing your domains and DNS records entirely within the system, but I personally didn't explore this route, as my own domains and DNS records are managed elsewhere. Whatever you use to manage your own domains and DNS, you will need to create two records for your domain name corresponding with the IPv4 and IPv6 addresses of the application:

flyctl ips list
TYPE ADDRESS             REGION CREATED AT           
v4             global 2022-07-03T04:39:18Z 
v6   dead:beef:1::a:a    global 2022-07-03T04:39:19Z 

Create an A record for the v4 address, and an AAAA record for the v6 address. With those records in place, flyctl can automatically perform the necessary setup with LetsEncrypt to secure your domain:

flyctl certs add
flyctl open

Now it's time to revel in your new code hosting powers.

The First Push (or, 256MB just isn't enough sometimes)

With everything now set up, let's go ahead and kick the tires on our new Gitea installation. We can push our fly-apps repository to Gitea as a test. Create a new blank repository on Gitea with an appropriate name, then add that as a remote for your local repo:

git remote add origin

And now it's as easy as one simple command!

git push --set-upstream origin main
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 195 bytes | 195.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Gitea: Internal Server Error
Gitea: Internal error
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to ''

Uh. Hm. I just got an email saying a instance ran out of memory and crashed. Let's peek at our dashboards: memory dashboard memory dashboard

That doesn't look so great. It seems like Gitea idles just under the amount of memory we have with a default instance size, and operations like git push can bump it over the threshold to an out-of-memory error. Let's check out the "Scale" section of the dashboard, and increase the memory allotment for this VM: VM scaling interface VM scaling interface

You can also use flyctl to scale your app!

flyctl scale memory 512

I have been running my Gitea install on a 512MB instance since the first day I started using it, which seems to be plenty of headroom for personal use. If you open up your Gitea installation to the public and it starts to get popular, you might end up needing to scale up further.

It's worth noting that scaling up to 512 MB means you will start accruing a balance, but so far this has never been more than a $2 monthly bill for me. If that's too steep for you, consider that doesn't (at the time of this writing) charge for monthly bills below $5, or else check out some of the competing PaaS options out there.