Inside Out

Notes on seeking wisdom and crafting software

DIY - Ghost (from git) on Openshift

The easiest way to get started in less than an hour with your own ghost deployment is ghost quickstart for openshift. It’s a great reference, if you’re stuck along the way.

Why cook your own? Curiousity and an attempt to try the bleeding edge bits (every minor release of Ghost :P). Let's try to setup hosted ghost linked to the [Ghost Stable git branch](

*As I finished writing this post, I came cross a [nice post]( on the same topic by [Matthew Schultz]( Wish I had came across it while during my experimentation. I highly recommend his post to get started.*

I will leave these raw notes for my future reference :)

Setting up git remotes {#settingupgitremotes} ----------------------

Sign up for an [openshift account]( if you've not yet! Setup your first app with the [nodejs on openshift getting started]( tutorial.

At this point, we have a git remote setup for us by `rhc`. Idea is pretty simple, every push to the git repo starts a deployment of your app.

We will setup another git remote for this repository and point it to [ghost stable tree]( Then merge the `upstream/stable` branch to our master branch for deployment.

git remote add upstream git fetch upstream git merge upstream/stable

Commit away the changes :)

Build some assets {#buildsomeassets} -----------------

Instructions for these are in the [install from git]( page.

npm install -g grunt-cli npm install grunt init grunt prod npm start

At this point, validate your local installation of ghost is successful by navigating to

`grunt prod` command builds javascript files necessary for running ghost. While openshift automatically builds your nodejs files on a `git push origin master`, it doesn't have a way to build the client side js files. We may commit these files we built locally to our repo.

cd git add core/built git add core/client

Getting ready for npm start {#gettingreadyfornpmstart} ---------------------------

Ensure the `package.json` file follows [guidelines from openshift nodejs environment setup]( blog.

Apply the [503 error fix]( for `npm start` to `package.json` file. See [this]( commit for a diff view.

Set the production environment variables for openshift gear. This will ensure openshift doesn't install devDependencies on the git deploy.

rhc set-env NODE_ENV=PRODUCTION -a myapp rhc set-env NPM_CONFIG_PRODUCTION=true -a myapp

We can [persist]( this environment variable as a `pre_start_nodejs` script. See an example in the openshift-quickstart [here](

Persist the data {#persistthedata} ----------------

Just one last bit of caution that I learnt the hard way: openshift deployment doesn't persist the content and images :(

![Openshift Environment Variables](/content/images/2015/02/20150221-openshift-envvar.jpg)

The trick here is to use `$OPENSHIFT_DATA_DIR` as a content and image store. We can use a `deploy hook`.

cd mkdir .openshift/action_hookswget -O .openshift/action_hooks/deploychmod +x .openshift/action_hooks/deploy

We're all set. Do a final commit and `git push origin master`. Your openshift application should automatically build and deploy!

Tips and tricks {#tipsandtricks} ---------------

Several errors that I came across and some remarks:

- `git push origin master` times out during app build. It happens due to `ssh` time out. Follow the guidelines at - If nodejs application doesn't start, try logging in with ssh and use `tail_all` command to see the log. Mostly this happens if we miss a step above: a) `grunt prod` to build the client files, or b) environment variables are not set - If you see the instructions for admin setup everytime, clearly you missed the persist step above :) - Moving your old data is a snap. Use . I had a ton of tags in wordpress, had to consolidate it manually :( - I did another silly mistake. If you setup my localhost ghost with wordpress and then do a `ghost export` and `import` to online ghost; it is going to override the "owner" user account (I had same login). It's good to remove the user info from `ghost export` and try import. It gets messy, be careful. - If all fails: delete the data in `$OPENSHIFT_DATA_DIR` and ghost is reset.