Jekyll GIT hooks
February 25, 2017
Premises:
- I host my jekyll git repo for this website both on the website server and my github account
- With only one commit/push I want to:
- update bot the git repo on the website server and the git repo on the github account
- launch the jekyll serve command an regenerate the jekyll website files
Steps:
- Create a working repo on the website server (in this case, called jekyll_files)
- Create an SSH key with my website server user and upload it to my github profile
- Add the github repo as a remote for my website server bare repo
git remote add github git@github.com:lucabaldesi/personal-website.git
- Create the post-receive file in the website server bare repo (folder hooks/):
#!/bin/sh REPO=github echo echo "==== Sending changes to $REPO repo ====" echo GIT_SSH_COMMAND="ssh -i /home/baldesi/.ssh/id_rsa_ans"\ git push --mirror $REPO echo echo "==== Generatin website files ====" echo exec /home/baldesi/jekyll_serve.sh
- Create a jekyll_server.sh file in my home folder on the website server
#!/bin/bash --login source /home/baldesi/.bashrc repo=/home/baldesi/jekyll_files cd $repo git --git-dir=$repo/.git --work-tree=$repo pull jekyll build --source . --destination /home/baldesi/public_html \ --config _config.yml,_config-prod.yml
The optional _config-prod.yml file contains the production environment variables.