Deploy Jekyll Site To Server
Table of contents
Add a Jekyll site to your server, and set up to rebuild on a ‘git push’ to the server
Add Git User And Make Repository
First, you create a git user account and a .ssh directory for that user.
$ sudo adduser git
$ su git
$ cd
$ mkdir .ssh && chmod 700 .ssh
$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
Add your public keys to file.
Create /srv/git
$ cd /srv
$ sudo mkdir git
$ sudo chown -R git:git git
Create a blank repository in /srv/git
$ cd /srv/git
$ sudo mkdir project.git
$ cd project.git
$ sudo git init --bare
If you want to restrict access to shell
$ which git-shell
add to /etc/shells
$ sudo chsh git -s $(which git-shell)
what i did:
$ sudo chsh git -s /bin/zsh
Install Jekyll and Create Hook to Build on Git Push
Install dependencies
$ sudo apt-get install ruby-full build-essential zlib1g-dev
ADD TO BASHRC or ZSHRC
echo '# Install Ruby Gems to ~/.gems' >> ~/.zshrc
echo 'export GEM_HOME="$HOME/.gems"' >> ~/.zshrc
echo 'export PATH="$HOME/.gems/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
(you might want to $ screen this next one. it takes awhile)
$ gem install jekyll bundler
$ cd /srv/git/project.git/hooks
$ vim post-receive
Input:
#!/bin/bash -l
# Install Ruby Gems to ~/.gems
export GEM_HOME=$HOME/.gems
export PATH=$GEM_HOME/bin:$PATH
TMP_GIT_CLONE=$HOME/tmp/PROJECT.git
GEMFILE=$TMP_GIT_CLONE/Gemfile
PUBLIC_WWW=/var/www/SITE/site
git clone $GIT_DIR $TMP_GIT_CLONE
BUNDLE_GEMFILE=$GEMFILE bundle install
BUNDLE_GEMFILE=$GEMFILE JEKYLL_ENV=production bundle exec jekyll build -s $TMP_GIT_CLONE -d $PUBLIC_WWW
rm -Rf $TMP_GIT_CLONE
exit
$ chmod +x post-receive
$ sudo mkdir /var/www/SITE/site
$ sudo chown -R git:git /var/www/SITE/site
IF you get this warning:
warning: remote HEAD refers to nonexistent ref, unable to checkout.
Go to the repository and execute this where BRANCHNAME is the name of the branch:
$ git symbolic-ref HEAD refs/heads/BRANCHNAME
Seems to be working…
Who knows how much I did that I didn’t document…at least a bit…