Building static sites with Jekyll is all well and good, but as I tend to re-install my PC from time to time (just for fun or because I broke something beyond repair) I’m always left with getting the build environment for my site up and running again.
There are of course ways to create an automated build system inside git hosting, but that’s not my cup of tea. I like to be in full control of things and tend to do manual builds.
I also looked into using docker for building the site files, and that is a possible solution. Noticing it running through a ruby install on every run however made me feel it wasted a lot of time. Maybe that could be changed somehow but I didn’t want to investigate it. (call me lazy)
Where does that leave me? Well, a while back I started looking into LXD containers. They may be containers just as docker, but they behave more like a mini-virtual machine. This seemed like a fine fit for my requirements and would enable me to setup the build system once and just keep a backup of the image for later usage.
Incus command
The command to run a debian 12 instance is easy enough.
incus launch images:debian/12 jekyll
Programs
There are some standard programs I always install on a container.
apt install nano vim less git rsync exa openssh-server
User account
I’ll create a normal user account to use for generating the site files.
useradd -d /home/john -G sudo -m -s /usr/bin/bash -u 1000 -U john
Timezone
It’s a good idea to make sure the timezone is correct, otherwise jekyll may ignore (new) pages, as they are in the future. (it did on my installation)
dpkg-reconfigure tzdata
Jekyll static site generator
Jekyll requires some packages to be installed before it will work.
Install pre-requisites
apt install ruby-full build-essential
Add required environment variables
These are maybe not strictly necessary but makes it easier in the long run.
echo '# Install Ruby Gems to ~/gems' >> ~/.bashrc
echo 'export GEM_HOME="$HOME/gems"' >> ~/.bashrc
echo 'export PATH="$HOME/gems/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Install jekyll
gem install jekyll bundler
Add proxy to access jekyll from outside the container
This way I will have access to the preview of the site inside the container.
incus config device add jekyll myport4000 proxy listen=tcp:0.0.0.0:4000 connect=tcp:127.0.0.1:4000
First run
install the necessary bundles for the site to build.
bundler install
Build the Site Files
First get access to the container.
incus exec jekyll bash
Then change into the directory containing the site files.
cd jekyll
Now you can either serve the files for preview or build the final files ready to deploy to your web server.
bundle exec jekyll serve
or
jekyll build
Access to files from outside container
It would be easier to have access to the directory inside the container for doing the development. This requires using sshfs on the host system.
First find the IP address of the container. (Use lxc list.)
sshfs john@10.220.215.17:/home/john/jekyll /mnt/jekyll
Related Posts
Categories
Linux Debian Jekyll Container Virtualization