How to install Ghost.js on IBM Bluemix

Step 1 out of 1: Follow instructions on this blog

Remarks

I found it easier to install Cloud Foundry CLI to install the app and the services. However I wasn't able to install the Cloudant service from CLI. The docs on Bluemix didn't show the CLI syntax for javascript. I don't know if it's a failing on the docs, the service or on my part. I've deployed Cloudant from the Bluemix dashboard instead

The most recent release of Ghost downloadable was 0.8.0 by time of writing, but the version number specified in the package.json file was still 0.6.4

Issues

1. Cannot install mysql service

To install the service you can use:

$ cf create-service mysql 100 my_mysql_server_name

but when I did that it failed with an error.

It turns out, that (to date), you have to use US South data centre. At the time of my attempt, It doesn't work with Sidney data centre, because ClearDB mysql is not available there. I haven't try the United Kingdom data centre. The symptom error thrown by the CLI is Service offering mysql not found

2. Ghost app fails to start

after finally deploying the Node.js app and the two dependant services (Mysql & Cloudant), Ghost still failed to launch.
After summoning the logs with

cf logs myapp --recent

I saw this:

ERR Ghost needs Node version ~0.10.0 || ~0.12.0 you are using version 1.2.0

That surprised me in two ways, I normally use Node 4.* these days and the 1.2.0 installed by Bluemix SDK for Node.js as runtime seems suspiciously old.
But more surprising to me was the hard requirement that the most recent build of Ghost (to date) has on an even older version of Node.

which is the version installed for my app on Bluemix (well it says 3.x), now I'm confused...

Than I stumbled upon this snippet:

The buildpack uses a default Node.js version of 0.12.7. To specify the versions of Node.js and npm an application requires, edit the application’s package.json, as described in “node.js and npm versions” in the nodejs-buildpack repo.

it occured to me that the fact that 1.2.0 appears in the error and as version requirement for iojs couldn't be just a coincidence.

I didn't realised what IO.js was. Now I know... (but wondering why Bluemix picked up on that one rather than Node, given that IO.js has merged into Node a while back, the current build pack for Node.js should have ignore it, shouldn't it?)

So, I've decided to get rid of the engines section all-together.

After deleting and recreating the app (restaging wasn't enough), it eventually worked.

3. Error installing SQLite

in the logs:

2016-06-20T14:56:51.24+0800 [STG/0] OUT npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build`
2016-06-20T14:56:51.24+0800 [STG/0] OUT npm ERR! Exit status 1
2016-06-20T14:56:51.24+0800 [STG/0] OUT npm ERR!
2016-06-20T14:56:51.24+0800 [STG/0] OUT npm ERR! Failed at the [email protected] install script 'node-pre-gyp install --fallback-to-build'.
2016-06-20T14:56:51.24+0800 [STG/0] OUT npm ERR! This is most likely a problem with the sqlite3 package,
2016-06-20T14:56:51.24+0800 [STG/0] OUT npm ERR! not with npm itself.
2016-06-20T14:56:51.24+0800 [STG/0] OUT npm ERR! Tell the author that this fails on your system:
2016-06-20T14:56:51.24+0800 [STG/0] OUT npm ERR! node-pre-gyp install --fallback-to-build
2016-06-20T14:56:51.24+0800 [STG/0] OUT npm ERR! You can get information on how to open an issue for this project with:
2016-06-20T14:56:51.24+0800 [STG/0] OUT npm ERR! npm bugs sqlite3
2016-06-20T14:56:51.24+0800 [STG/0] OUT npm ERR! Or if that isn't available, you can get their info via:
2016-06-20T14:56:51.24+0800 [STG/0] OUT npm ERR!
2016-06-20T14:56:51.24+0800 [STG/0] OUT npm ERR! npm owner ls sqlite3
2016-06-20T14:56:51.24+0800 [STG/0] OUT npm ERR! There is likely additional logging output above.
2016-06-20T14:56:51.78+0800 [STG/0] OUT npm ERR! Please include the following file with any support request:

I replaced in the package.json file,

"sqlite3": "3.0.8",

with the latest version to date:

"sqlite3": "3.1.4",

Then, I did delete the app and pushed it again and it worked. Although I think setting NODEMODULESCACHE to false and restaging the app might have been enough.

7. Issue about js-yaml module missing

Bluemix version of config.js needs js-yaml, so it needs to be re-added to the dependencies list if it has been removed while solving issue #6

"js-yaml": "^3.3.1",

I had same issue with nano and when, then need to be added back to the package.json file:

"nano": "^6.1.4",
...
"when": "^3.7.3",

They are needed to enable support for Cloudant (see section below)

What's next?

The author of the original blog post mentioned at the top of this post, published a follow-up on how to integrate Ghost with Cloudant for storing image away from the ephemeral filesystem and in a way that allows Ghost.js to scale out: