summaryrefslogtreecommitdiff
path: root/content/posts/2023/2023-03-08-using-laminar-for-selfhosted-ci.md
blob: 7c784b8d35cbdf43c1ce8c6e6fb0012a9ef90660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
---
date: 2023-03-08
title: Using Laminar for Self-hosted CI
tags:
- Bash
- CI
- Git
- Linux
---

I've hosted my [own git repositories](https://git.tyil.nl) for quite a while,
but I hadn't found a simple self-hosted CI solution yet. I've tried several,
and found them to be a bit too cumbersome to setup and actually put to use. The
majority requires you to host a full "git forge", such as GitLab or Gitea, in
order to use their webhook functionality in order to trigger a CI build. This
didn't seem worth the effort to me, so I kept looking for an alternative that
worked well for me.

I think I've finally found one in [Laminar](https://laminar.ohwg.net/), after a
suggestion from a friend on the Fediverse. I do wonder how I could've spent so
much time searching without ever finding this solution!

Laminar itself was easy to install from source, but another person chimed in to
let me know they already made an `ebuild` for it, which is available in their
overlay, making it even easier for me to try out. A single `emerge laminar`,
and a couple seconds of building it, and I was ready to start trying it out.

Configuration of jobs is done through scripts in whichever language you prefer,
giving you quite a bit of power. The documentation seems to mostly use Bash,
and that seemed to be a logical choice for me too, so that's what I've been
playing with as well.

Running jobs itself is as easy as `laminarc queue <name>`. It can't be much
simpler, and this CLI interface makes it very easy to start a new job from a
git `post-receive` hook. I wrote one which also shows the URL of the job's logs
whenever I push new comments to [the Bashtard
repository](https://git.tyil.nl/bashtard/about/).

{{<highlight bash>}}
while read old new ref
do
        laminarc queue bashtard \
                "GIT_BRANCH=$ref" \
                "GIT_COMMIT=$new" \
                | awk -F: '{ print "https://ci.tyil.nl/jobs/"$1"/"$2 }'
done
{{</highlight>}}

Using this, I can verify a job started, and immediately go to the page that
shows the logs. I plan to use Laminar's post-job script to leverage `ntfy` to
send me a notification on failed builds.

Since all the worthwhile configuration for Laminar is just plain text, it is
also very easy to manage in your preferred configuration management system,
which is also something I plan to do in the nearby future.

One slight annoyance I have so far is that I can't use (sub)directories for all
the job scripts. Since I don't have many yet, this isn't a real problem yet,
but it could pose a minor issue in the far future once I've written more job
scripts.

Given that that's the only "issue" I've found thus far, after a couple days of
playing with it, I'd highly recommend taking a look at it if you want to set up
a CI system for your self-hosted git repositories!