Deployment of Jekyll-Sites using Git Bare Repository on a Linux🐧 webserver e.g. uberspace🚀.
The script can be used in 2 ways:
In both cases the same config (deploy.conf) is used.
The script executes the following steps:
bundle install
jekyll build
to our document root$post_exec
that can be configuredOn your target machine, you will need to install Jekyll and Bundler.
See Jekyll on Linux for details.
You need to add all ssh public keys that should be able to deploy to ~/.ssh/authorized_keys on your target machine.
We need to create a bare git repository on your target machine.
We start after successful ssh-login on our target host in our home directory and create a directory for our repositories.
mkdir repos
change into...
cd repos
and create another directory to which we want to push. In the following example the directory is named like our domain. (From here on you should substitute florian.latzel.io with your domain.)
mkdir florian.latzel.io
change into...
cd florian.latzel.io
now we initialise the directory as bare repository.
git init --bare
At first we remove the post-receive from the git repository (if exists), to replace it later with a symbolic link to our script:
rm ~/repos/florian.latzel.io/hooks/post-receive
We clone the Jekyll Deployment Skript into above created repo directory:
git clone https://github.com/fl3a/jekyll_deployment.git ~/repos
Now we create a symbolic link named post-receive in our git bare repository which source is the same named script from Jekyll Deployment Skript:
ln -s ~/repos/jekyll_deployment/post-receive ~/repos/florian.latzel.io/hooks/post-receive
At last, we need to make script executable:
chmod +x ~/repos/jekyll_deployment/post-receive
Set a symbolic link to directory which is your $PATH
.
(On uberspace it is ~/bin
by default).
ln -s ~/repos/jekyll_deployment/post-receive ~/bin/jekyll_deployment
On your target machine, add the following line to ~/.bundle/config:
BUNDLE_PATH: "~/.gem"
Copy deploy.conf to your sites repository, edit the variables, commit and push it.
So the script can read its config from the repository.
These are the mandatory variables, you must change them according your needs:
(If you are on uberspace🚀 like me,
www
path schema will already fit😙)
build_branch
, the branch that should be build (pushes to other branches will be ignored) e.g. main
domain
, name of your domain e.g. 'example.com'
git_repo
, path to your Jekyll Git-Repository e.g. "${HOME}/repos/${domain}.git"
www
, path to document root, destination for the generated html e.g. "/var/www/virtual/${USER}/${domain}"
For optional variables have a look at the corresponding comments in deploy.conf and the examples below.
On your local machine, you need to add a remote repository,
in below example named uberspace
to your local git repository.
git remote add uberspace [email protected]:repos/florian.latzel.io
Now you can push your branch e.g. main to your remote uberspace
and might see the output from git clone
, bundle install
and jekyll build
after the transmission of your changes.
git push uberspace main
From your repository on your local machine you will just type git push uberspace
and your site will be depoyed in a few moments.
On your target machine (where the HTML is generated and served) type jekyll_deployment
with path to your bare respository as argument:
jekyll_deployment ~/repos/florian.latzel.io
This might be useful if you want to rebuild your site without having changes to push.
E.g. your deployment fails and you want to investigate where and why.
$post_exec
, rebuilds cv after deployment)site.github
vars)This script is based on Jekyll Auf Uberspace Mit Git from Daniel Wittberger.
Thanks for sharing🙏!
Since 2013 jekyll and uberspace changed a bit and this script itself experienced a lotta love👨💻💕.