MBaaS on Cloud Foundry: How to Deploy Helios

by Alexander SologubJune 6, 2014
Learn how MBaaS automates development, how to use the PostgreSQL hstore extension for Helios, which preparations are needed to deploy an app, etc.

What MBaaS is?

Mobile-backend-as-a-service frameworks appeared to speed up app development by providing/automating such things as user and data management, billing, etc. Thanks to MBaaS, developers can finally concentrate on implementing the features they envisioned, instead of worrying about infrastructure. Dozens of solutions exist today. Paid ones generally offer more advanced features, but there are also some decent open-source options.

Helios MBaaS is one of them. It is an extensible open-source mobile backend framework that provides essential services. In fact, it is a Ruby Gem that can be used to build an independent Rack application. Helios can also be implemented with Sinatra or Ruby on Rails. Out-of-the-box features include synchronization, push notifications, in-app purchases, logging, analytics, etc. In addition, Helios is one of MBaaS frameworks—along with LoopBack—that can be deployed to PaaS systems, such as Cloud Foundry.

In this tutorial, we will walk you through the steps for deploying Helios with your application to Cloud Foundry.

 

Prerequisites

Helios uses PostgreSQL and its hash store. To operate normally, it needs the XCDATAMODEL file in the XML format (borrowed from the iOS SDK), where the business logic will be described.

To deploy Helios on Cloud Foundry, we will need to install and set up the following:

  • PostgreSQL
  • Helios
  • Cloud Foundry Command Line Interface (CLI)

Before starting, you also need to check your Ruby version by typing the following lines into the terminal.

As you can see, we are using Ruby 1.9.3 (and newer versions should do just fine). We also prefer to use RVM and Gemsets.

Now, let’s begin.

 

Installing PostgreSQL

PostgreSQL is one of Helios’s external dependencies. Helios also uses the PostgreSQL hstore extension, so we are going to install it, as well. Besides that, since we are going to deploy our app to Cloud Foundry, we need to provide a PostgreSQL service. There are a couple of ways to do this. If your existing Cloud Foundry installation already has a PostgreSQL service (or a way to create one), you can just bind it to your app. However, we had no other way but to provide a service of our own.

Let’s start with local setup. The simplest way to do it on Ubuntu 12.04 LTS is with the command below.

In addition, you are going to need a user and a proper database.

If you want to provide the PostgreSQL service from your computer, simply follow the instructions below. Otherwise, you will need to install PostgreSQL on a machine that can be accessed by your app from Cloud Foundry (in our case, it was a machine with a public IP).

Then, you need to proceed with additional steps required for PostgreSQL to receive remote connections. Add the following line to /etc/postgresql/9.1/main/postgresql.conf.

Then, add the line below to /etc/postgresql/9.1/main/pg_hba.conf.

Note, that depending on the operating system, these files might be stored in a different location. In addition, do not forget about firewalls. By default, PostgreSQL uses port 5432.

Restart PostgreSQL for changes to take effect.

 

Installing Helios

Now, let’s install Helios.

To create an application, use the following code.

It will create the ch_helios_app folder in your current directory. You need to edit the cf_helios_app/.env file, so that it looks like shown below.

Now, you can use helios start to launch your app inside the cf_helios_app directory. We recommend that you open http://localhost:5000/admin/ in your browser to make sure it works properly.

 

Installing the Cloud Foundry CLI

Installing the Cloud Foundry console is as simple as it can be.

Now, we need to connect with our Cloud Foundry deployment. The console will ask you to select the organization and space. Just follow the steps below.

We are almost ready to deploy our application to Cloud Foundry.

 

Preparing to deploy an app

As mentioned before, in order to deploy an application, you need to deliver a PostgreSQL service. To create a so-called user-provided service in Cloud Foundry, type the following lines in your terminal.

Then, create the .cfignore file inside the cf_helios_app directory and add the line below.

 

Deploying your app to Cloud Foundry

To deploy your application, follow the directions of the Cloud Foundry console. Inside the cf_helios_app directory, do as listed below.

Now, you can access your Helios app. Note that Cloud Foundry has changed the application port from 5000 to 80.

You might want to consider another MBaaS option, such as LoopBack. In this case, you can check out our blog post on how to deploy it to Cloud Foundry.

 

Further reading


This post was written by Alexander Sologub and edited by Volha Kurylionak.