Create your jekyll site:

gem install jekyll bundler
jekyll new
git init
git remote add origin ssh://

On the server create the git repo and install ruby

sudo apt-get install ruby-dev
git init --bare

Create the folders and files for nginx

sudo mkdir -p /var/www/vhosts/
sudo chown cicd /var/www/vhosts/
echo "server {
listen 443;

        gzip on;
        gzip_types      text/plain application/xml;
        gzip_proxied    no-cache no-store private expired auth;
        gzip_min_length 1000;

        root /var/www/vhosts/;

        location / {
                index index.html;

}" > /etc/nginx/sites-available/
sudo certbot --nginx -d

Certbot messed up the nginx config, you will need to look at your default config and correct it.

Clone Git Repo to local folder.

cd ~/
git clone /var/git/

Setup githook

echo "#!/bin/bash
bash /home/cicd/" > /var/git/
chmod +x /var/git/

In the script called by the githook the actual magic happens

cd /home/cicd/
unset GIT*DIR
git reset --hard
git checkout develop
git pull
bundle install
bundle exec jekyll clean && bundle exec jekyll build
rm -rf /var/www/vhosts/*
cp -r \_site/\* /var/www/vhosts/

And that’s it.

The important part is the third line, it clears some variables and makes the git command work. Without this line, the directory is not recognized as a git repo.

You can edit your site localy and debug it, using the command

bundle exec jekyll serve --incremental

when you are happy, commit your changes and push them, then the post-update hook will take care of the update.

The only caveat is updates to the build script take two pushes to take effect.