Tackle dependencies

. You will use ruby (programming language interpreter) using rvm (ruby installer),

For ruby visit: https://www.ruby-lang.org/en/ For installing rvm https://rvm.io/rvm/install

rvm get stable

Install ruby (using rvm) and set it’s latest version as default. You may remove old relics: older versions of ruby. Check the latest version of ruby on their site.

rvm install ruby-3.1.0
ruby -v
rvm use 3.1.0 --default
rvm remove ruby-2.3.0

You might need to add the current user (spokane) to the rvm group: sudo usermod -aG rvm spokane

You need to manage your software dependencies with rubygems. Ruby, at its lowest level, doesn’t really have “libraries” built in. It has the ability to “load” or “require” a file, and it has $LOAD_PATH, an array of paths to check when you ask for a filename. Rubygems is a medium level package manager sudo dnf install rubygems. The rubygems is invoked using the command gem.

Make sure you’ll have latest lists gem update. Then check the system overall: gem update --system

It is best to avoid installing Ruby Gems as the root user.Therefore, we need to set up a gem installa tion directory for your user account.The following commands will add environment variables to your ~/.bashrcfile to configure the gem installation path.

Run the following lines in the terminal. They will add some paths so that gem will find them later:

echo 'Install Ruby Gems to ~/gems' >> ~/.bashrc
echo 'export GEM_HOME="$HOME/gems"' >> ~/.bashrc
echo 'export PATH="$HOME/gems/bin:$PATH"' >> ~/.bashrc

Reclaim them immediately: source ~/.bashrc

Install Jekyll Static Site Generator

Display local gems with gem list. Use grep find any module.

. jekyll is itself a gem.

Install jekyll’s bundler package manager (is a gem). Note bundler is expected to run from project folder. Bundler is the equivalent of PHP composer for Ruby world. It writes a file called Gemfile. Gems are locked in a Gemfile.lock. Gems can be fetched from ‘https://rubygems.org’ or any other source specified from Gemfile with keyword source. Bundler is a much more powerful, complex and subtle tool than RubyGems. While gem can be used a system level and at project level, bundle It will replace gem at project level. Install them both at once

gem install jekyll bundler
jekyll -v

Add your repository to git cd myjekyllsite git init git add . git commit -m “Initial commit”

WORKSHOP 1: PART 2 Deploy jekyll with git hooks

Preliminaries: (1) see above TASK: Install Latest ruby, rvm, rubygems, bundler and jekyll (2) Execute PART 1

In this section we will deploy our project based on hooks your-project/hooks/post-receive

On RHEL server

cd ~/
mkdir jazio.eu.git && cd jazio.eu.git
git init --bare
cd hooks && touch post-receive && vim post-receive

In post-receive hook paste, the following script. Don’t forget to replace jazio.eu.git with your specific project name

#!/usr/bin/env bash

GIT_REPO=$HOME/jazio.eu.git
TMP_GIT_CLONE=/tmp/jazio.eu.git
PUBLIC_WWW=/var/www/html/jazio.eu

git clone $GIT_REPO $TMP_GIT_CLONE
pushd $TMP_GIT_CLONE

tmp_dir=$(pwd)
printf '%s\n' "You are in .. ${tmp_dir}"
sleep 5
printf '%s\n' "Output in... ${PUBLIC_WWW}"
bundle exec jekyll build -d $PUBLIC_WWW
popd

rm -rf $TMP_GIT_CLONE

exit

Make it executable: chmod +x post-receive

Here is an improved version

#!/usr/bin/env bash

# This is added lately to ensure the environment won't change
export PATH="/home/git/.rvm/gems/ruby-3.1.0/bin:$PATH"
export GEM_HOME="/home/git/.rvm/gems/ruby-3.1.0"
export BUNDLE_PATH="/home/git/.rvm/gems/ruby-3.1.0"

GIT_REPO=$HOME/jazio.eu.git
TMP_GIT_CLONE=/tmp/jazio.eu.git
PUBLIC_WWW=/var/www/html/jazio.eu

# Perform a cleaning
rm -rf $TMP_GIT_CLONE

# Clean cloning
git clone $GIT_REPO $TMP_GIT_CLONE

# Switch Remember the temp folder.
pushd $TMP_GIT_CLONE

# Ensure dependencies are correctly set in the cloned repo before running Jekyll:
cd $TMP_GIT_CLONE
bundle install --path vendor/bundle

# You are in the /temp folder now
tmp_dir=$(pwd)
printf '%s\n' "You are in .. ${tmp_dir}"
sleep 5
printf '%s\n' "Output will go in... ${PUBLIC_WWW}"

# Create/Update the site (all the content from _site folder)
bundle exec jekyll build -d $PUBLIC_WWW --trace



popd
rm -rf $TMP_GIT_CLONE
echo "Executing post-receive hook at $(date)" >> /tmp/post-receive-debug.log
exit

Now every time you git push origin your files, the post-receive script will deploy and build your site on the server in place.

Troubleshooting

If jekyll won’t run in a specific directory try to run post-receive hook line by line A possible issue causing it the missing /tmp file set as so in linux server:

chmod +t /tmp

Now you have a sticky bit (all of the files in that directory will be modifiable only by their owners). We don’t want other users will modify it.

drwxrwxrwt.  11 root root 4096 Jun 26 19:03 tmp

chmod 777 /tmp removes the sticky bit from the directory. Without the sticky bit, anyone can remove, rename or replace a file from/in the directory at any time Delete Gemfile.lock and run again the bundle install to rebuild all project gem’s dependencies bundle install

bundle config set path '/home/git/gems'
bundle install

bundle config list
Settings are listed in order of priority. The top value will be used.
clean

Set for the current user (/home/git/.bundle/config): true
Set for your local app (/var/www/html/jazio.eu/.bundle/config): "/home/git/gems"
Set for the current user (/home/git/.bundle/config): "/home/git/gems"