It has been quite some time (about a month) that I decided to put the server I had rented to some use, since it was sitting nearly idle since last few years. So what did I do? of course, I started off with GitLab. In my immediate circles, most people know me as a guy who does not like spending much on software subscriptions and I for sure do not like handing over my data either.
Gitlab made some sense, not a lot; at least in the beginning anyway. I started with something called Gitea which is a quite lovely service which can get you all the basic stuff - hosting git repos, issues, tasks, collaborations, pull-requests, diff views etc. Recently they also added the ability to create a container repo. Honestly, I have not explored the tool in its entirety.
I was happy!
I was happy using Gitea but then, one day, chatting to my good friend logiczilla, he said he uses Gitlab and has been using it since quite some time. So I thought “why not? Let me try Gitlab as well!”
Now I wasn’t new to GitLab. I use it at work, I once installed it on my server too and deleted. So this time, I decided to give it some serious try!
Setting up Gitlab has been good. There is mostly success (with a number of lessons). And as of now, I am using GitLab for quite a bit. One of the things that I hate about GitLab CE (the free edition) is that it does not allow me to create “pull mirrors”. Since I have most of my stuff on GitHub still and am not confident with GitLab yet, I need to keep the rest of my stuff, the workflow and scripts as it is. But I did manage to Create a pull-mirror on GitLab CE and after that, it was working well enough.
CI/CD and the rest
I don’t always get a lot of time, so it took me quite some time to get the CI/CD part done right. I have my gitlab runner setup on the same machine. I ran it inside a zellij session, and voila … well, it did not work.
It took me quite some time (and a lot of documentation reading to understand how it all works). You need to create the .gitlab-ci.yml
file. Then you setup your actions in the repo settings. Then you register a runner. If you have selected a docker executor, you gotta know how to use artifacts, where the repe gets cloned inside the container and so on! Then you make a commit and test.
I had to do multiple cycles of those to figure it all out. But in the end, it worked.
The Final flow
Right now, I have configured my setup in the following manner:
- A cron job on my laptop runs every 1 minute and pushes any changes I make to this repo (as an Obsidian vault) to the remote (which is on Github). This I have had for years now.
- Every 1 hour and 2 minutes, it gets updated to GitLab (the how is covered in Create a pull-mirror on GitLab CE article). I can reduce the interval but this blog is not super critical to me anyway. So 1 hour is fine by me.
- GitLab calls my runner.
- The runner builds my site and places the contents in a directory.
- Caddy serves the site.
And all of this happens without me interfering manually.
Yeah, that’s kinda more work than required, but I think it made me learn quite some about setting up CI/CD, GitLab and GitLab runner. And yes, if you want to understand how most of the gitops is done, just go through the amazing documentation GitLab has for you. It is way better than what I find GitHub has. The scope of their documentation itself is large enough to help you imagine how CI/CD solutions should be made!