Deploy Pelican blog with git on Linode
  |   Source

Ok, now I have a new blog with Pelican on my pc, but how I can deploy it to my remote server on Linode ?

Aside from the two ways already usable from the Makefile you have by default (ssh and rsync), it is possible to deploy also with Git.

Disclaimer

This mini-tutorial is not all mine, I got the informations from various sites and pages, and adapted it to my need. You can find a lot of similar solutions on the Web, many way older than mine. Additionally, I got inspired from the deployment of Hexo.io, another blog generator written in nodejs that I used some time ago, done with a git's hook.

Prerequisites

All you need is a working local Pelican blog, to install it you can follow the Pelican Documentation which explain really well how to do it.

Another thing you need to have is a working Linode's linode with shell access and a working git installation. It is not really important how big.

Step 1

Access your server and create a git repository for your blog

mkdir -p /path/to/your/repo
cd /path/to/your/repo
git init --bare

This create a bare Git repository that will not host any files but only the version control (see the git documentation for more info)

Step 2

In your repository create a hook caller post-receive in the hooks directory of your repository

#!/bin/bash -l
PATH=[your_user_path]
GIT_REPO=/path/to/your/repo
TMP_GIT_CLONE=/tmp/git/your_repo_name
PUBLIC_WWW=/path/to/your/web_root
git clone $GIT_REPO $TMP_GIT_CLONE
cp -a TMP_GIT_CLONE/* PUBLIC_WWW
rm -Rf $TMP_GIT_CLONE
exit

Step 3

In your local Pelican directory, clone your git repository of your blog, with the usual git command git clone [your_user]@your_serve:/path/to/your/repo output

The output at the end is important since it is the directory where Pelican generate your site.

At this point your are ready to deploy your site. You simply need to generate it using one of this ways: * pelican -lr * make html

I use the first option since it start a local server http://localhost:8000 which allow you to see your blog locally with a browser, but also the latest can be used.

Once you have generated the html files for your articles, pages and everything else, you just need to add, commit and push your repo t deploy your site

git add .
git commit -am "First article"
git push

at this point you should see something like this:

Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 338 bytes | 338.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Cloning into '/tmp/git/devel.grys.it'...
remote: done.
To git.grys.it:/home/git/devel.grys.it
   e6f9934..ec16614  master -> master

which is the message I got for this site. If you get an error, it will be displayed in the message to allow you to solve the problem (permission problem, missing directory, wrong path, whatever)

If no error is reported, congratulation, you just deployed your blog on your server, just open a browser and navigate to it to do a final check.

Comments powered by Disqus