Hosting a static blog on an Object store

There are a ton of CMS systems for personal blogs. Wordpress is probably the most popular one, but there are many others. These systems tend to have an web-facing administrator panel, protected by a password. Creating a blog entry is usually pretty easy, although when you’re a bit picky about the appearance of your post, you’ll end up editing HTML.

While these systems are great for not so tech savvy users, they have one major weakness: both the software and the content need to be on the same server. This means that the software you use is exposed to the entire Internet. Just Google wordpress vulnerability to get a sense of the implications. Moreover, you’ll need a server configured for some script language, usually PHP, which has both cost and performance implications. Lastly, if your blog gets blessed by Slashdot or Reddit, there is often no good way to scale your blog, as there are many dynamic components.

If nice WYSIWYG editing is not among your requirements, you could decide to switch to a static blog system. These systems live in the safety of your own computer, and only store their output on a web server. In the event of a traffic surge, you can just copy your blog to multiple locations, as there are no dynamic components In this example I’ll be looking at pelican, but there are others, such as jeckyl , octopress and middleman. In this example I’ll be using the CloudVPS Object Store, but there are many suitable alternatives.

Setting things up

Make sure CloudVPS OpenStack is configured for your environment. Add the following to your environment (e.g. in your ~/.bashrc).

export OS_PROJECT_ID="01234567890abcdef01234567890abcdef"
export OS_TENANT_ID="01234567890abcdef01234567890abcdef"
export OS_USERNAME="[email protected]"
export OS_PASSWORD="Not.Sh4rIng_+hi$"
export OS_AUTH_URL="http://identity.stack.cloudvps.com/v2.0"
# some systems need this, depending on who shipped the ca certificates
export OS_CACERT=/etc/ssl/certs/ca-certificates.crt

Create a virtualenv for all of the blog software, that way you will not contaminate the rest of your system.

$ virtualenv .venv
$ . .venv/bin/activate

Now it’s time to install the software:

$ pip install pelican python-swiftclient python-keystoneclient

Creating your blog

Once all software is installed, it’s time to actually bootstrap the blog. Pelican comes with a nice quick start tool, pelican-quickstart. It will ask a few questions, and when it’s done, you’re ready to write content. You can skip (say no) to all questions concerning uploads, we’ll be adding our own upload method later on.

$ pelican-quickstart 
Welcome to pelican-quickstart v3.4.0.

This script will help you create a new Pelican-based website.

Please answer the following questions so this script can generate the files
needed by Pelican.

> Where do you want to create your new web site? [.] 
> What will be the title of this web site? My twenty-fifth blog
> Who will be the author of this web site? John Doe
> What will be the default language of this web site? [en] 
> Do you want to specify a URL prefix? e.g., http://example.com   (Y/n) n
> Do you want to enable article pagination? (Y/n) n
> Do you want to generate a Fabfile/Makefile to automate generation and publishing? (Y/n) y
> Do you want an auto-reload & simpleHTTP script to assist with theme and site development? (Y/n) y
> Do you want to upload your website using FTP? (y/N) 
> Do you want to upload your website using SSH? (y/N) 
> Do you want to upload your website using Dropbox? (y/N) 
> Do you want to upload your website using S3? (y/N) 
> Do you want to upload your website using Rackspace Cloud Files? (y/N) 
> Do you want to upload your website using GitHub Pages? (y/N) 
Done. Your new project is available at /home/johndoe/blog25

To enable swift uploads, we’ll have to add a few lines to the makefile, before the .PHONY target.

swift_upload: publish
    export CONTAINER=mycontainer
    swift post "$CONTAINER" --header 'x-container-read: .r:*' -m 'web-index:index.html'
    cd "$(OUTPUTDIR)" && swift -v upload -c "$CONTAINER" .

The first line indicates a new make target, named swift_upload dependent on the publish target. If you’re not familiar with how make works, don’t worry, it’s not important.

The second line configures which container to use, edit it to your liking. Make sure to use only DNS-compatible characters (0-9, a-z and dash), so you can set up a nice CNAME later on.

The third line creates the container, and sets up two pieces of meta data. The X-Container-Read: .r:* makes sure your container is publicly accessible. At CloudVPS object store containers are secure by default, so we’ll need to enable public access. The web-index:index.html sets up some container meta data, so the object store knows what file to host as the index file.

The last line enters the output directory (where your blog was generated) and simply uploads everything.

Generating and uploading your blog is now simply a matter of typing make swift_upload, and you’re done.

Setting up a nice domain name

If you have your own domain name, you can point it to your container, by creating a DNS record like this:

blog IN  CNAME mycontainer.01234567890abcdef01234567890abcdef.objectstore.eu

Replacing mycontainer with the container name you chose earlier, and 01234567890abcdef01234567890abcdef with the project id from your authentication data. When you’ve done this, your blog will be accessible at http://blog.<yourdomain>/, provided you’ve already uploaded it.

Creating content

Content is created by adding some .rst documents in the /content folder. I haven’t yet found a way to automatically generate high quality content, so for now I just create mediocre content manually.

Back To Home