Synchro on IBM BlueMix

Last week we talked about how to deploy Synchro Server using Docker. This week we're going to look at deploying Synchro Server on the IBM BlueMix cloud platform. Following the steps below, you can be serving your Synchro native mobile client apps from the IBM BlueMix cloud in about 10 minutes.

We have done public cloud deployments to a number of cloud back-ends, including Azure, Amazon AWS, Joyent, and a few other places, using a variety of Node.js deployment tools/techniques (ranging from things that are Node.js-specific to just using Docker containers). It's generally not too difficult to get a Node.js app running in these kinds of environments, but it does sort of seem like you're fighting it a little. Not so with BlueMix. It does Node.js very nicely.

Let's Do This...

To get Synchro Server running, first start by going to your BlueMix "Catalog" and under "Runtimes", select the "SDK for Node.js" option (by IBM). Follow the prompts to create the service (there is a 30-day free trial that will work fine). When you're done, you will have a running Node.js server and you'll only be about a minute into the process.

Note: BlueMix supports Docker containers, so we could also deploy our Synchro Server app that way. In fact, between all of the offered services, there are a bunch of ways you could choose to deploy Synchro Server (or any Node.js app) on BlueMix. We chose the "SDK for Node.js" option because it seemed the simplest and most Node-aware/Node-friendly of the options.

Next, go to your BlueMix "Dashboard" and select the service you just created. In the menu on the left, choose "Start Coding". This will lead you through the installation of some command line tools, downloading the app you created above, and deploying it back to cloud.

When you have completed the "Start Coding" exercise, in the same directory where you were working with your BlueMix boilerplate Node.js app, do:

$ synchro init
$ synchro install https://github.com/SynchroLabs/SynchroSamples/archive/master.zip samples

This will install Synchro Server and our "Samples" app over the top of the boilerplate app that BlueMix made. If you want to make sure it's installed properly (but trust us, it will be), you can run it and test it locally:

$ node app.js

When you're ready to deploy to BlueMix, you need to add a couple of items to your config.json (the APPS will already be set, you just need to add HOST and PORT):

{
  "HOST": "yourserver.mybluemix.net",
  "PORT": 80,
  "APPS": {
    "samples": {
      "container": "samples"
    }
  }
}

And since this will be a public-facing server, let's secure the edit/debug interface by adding a user:

$ synchro userpass demouser yourpasswordhere

When you're done, you can deploy SynchroServer to BlueMix just like you pushed the boilerplate app:

$ cf push YourProject

That's it! Synchro Server is running and serving mobile apps on BlueMix. If you go to your BlueMix app's URL, you should see:

Synchro API Server

Now you can point the Synchro Explorer (iOS/Android/Win/WinPhone) native app to the endpoint shown, and start running the Synchro native mobile app you deployed to the BlueMix cloud.

What About Production?

For a production deployment, Synchro Server needs a few things:

  • A Redis cache server to manage sessions and app state (across server instances)
  • A storage solution for shared access to your Synchro app code (optional, depending on deployment strategy)
  • A solution for serving static resources from your app (optional, but highly recommended if your app has static resources)

Luckily, BlueMix has pretty nice solutions in each of these areas. The instructions below assume that you do want to use a shared module store and that your apps have static resources.

Create a Redis Service

BlueMix has two Redis solutions. Neither of them is really 100% integrated into BlueMix. Go to the BlueMix "Catalog" and under "Data and Analytics" you will see "Redis Cloud (Third Party)" and "Redis by Compose (IBM)". Redis Cloud can be deployed from the BlueMix UX, but when you go to manage it later, the BlueMix UX will launch an admin page at redislab.io. Redis by Compose, while it is listed as being by "IBM", actually requires registration at compose.io even to deploy it. We chose "Redis Cloud" and it worked well. There is a free level (30Mb) that is sufficient for testing or small workgroup usage with Synchro Server.

Create a Storage

In the BlueMix "Catalog", under "Storage", select "Object Storage". Configure and deploy an Object Storage (the smallest free storage will be more than enough).

In order to do anything useful with storage containers, you are going to need a tool other than the BlueMix storage admin UX (which is extremely limited). The OpenStack Storage Explorer from CloudBerry Lab is a nice (free) Windows GUI. If you go that route, there are instructions for configuring it to work with your BlueMix storage.

Otherwise, you'll be using the "swift" command line tools. A word of warning: swift as used here refers to the storage technology, and has nothing to do with the Swift programming language, which has recently been integrated by BlueMix. For information on installing and using those tools, go to Getting Started with Object Storage and scroll down to the section titled: Using the Swift CLI to access Object Storage. Follow those instructions.

Populate the Storage

Create a container for your app modules. For the Synchro Samples, we would call the container "samples". Populate this container with your Synchro app code (make sure any sub-directories are propagated correctly).

Create a container for your resources, typically named "resources". Move any static resources from your app to this container (anything that would be in your app "resources" directory should go here). You are going to need to make this container public, so that Synchro mobile apps can access the resources. In the CloudBerry GUI, you can just right-click the container and select "Public / Private" and make it public. Then to get the URL for the newly public container, you can right-click and select "Properties".

From the command-line, you can make the container public by doing:

$ swift post -r '.r:*' resources

And you can get the URL for the newly public container by doing:

$ swift stat -v

Configure Synchro Server for Production

The next step is to configure Synchro Server to use these new services. Before starting, it is probably a good idea to review Pluggable Session and Module Stores as well as Server Configuration in our Help Center.

Your final config.json will look like this (with your values substituted, of course):

{
  "HOST": "yourserver.mybluemix.net",
  "PORT": 80,
  "APP_RESOURCE_PREFIX": "url_to_your_resources_container/",
  "SESSIONSTORE_SERVICE": "RedisSessionStore",
  "SESSIONSTORE": {
    "host": "xxxxxx",
    "port": 9999, // Your actual port goes here
    "password": "XXXXXXX"
  },
  "MODULESTORE_SERVICE": "PkgCloudModuleStore",
  "MODULESTORE": {
    "provider": "openstack",
    "keystoneAuthVersion": "v3",
    "authUrl": "xxxxxx",
    "region": "xxxxxx",
    "tenantId": "xxxxxx",
    "username": "xxxxxx",
    "password": "xxxxxx",
    "domainId": "xxxxxx",
    "domainName": "xxxxxx"
  },
  "APPS": {
    "samples": {
      "container": "samples"
    }
  },
  "STUDIO_USERS": {
    "demouser": "$2a$10$QTUmxQDpnJSlJW4W4uH/wuc/wfIMHGaoLutPt2p39k9p.cKp0R6fK"
  }
}

Deploy and Run

To test locally using the production services configured above, just set the HOST and PORT to something that will work in your local environment and run Synchro Server:

$ node app.js

Assuming everything is working, you're ready to deploy your production configuration to BlueMix. Set the HOST and PORT back to the BlueMix values and deploy as before:

cf push YourProject  

That's it. You should be up and running a production environment on BlueMix. You can now starting looking at other BlueMix services to support your production deployment (load-balancing, CDNs, etc, etc) as needed.