CI/CD! Who Needs ‘Em?

#CI #CD #Git

I began trying out various CI/CD solutions last week. Spinning up new Jails, configuring reverse proxies and certs, to finally walk away thinking: “wow, all this just to write a little sh after a git push to the main branch?”

I deleted the Jails.

If all you want to do is write a little sh after a git push, this is what I would and did do: wherever you host your Git: SSH in and find your repository’s hooks directory.

find / -type d -name hooks | grep \.git

Create a new sh script named post-update. This script will be executed (on your Git server) once a git push has successfully executed. Don’t forget to make the file executable.

Here’s an example of a post-update script very similar to one a project of mine uses:

#!/bin/sh

BIN='...'
TMP=$(mktemp)
SERV='...'
TOUT='...'
TUSER='...'
THOST='...'
TPORT='...'

ssh -p $TPORT $TUSER@$THOST "
        wget --quiet -O $TMP $BIN
        chmod +x $TMP
        yes | mv $TMP $TOUT
        service $SERV restart
"

You’ll notice this script downloads a binary, replaces a different binary with the downloaded binary on the target machine, and restarts an rc.d service. I create a binary on an internal network as part of a pre-commit hook (but you could create this binary on your Git server instead — honestly, probably a better idea.)

I suggest reading the githooks documentation.

EOF