Software by Steve

Sep 25, 2014

Publishing and Deploying for Pelican with Fabric

I recently switched to Pelican to build this site. I'm very happy with everything it offers, but wanted to tweak how the site gets deployed to the remote server. This is where Fabric comes in. Fabric is a "library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks." I've used Fabric for plenty of automation tasks before, so I knew it'd fit the bill perfectly.

If you use the pelican-quickstart command, it offers to build a that comes with a publish method. I just needed to change the default implementation; I wanted to push everything to GitHub and then have the remote server pull down the changes.

Here's what I ended up with:

def publish():
    local('pelican -s')
    local('git add .')
    local('git commit -am "Automated publish - {}"'.format(time.strftime('%m/%d/%Y %H:%M')))
    local('git push')
    with cd(dest_path):
        run("git pull origin master")

(dest_path should already be defined in for you, but you'll need to import time.)

I could've made it simpler by rsyncing the output directory, but I knew that I was going to keep a backup of everything on GitHub, and I like the idea of keeping the entire project source on the remote server in case I ever want to SSH in and make changes directly.

Click to read and post comments