How to install your own parse-server on OpenShift

UPDATE October 2017: As of today, OpenShift 2 is officially reached its end of life and is shut down rendering this guide irrelevant. I will keep it here for historical purposes.

Please note that this guide was for version 2 of OpenShift cloud platform. parse-server-example supports OpenShift 3 platform out of the box, so there is no need for any external guide.

TL;DR just take me to the instructions

parse-openshift

Few months ago I was consulting a start-up called AbiliSense on their cloud solution. They build this amazing mobile app for people with hearing disabilities. After understanding their service needs we decided to go with Parse BaaS solution, and it was all good until the dramatic Parse Announcement  about the retirement of their services. So there was a bit of frustration.. But then we realized that parse-server

gone open-sourced, so I said: You know what, this is even better! We will still use it as before, but now we will also own it!

Most of the functionality work out of the box, including cloud code. And also push notifications are implemented now as well.

There are guides on how to run it on many different cloud platforms. But not for OpenShift. Installing parse-server on OpenShift is a bit tricky, because of an outdated stock node.js and MongoDB cartridges. Luckily, this guy: icflorescu already created custom  node.js and MongoDB cartridges, that are up to date. So we are going to use these custom cartridges with more recent versions. Some people also have reported running into issues because of an old GCC version, but it seems that now parse-server does not rely on any native modules that require recent GCC version, so there should be no problem here. I tested it personally and it worked like a charm.

So let’s dive in, and see how you can run your self-hosted parse-server on OpenShift:

With Deploy to OpenShift button:

Update: OpenShift deploy button is no longer available

Deploy parse-server to OpenShift

IMPORTANT: after that follow the instructions in step #4 of web console steps to configure you APP_ID and MASTER_KEY

With OpenShift Client Tools(RHC):

First Installing the Client Tools (RHC), if you don’t have it already.

rhc app create parseaio http://cartreflect-claytondev.rhcloud.com/github/icflorescu/openshift-cartridge-nodejs http://cartreflect-claytondev.rhcloud.com/github/icflorescu/openshift-cartridge-mongodb --from-code https://github.com/antt001/parse-server-example --env APP_ID=myAppId MASTER_KEY=myMasterKey

Using a web console

  1. Go to Choose a type of application in your OpenShift Online account, paste this URL: http://cartreflect-claytondev.rhcloud.com/github/icflorescu/openshift-cartridge-nodejs into ‘Code Anything’ textbox at the bottom of the page and click ‘Next’.

  2. Set your public URL, paste a modified for OpenShift parse-server git repo URL: https://github.com/antt001/parse-server-example into ‘Source Code’ textbox and click ‘Create Application’.

  3. Add custom MongoDB cartridge to your new OpenShift application, go to ‘See the list of cartridges you can add’, paste this URL: http://cartreflect-claytondev.rhcloud.com/github/icflorescu/openshift-cartridge-mongodb into ‘Install your own cartridge’ textbox at the bottom of the page and click ‘Next’.

    1. If you use rhc, run the following command to set up you Parse APP_ID and MASTER_KEY rhc env set APP_ID=myAppId MASTER_KEY=myMasterKey -a myAppName replace myAppId and myMasterKey with your actual app id and master key

    2. If you don’t - then clone your OpenShift application repository with git using ‘Source Code’ link from the application details in web console, and modify ‘appId’ and ‘masterKey’ values in index.js file

    var api = new ParseServer({
      databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
      cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
      appId: process.env.APP_ID || 'myAppId',
      masterKey: process.env.MASTER_KEY || 'myMasterKey' //Add your master key here. Keep it secret!
    });
    

    replace myAppId and myMasterKey with your actual app id and master key, commit and push you changes to remote.

  4. Live long and prosper, and enjoy you own parse-server on OpenShift.

Update 1:

This is an all-in-one solution, where you have your node.js server and MongoDB running on the same machine. This is good for development, testing or small-scale production(one small gear can handle around 60 requests per second, which is twice as much as Parse.com free tier). This is not a scalable solution. If you want a solution for a large scale production you will need to run a MongoDB cluster(don’t do it, unless you are an expert in MongoDB clusters) or use external services like mLab to do it for you.

comments powered by Disqus