Intro
I recently realized I had no easy way to spin back up services in my home lab... and that could be a problem. I have over 30 services running at any given time. Version controlling my home lab was truly a game-changer. It has helped me start to get more organized, track changes, and know what worked without fear of things permanently breaking. My home lab work has directly led to success in my career.. and implementing practices like version control is a great example.
Core
So you may be wondering where to get started with version controlling your home lab. There are two main options: use your own version control service or use a service like GitHub. I'm doing both. You might ask what the benefits of using your own service, so here’s a breakdown of some pros and cons.
I am specifically highlighting three positives and two negatives for each option. The lists below are not exhaustive, because there can be arguments made either way. I actually chose to do a mix of both.
DIY version control
Pros
Plenty of options (Gitea and Gitlab to name two)
Increased security by keeping it local
Learn extra tools that expand your skill set
Cons
Risk of data loss if hardware fails
Learning curve to implement from scratch
GitHub version control
Pros
Less configuration to manage
Still secure with proper configurations
Public portfolio of skills for future employers
Cons
Risk of exposing private/sensitive with misconfigurations
Less control over data
After deciding on the version control method, I recommend using Portainer to manage any containerized services. Portainer simplifies the process and integrates well with Git repositories. You don't need to setup your own runners to deploy code, for example.
Organize your repo
It is important to use a decent structure. Below is a starter structure to organize your home lab. I recommend at least setting up each service group within its own directory. Inside each folder, include the .env
needed, and add your .env
to your .gitignore
!!!!
git_repo
|-- <service name>
|-- .env
|-- docker-compose.yml
|-- <service name>
|-- .env
|-- docker-compose.yml
Setting up Portainer with Git
Setup Portainer CE (If not already configured).
docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
Complete Portainer setup steps available at their docs here.
Link Your Git Repository
Navigate to Stacks and select Add Stack
Choose Repository as deployment method, and enter URL the Git repo is accessible from
For authentication, set up a Personal Access Token instead of using your Git password. This is more secure.
Automatically Sync
Set Portainer to automatically sync at the desired interval for your needs (10m, 1h, 8h, 12h, etc)
Conclusion
These basic steps should get you going with some ideas to improve your home lab's resiliency. The skills you learn with this can be beneficial in DevOps, system administration, and almost any developer role.