How to test a system (in isolation) which needs to `git clone`

https://github.com/ryan0x44/local-git-server

Today I was trying to create a pipeline-as-code using Kotlin and TeamCity. I’m a huge fan of fast Feedback Loops, so my first thought was: how can I test these changes faster. And my second thought was: how can I eventually automate testing these changes.

In particular, when experimenting with the settings.kts file of the Kotlin DSL, the way you test this is to put it under a .teamcity directory in the root of your Git repository and then loading that repository in the TeamCity UI. However, that meant pushing up a settings.kts to a Git repository — and if I wanted it to be extra fast, making that repository public (rather than having to enter credentials every time I went through the ‘Create Project’ flow).

Then it hit me: what if I could expose my local settings.kts file through a local HTTP/Git server (ideally running in a Docker container)? And local-git-server was born!

Introducing Local Git Server

In a sentence: it’s a minimalistic Alpine-based Docker image for running a local HTTP Git server using Lighttpd.

WARNING: this tool is not designed for use in production. If you’re going to that, please please please use a server which supports TLS/HTTPS or SSH. This tool is HTTP-only, so communication is not encrypted. Further, I’ve tried to keep all configuration to the minimum required to make it easier for a newcomer to grok and to customise — it certainly has not been hardened.

Leveraging Git built-ins & Lighttpd

It turns out, the git tool comes with a HTTP backend built-in! It’s called git-http-backend — it’s a simple CGI program, so all it needs is a web server in front to handle.

For a web server, while you could look at something more heavyweight like Apache or Nginx+additional modules, I opted for Lighttpd which is leightweight AND comes with all required modules (including for CGI) built-in.

Getting Started

It’s a matter of cloning the repo, tweaking the volume mount in thedocker-compose.yaml, and starting up the container. For more details head to https://github.com/ryan0x44/local-git-server and follow the README.

Note: I could also make it as easy as publishing a Docker image that you could run with a single-line command, so if there’s demand I might hook that up :)

Integration Testing Git in CI/CD

While this tool was initially created for running locally, at some point I might create an End-To-End Test which checks a locally-running TeamCity instance can load configuration from a Git repository — and that’s where this tool could come in handy.

By being able to run a Git server locally, any integration test against a Git repository could be done in isolation from the web (great for reliability and security of your CI/CD builds!). All you need to do is run this container as part of your CI/CD pipeline, with the Git repo’s you want to test mounted in its volume.

In future I’m hoping to share how I’m using this tool in a broader development flow for testing changes to TeamCity pipelines-as-code. But I hope this tool has other uses too!

--

--

--

#DevOps, #Security, Go (#golang), #Linux, #Docker, #Kubernetes. Senior Engineering Manager @Xero. Previously: DevTools EM @Cloudflare. Opinions are my own.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Top 10 Tips on Developing Your Problem Solving Skills and Levelling Up Your Coding!

Linux Walkthrough: abif installer/ArchLabs installation (DEPRECATED)

cuda 11 installation on ubuntu 20.04

Oops! Deleted the Terraform state file. Imported the resource but now it wants to recreate it!

Django Dashboards — Iconic UI Kits coded in Django

Django Dashboard — CoreUI Design.

React/Redux/Rails — My Final Project for Flatiron School

How to Make Sysadmins More Human

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ryan D

Ryan D

#DevOps, #Security, Go (#golang), #Linux, #Docker, #Kubernetes. Senior Engineering Manager @Xero. Previously: DevTools EM @Cloudflare. Opinions are my own.

More from Medium

Handy MySQL Commands-II

Top 10 Automated Testing Software

Object Oriented Concepts in SAP ABAP….An Introduction to Object Oriented Programming.

2. Setting up your git repository