BootConf 2014 and Octopress

· Read in about 3 min · (608 words) ·

Last week, I setup the infrastructure for BootConf 2014 website and its deployment workflow. Essentially the website is based on Octopress with a mix of Git + SSH to ensure we deploy to a staging site first and then to the live site. Its all working nice for us.

Octopress Setup

Here is how I set it up:

On a server machine

On a staging server setup two Git+SSH Repositories or you can use GitHub for this step. Lets assume these repositories are defined in environment variables SITE_OCTOPRESS_REPO and SITE_SOUCE_REPO. We set a few environment variables to shorten the CLI ( read more at Octopress Setup ):

WEBUSER=user@staging.example.com
SITE_OCTOPRESS_REPO=$WEBUSER:/home/user/repos/octopress-bootconf.in.git
SITE_SOURCE_REPO=$WEBUSER:/home/user/repos/octopress-bootconf.in-source.git

Clone Octopress to a folder: octopress-bootconf

$ git clone https://github.com/imathis/octopress octopress-bootconf
$ cd octopress-bootconf/
$ bundle install
$ git remote add myrepo $SITE_OCTOPRESS_REPO
$ git push myrepo master

Now create the site source with default theme:

$ bundle exec rake install # creates a source/ folder with site structure and some files
$ cd source/
$ git init .
$ git add .
$ git add myrepo $SITE_SOUCE_REPO
$ git push myrepo master

You don’t need to commit source/ folder to the octopress repo, because its a separate repository. In this repository you keep track of only the site source. Thereby separating Octopress code from your site’s content and layout.

On a local machine

Install Ruby and related tools: ruby1.9.3, gem, bundler, rake

$ sudo apt-get install ruby1.9.3 ruby-bundler ruby-rake rubygems 
$ git clone $SITE_OCTOPRESS_REPO octopress-bootconf.in
$ git clone $SITE_SOURCE_REPO source-bootconf.in
$ cd octopress-bootconf.in/
$ ln -sf ../octopress-bootconf.in/ source
$ sudo bundle install -V

NOTE: You may also use a Git submodule for keeping Octopress and site source in separate repositories.

Change the base url for the site to /2014/, and read here for more details:

$ bundle exec rake set_root_dir[2014/]

How to add a new post?

New post is created using new_post task. The file is generated in source/_posts/ folder as a markdown file. You can generate it like this:

cd /path/to/octopress-bootconf.in
bundle exec rake "new_post[title of the post]"

Feel free to edit it ( refer to existing posts on formatting ). Once you are done editing, you can check the preview and deploy it.

Same goes for the existing pages in the navigation menu.

Generating the static site and previewing it

NOTE the use of bundle exec prefix in the command bundle exec rake as we are using bundler to resolve dependencies.

Generate site:

$ bundle exec rake generate
## Generating Site with Jekyll
identical source/stylesheets/screen.css 
Configuration from /..../_config.yml
Building site: source -> public/2014
Successfully generated site: source -> public/2014

Preview it:

$ bundle exec rake preview
Starting to watch source with Jekyll and Compass. Starting Rack on port 4000
Configuration from ..../_config.yml
[2014-03-10 13:57:47] INFO  WEBrick 1.3.1
[2014-03-10 13:57:47] INFO  ruby 1.9.3 (2011-10-30) [x86_64-linux]
[2014-03-10 13:57:47] INFO  WEBrick::HTTPServer#start: pid=24422 port=4000
Auto-regenerating enabled: source -> public/2014
[2014-03-10 13:57:47] regeneration: 100 files changed
>>> Change detected at 13:57:47 to: screen.scss
identical public/2014/stylesheets/screen.css 
>>> Compass is polling for changes. Press Ctrl-C to Stop.

Open the URL: http://localhost:4000/2014/

Deployment to staging and live sites

First login into staging site:

ssh $WEBUSER
cd /path/to/octopress-bootconf.in

Copy Rakefile into two files: Rakefile.staging and Rakefile.live, and update the deployment user/server details in the two files.

To deploy to staging site, you need to symlink the Rakefile to staging config:

cd /path/to/octopress-bootconf.in
ln -sf Rakefile.staging Rakefile

To deploy to live site, you need to symlink the Rakefile to live config:

cd /path/to/octopress-bootconf.in
ln -sf Rakefile.live Rakefile

And then switch back to staging site Rakefile.

ALWAYS MAKE SURE which Rakefile you are using.

Deployment is a simple command:

cd /home/jdevday/workspace/octopress-bootconf.in
bundle exec rake generate deploy