Deploying Octopress on Openshift

Today I am going to lightly touch on how to install Octopress on Openshift. This post assumes you have a common understanding of the command line and its processes.

The Software / Services

  • Octopress is a framework designed for jekyll to produce lightweight blogs.
  • Openshift is an auto-scaling Platform as a Service (PaaS) for applications developed by RedHat.

This how-to is my workflow. It may not work for you and I will not be held accountable if it blows up your site, deletes your internets or kills your kitten.

Requirements

  • A terminal with access to git and ruby 1.9.3.
  • A brain and the ability to think outside the box.

Step 1. Obtain an Openshift account.

At the time of this writing, openshift was free with 3 gears. You simply have to signup at Openshift and complete the registration steps. Once you have your account up and are logged into your Openshift account, do the following.

  1. Click on Add Application
  2. Install a Ruby 1.9 application.
  3. Leave the settings at default and put in your application name and namespace.
  4. Copy down the git repository url that openshift gives you on step 2.

(example) ssh://[email protected]/~/git/app.git/

If needed, upload your public SSH key from the server/PC you are going to be working with if this is your first application, they will prompt you for it.

Step 2. Getting Octopress Ready

Get the Octopress source and set it up.

1
2
3
4
5
6
# start in your home directory or wherever you want to put this for developing.
git clone git://github.com/imathis/octopress.git octopress && cd octopress
sudo gem install bundler # depending on your setup, you may or may not have to use sudo.
rbenv rehash # If you use rbenv, rehash to be able to run the bundle command
bundle install
rake install

At this point you should have a fully operational Octopress setup! That sure was easy. Moving on…

Step 3. Staging a public directory

I do not deploy the entire octopress directory to Openshift. It really is not needed at all and doing it this way takes up less space on your application. At this point you can just push it to your openshift git and it will probably just work. I like making things complicated though.

So we need to make another git repository somewhere outside octopress. Here is what I do.

1
2
3
4
cd .. # we should now be in the level below octopress.
mkdir _deployment && cd _deployment # make a directory outside octopress.
cp ../octopress/config.ru . # copy the config.ru needed into the _deployment
cp ../octopress/Gemfile . # copy the Gemfile into the _deployment

I normally at this point modify my _deployment/Gemfile to remove the –development stuff. All that should remain is the source and sinatra gem. Once you edited your file move on.

1
2
3
4
5
6
7
bundle install # Generate a Gemfile.lock
mkdir public/
git init . # initialize the repo
git remote add openshift ssh://[email protected]/~/git/app.git/
git add .
git commit -am 'initial deploy'
cd ..

You should now see two directories. _deployment and octopress. We need to move that _deployment directory into octopress.

1
mv _deployment octopress # move the git repo into the octopress directory.

At this point your probably asking why we did Step 3 outside the octopress directory. Well when you initialize a git repo inside of another repo it adds it as a submodule. And to be honest, it’s never worked out well for me.

I keep my octopress synced with another repo on the internet and adding the repo as a directory instead of a submodule keeps it all in sync with no fuss. Your milage may vary.

Step 4. Putting it all together

Now we have to add this _deployment directory into our octopress repo. Generate a post and publish this sucker. Lets do this.

1
2
3
4
5
cd octopress
git add _deployment/ # The trailing / is important. If you omit it, bad things will happen.
rake new_post['Hello World'] # Depending on your environment, use bundle exec
Edit and save the file in source/_posts/2013-02-24-Hello-World.markdown # date and file may vary, see the output.
rake generate # Again, you may have to use bundle exec before rake.

Now at this point in time, we have our static blog that we just generated in octopress/public but we need that data into _deployment/public to push it to Openshift. I have a modified Rakefile that does this for me, please modify it before using it and make you make sure you take a backup of your original. Download the Rakefile @ gist.github.com

If you use my Rakefile, you simply have to run rake deploy and it will do everything for you. Your blog should now be live on http://app-domain.rhcloud.com/ go check it out..

….otherwise…..

If you want to do this manually, here is what you need to do. Again starting in the octopress directory.

1
2
rm -rf _deployment/public/* # clean out the directory.
cp -R public/* _deployment/public/ # copy our generated files.

Now we have a copy of our site in the _deployment directory ready for publishing. Lets get it on the internets!

1
2
3
4
cd _deployment
git add .
git commit -am 'New blog post'
git push openshift master

At this point Openshift will start spitting out what it’s doing in the background. Once it is done, you should see something like this.

1
2
3
remote: Done
To ssh://[email protected]/~/git/app.git/
   7137029..432c8ca  master -> master

Congrats! Your blog should now be live on http://application-namespace.rhcloud.com/ so go check it out.

If you get any errors, just remove the files in your _deployment/public/ and start over. I am sure there is an easier way for all of this, but I am used to doing it this way.

See any mistakes, ways this can go better or just want to say hey? Drop me a comment below!

Free Software, Hell Yeah!

Comments

All content © 2013 - http://www.shellco.de - Proudly powered by Octopress

Design: Greyshade