Noah Luskey
  • Resume

Make your own CI/CD - Sat, Jun 8, 2019

Why even use a Continuous Integration service? Just make your own. It’s actually not that hard (if you’re doing something simple).

Background

I have a website. You’re reading it right now. It’s made of a git repository that contains a bunch of markdown and gets compiled into html by a program called hugo.

At one point, I was using gitlab to do this. But why? I already have a server. Let’s just put everything in once place.

How it works

  1. Make your webserver a git server
  2. Also install whatever you need to compile your repo on your webserver
  3. Add a super simple script to hooks/post-update and watch the magic

1 and 2, you can figure out.

3 is below:

#!/bin/sh

worktree=/var/www/noahluskey.com/
GIT_DIR=${worktree}/.git
cd ${worktree}
git checkout master
git reset HEAD .
git reset --hard HEAD
hugo    

exit 0

Now, you push, and the server takes care of the rest.

Writing objects: 100% (5/5), 409 bytes | 409.00 KiB/s, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: Already on 'master'
remote: M       content/about/index.md
remote: Unstaged changes after reset:
remote: M       content/about/index.md
remote: HEAD is now at 2831407 "Test commit"
remote: 
remote:                    | EN  
remote: -------------------+-----
remote:   Pages            | 11  
remote:   Paginator pages  |  0  
remote:   Non-page files   |  0  
remote:   Static files     | 11  
remote:   Processed images |  0  
remote:   Aliases          |  1  
remote:   Sitemaps         |  1  
remote:   Cleaned          |  0  
remote: 
remote: Total in 76 ms
To noahluskey.com:/srv/git/noahluskey.com.git

Why?

Because it’s way faster, it’s way simpler, and you control every aspect of your pipeline.

Cheers.

Back to Home


© Noah Luskey 2020

Linkedin GitHub