Skip to content

Instantly share code, notes, and snippets.

@jazio
Created December 15, 2023 12:44
Show Gist options
  • Save jazio/e0d17b9bcd6c4549dec37db70cf38de0 to your computer and use it in GitHub Desktop.
Save jazio/e0d17b9bcd6c4549dec37db70cf38de0 to your computer and use it in GitHub Desktop.
Spin up a Jekyll Blog + git revisioning system

Spin up a Jekyll Blog + git revisioning system

TASK: Install Latest ruby, rvm, rubygems

NOTE: In order to have a jekyll pipeline these steps needs to be run on both local and on the server

WARNING: The following software to be installed under a specific user not root! I called it user: git because will build a git based deployment for a jekyll blog. I added git to the following groups: wheel, rvm, apache. Note later will remove wheel (centos's sudoers) group and transform the user in a non-interactive-shell

Install rvm (Ruby Version Manager). Note: unlike rubygems and bundler(package managers), rvm is a version manager gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB \curl -sSL https://get.rvm.io | bash source ~/.rvm/scripts/rvm rvm -v Check what versions are available rvm list known

Install ruby

rvm install ruby

note, the command will install all dependencies: sudo yum install curl gpg gcc gcc-c++ make patch autoconf automake bison libffi-devel libtool patch readline-devel sqlite-devel zlib-devel openssl-devel Or install a specific version

rvm install 2.5.7
ruby -v

Or specify another version

rvm use 2.5.6 --default

Check for troubles

rvm requirements
Warning! PATH is not properly set up, /home/git/.rvm/gems/ruby-2.7.1/bin is not at first place.
         Usually this is caused by shell initialization files. Search for PATH=... entries.
         You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles
         To fix it temporarily in this shell session run: rvm use ruby-2.7.1
         To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.
Checking requirements for centos.
Requirements installation successful.

If the above error occurs run

rvm reset

Update the system environment variables

source /etc/profile.d/rvm.sh

Add current user (spokane) to the rvm group

sudo usermod -aG rvm spokane
rvm reload
Note RVM reloaded! Yep!

You need that as dependencies for jekyll rubygems is a package manager: 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

Install dependencies (around 6M) It will install curl gpg gcc gcc-c++ make patch autoconf automake bison libffi-devel libtool patch readline-devel sqlite-devel zlib-devel openssl-devel

sudo dnf install ruby-devel @development-tools

Rubygems is a medium level package manager sudo dnf install rubygems

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

https://jekyllrb.com/docs/installation/ubuntu/ It is best to avoid installing Ruby Gems as the root user. Therefore, we need to set up a gem installation directory for your user account. The following commands will add environment variables to your ~/.bashrc file to configure the gem installation path. Run them now: 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 and bundler Display local gems gem list Install Jekyll Stattic Site Generator gem install jekyll

Install 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. gem install bundler

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 centos:

chmod +t /tmp
now you have a sticky bit
ll
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

Uninstall a gem

gem uninstall <gem-name>

Optional

gem install rails
rails -v

Check ruby versions and remove all ruby versions

rpm -qa | grep -i ruby
sudo yum erase ruby-*

WORKSHOP 1: FIRST PART Spin up a Jekyll Blog + git revisioning system, locally (ongoing)

Preliminaries: see above TASK: Install Latest ruby, rvm, rubygems, bundler and jekyll

if issue with permissions alias sudo='sudo env PATH=$PATH' jekyll new myjekyllsite cd myjekyllsite bundle exec jekyll serve --host localhost --port 8080 --detach ##Then visit: http://localhost:8080/

Note: In Amazon AWS Cloud9 you need to pas port 8080 to launch it jekyll serve --detach --port 8080 Now go to https://025dbc2f7f4a4dbbaf4caa9fcbe9cc4d.vfs.cloud9.eu-west-1.amazonaws.com/ where 025.. is your ID and tada!

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

On CentOS server cd ~/ mkdir awesomeblog.git && cd awesomeblog.git git init --bare cd hooks && touch post-receive && nano post-receive

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

##!/bin/bash -l

Install Ruby Gems to ~/gems
export GEM_HOME=$HOME/gems
export PATH=$GEM_HOME/bin:$PATH

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

git clone $GIT_REPO $TMP_GIT_CLONE
BUNDLE_GEMFILE=$GEMFILE bundle install
BUNDLE_GEMFILE=$GEMFILE bundle exec jekyll build -s $TMP_GIT_CLONE -d $PUBLIC_WWW
rm -Rf $TMP_GIT_CLONE
exit

Make it executable

chmod +x post-receive

Local

git remote add droplet [email protected]:repos/awesomeblog.git
git push droplet master
or,
git pull droplet master --allow-unrelated-histories
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment