brainsteam.co.uk/brainsteam/content/posts/2024/03/17/Moving from Gitea to Forgej...

164 lines
8.9 KiB
Markdown
Raw Normal View History

2024-09-08 15:00:57 +01:00
---
categories:
- Software Development
date: '2024-03-17 12:51:07'
draft: false
tags:
- devops
- docker
- forgejo
- gitea
title: Moving from Gitea to Forgejo including Actions with Docker Compose
type: posts
2024-09-08 17:23:07 +01:00
url: /2024/03/17/moving-from-gitea-to-forgejo-including-actions-with-docker-compose/
2024-09-08 15:00:57 +01:00
---
<!-- wp:paragraph -->
<p>I just moved from <a href="https://about.gitea.com/">gitea</a> to <a href="https://forgejo.org/">forgejo</a> and the process could not have been simpler. I'm really impressed. I suppose since the latter was <a href="https://forgejo.org/2024-02-forking-forward/">until very recently</a> a soft fork of gitea, I shouldn't be surprised at how easy it was. Still though, I sat down expecting to need to dedicate a few hours to debugging and it "just works" without a hitch after 15 minutes. The most jarring part was getting the actions runner working but the forgejo documentation is great, in fact I'd say better than gitea's docs, so in the end this wasn't a massive issue.</p>
<!-- /wp:paragraph -->
<!-- wp:heading -->
<h2 class="wp-block-heading">Why?</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>I have used gitea for hosting personal projects since about 2018 when I first became aware of it. I've been super impressed and I love the fact that it's so lightweight and simple to use. However, I've been a little disappointed by the founders' r<a href="https://blog.gitea.com/a-message-from-lunny-on-gitea-ltd.-and-the-gitea-project/">ecent-ish pivot towards commercialisation</a>. Don't get me wrong, I'm an open source maintainer and contributor myself and I know that many of these folks are essentially doing a public service for free. The final straw for me has been the recent announcement of Gitea Enterprise and <a href="https://blog.gitea.com/gitea-enterprise/">the direction they seem to be moving in </a>(open "core" with a bunch of paywalled features). </p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>I was a huge fan of Gitlab about 10-11 years ago but they have since heavily commercialised and gotten worse, caring less and less about their community and more and more about corporate user. The open core model can be ok if the features that are paywalled genuinely are things that only big companies care about or if bleeding edge features are open sourced after an embargo period or <a href="https://squidfunk.github.io/mkdocs-material/insiders/">once a funding milestone has been met</a>. However, I'm once bitten twice shy when it comes to these kinds of precedents in software forges so forgive my cynicism.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Forgejo was set up in response to Gitea's pivot towards commercialisation and their governance model is pretty much set up in a way to prevent the same thing happening again (I guess nothing is impossible but it is unlikely and there would be a lot of drama). For now I will throw in my lot with them.</p>
<!-- /wp:paragraph -->
<!-- wp:heading -->
<h2 class="wp-block-heading">How to Switch The Server</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>The server software was the easiest thing to switch. Following the instructions from forgejo, I simply replaced the name of the gitea image with the equivalent forgejo one in my <code>docker-compose.yml</code> and ran <code>docker-compose pull</code> followed by <code>docker-compose up</code>:</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Before:</p>
<!-- /wp:paragraph -->
<!-- wp:enlighter/codeblock {"language":"yaml"} -->
<pre class="EnlighterJSRAW" data-enlighter-language="yaml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> server:
restart: unless-stopped
image: gitea/gitea:1.21
container_name: gitea
environment:
- USER_UID=1000
- USER_GID=1000
volumes:
...</pre>
<!-- /wp:enlighter/codeblock -->
<!-- wp:paragraph -->
<p>And after:</p>
<!-- /wp:paragraph -->
<!-- wp:enlighter/codeblock {"language":"yaml"} -->
<pre class="EnlighterJSRAW" data-enlighter-language="yaml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> server:
restart: unless-stopped
image: codeberg.org/forgejo/forgejo:1.21
container_name: gitea
environment:
- USER_UID=1000
- USER_GID=1000
volumes:
...</pre>
<!-- /wp:enlighter/codeblock -->
<!-- wp:paragraph -->
<p>As soon as I ran this and started the server the whole thing came back up and apart from the new orange paint job, very little had changed about my server.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->
<!-- wp:heading -->
<h2 class="wp-block-heading">Swapping the Runner</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>The runner was slightly more painful because I had made <a href="https://brainsteam.co.uk/2024/01/20/gitea-forgejo-actions-and-postgresql-tests/">a couple of customisations</a> to my gitea actions runner before in order to get it running docker-in-docker (allowing me to push and pull images from inside the runner without those images appearing in the host system's user space)</p>
<!-- /wp:paragraph -->
<!-- wp:enlighter/codeblock -->
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> runner:
restart: unless-stopped
image: vegardit/gitea-act-runner:dind-latest
privileged: true
environment:
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: https://git.jamesravey.me
GITEA_RUNNER_REGISTRATION_TOKEN: "<redacted>"
GITEA_RUNNER_NAME: gitea-runner-1
GITEA_RUNNER_LABELS: "ubuntu-latest,ubuntu-22.04,ubuntu-20.04,ubuntu-18.04"
volumes:
- ./runner-config.yaml:/config.yaml
- ./runner-data:/data:rw
- ./runner-cache/:/cache
ports:
- 42263:42263</pre>
<!-- /wp:enlighter/codeblock -->
<!-- wp:paragraph -->
<p>Again, the documentation in forgejo is great and they provide an example for running docker-in-docker as a separate service and having the runner talk to it. All I had to do was change a couple of env vars and the runner image name:</p>
<!-- /wp:paragraph -->
<!-- wp:enlighter/codeblock -->
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> docker-in-docker:
image: docker:dind
container_name: 'docker_dind'
privileged: true
command: ['dockerd', '-H', 'tcp://0.0.0.0:2375', '--tls=false']
restart: 'unless-stopped'
runner:
restart: unless-stopped
links:
- docker-in-docker
depends_on:
docker-in-docker:
condition: service_started
container_name: 'runner'
image: code.forgejo.org/forgejo/runner:3.3.0
user: 1000:1000
command: forgejo-runner daemon
environment:
DOCKER_HOST: tcp://docker-in-docker:2375
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: https://git.jamesravey.me
GITEA_RUNNER_REGISTRATION_TOKEN: "<redacted>"
GITEA_RUNNER_NAME: gitea-runner-1
GITEA_RUNNER_LABELS: "ubuntu-latest,ubuntu-22.04,ubuntu-20.04,ubuntu-18.04"
volumes:
- ./runner-config.yaml:/config.yaml
- ./runner-data:/data:rw
- ./runner-cache/:/cache
- /var/run/docker.sock:/var/run/docker.sock
ports:
- 42263:42263</pre>
<!-- /wp:enlighter/codeblock -->
<!-- wp:paragraph -->
<p>Again, a quick test via <code>docker-compose up</code> and running one of my CI pipelines and voila, everything clicked into place:</p>
<!-- /wp:paragraph -->
<!-- wp:image {"id":2092,"sizeSlug":"large","linkDestination":"none"} -->
2024-09-08 17:23:07 +01:00
<figure class="wp-block-image size-large"><img src="/media/image-6-1024x222_a7f47ead.png" alt="a screenshot of a forgejo run with green ticks" class="wp-image-2092"/><figcaption class="wp-element-caption">Happy green ticks after the forgejo runner completes its run.</figcaption></figure>
2024-09-08 15:00:57 +01:00
<!-- /wp:image -->
<!-- wp:heading -->
<h2 class="wp-block-heading">Conclusion</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>If you were thinking about checking out forgejo for philosophical reasons or simply because you were curious and you're worried about switching from gitea, it couldn't be easier. If you are thinking about trying it out though, I'd strongly recommend taking a backup and/or spinning up a temporary or beta site where you can try it out before committing. Also bear in mind that<a href="https://code.forgejo.org/forgejo/runner#forgejo-runner"> Forgejo recommend not using their actions runner in prod yet</a> because it may not be secure enough. I don't let anyone else use or sign up in my instance and I'm pretty paranoid about what I do run there so I'm taking a calculated risk here.</p>
<!-- /wp:paragraph -->