Deploy Deepstream.io to Cloud Foundry

Introduction

Deepstream.io is an open source system to synchronize data and events across multiple client applications in real time.

Using deepstream.io you can build modern web applications where users immediately see changes done by other users without reloading the page.

Cloud Foundry is an open source PaaS that helps you to deploy and scale web application with few commands.

This tutorial shows how to deploy deepstream.io to Cloud Foundry within a few simple steps.

Prerequisites

To follow this tutorial you need access to a Cloud Foundry installation.

There are some public provider out there which provide a trial account, e.g.: Bluemix, anynines, Predix, and Pivotal.

If you have a little patience you can also setup your own Cloud Foundry installation.

Once you have a Cloud Foundry account, you must install the Cloud Foundry CLI, target the Cloud Foundry installation and provide your credentials. In this example a Bluemix account is used:

$ cf api https://api.eu-gb.bluemix.net
$ cf login

Email>

Step 1: Checkout Deepstream.io

To get deepstream running with the existing node.js buildpack we created a node.js wrapper project for deepstream. It does nothing else then importing the deepstream sources and starting a listen socket on the port specified in the "PORT" environment variable.

You need to clone this project using git and then change into the projects directory:

$ git clone https://github.com/wolfoo2931/deepstream-for-cf.git
$ cd deepstream-for-cf

Step 2: Deploy Deepstream.io

To deploy deepstream.io to Cloud Foundry you just have to run the following command within the git repo:

$ cf push deepstream -m 256M --random-route

Attention: Note that this example doesn't configure any authentication. This means that everyone who knows the URL of your deepstream server can write data to it. For production purposes you must setup either a file based authentication or a HTTP Authentication.

This takes a few minutes and will result in the following output:

$ cf push deepstream -m 256M --random-route
Creating app deepstream in org info@specify.io / space dev as info@specify.io...
OK

Creating route deepstream-marine-hardwall.eu-gb.mybluemix.net...
OK

Binding deepstream-marine-hardwall.eu-gb.mybluemix.net to deepstream...
OK

Uploading deepstream...
Uploading app files from: /private/tmp/deepstream-for-cf
Uploading 1.4K, 2 files
Done uploading
OK

Starting app deepstream in org info@specify.io / space dev as info@specify.io...
-----> Downloaded app package (4.0K)

-----> IBM SDK for Node.js Buildpack v3.8-20161006-1211
       Based on Cloud Foundry Node.js Buildpack v1.5.20
-----> Creating runtime environment
       NPM_CONFIG_LOGLEVEL=error
       NPM_CONFIG_PRODUCTION=true
       NODE_ENV=production
       NODE_MODULES_CACHE=true
-----> Installing binaries
       engines.node (package.json): unspecified
       engines.npm (package.json): unspecified (use default)
       Resolving node version (latest stable) via 'node-version-resolver'
       Installing IBM SDK for Node.js (4.6.0) from cache
       Using default npm version: 2.15.9
-----> Restoring cache
       Skipping cache restore (new runtime signature)
-----> Building dependencies
       Installing node modules (package.json)
       > uws@0.9.0 install /tmp/staged/app/node_modules/deepstream.io/node_modules/uws
       > node-gyp rebuild > build_log.txt 2>&1 || exit 0
       deepstream.io-client-js@1.1.1 node_modules/deepstream.io-client-js
       ├── component-emitter@1.1.2
       └── engine.io-client@1.7.2 (yeast@0.1.2, indexof@0.0.1, has-cors@1.1.0,
component-inherit@0.0.3, xmlhttprequest-ssl@1.5.1, debug@2.2.0, parseqs@0.0.2, ws@1.1.1, parseuri@0.0.4, parsejson@0.0.1,
engine.io-parser@1.3.1)
       deepstream.io@1.1.1 node_modules/deepstream.io
       ├── adm-zip@0.4.7
       ├── colors@1.1.2
       ├── commander@2.9.0 (graceful-readlink@1.0.1)
       ├── mkdirp@0.5.1 (minimist@0.0.8)
       ├── engine.io@1.6.11 (base64id@0.1.0, debug@2.2.0, ws@1.1.0, engine.io-parser@1.2.4,
accepts@1.1.4)
       ├── needle@1.3.0 (debug@2.3.2, iconv-lite@0.4.13)
       ├── js-yaml@3.6.1 (esprima@2.7.3, argparse@1.0.9)
       ├── glob@7.1.1 (path-is-absolute@1.0.1, inherits@2.0.3, fs.realpath@1.0.0, once@1.4.0,
inflight@1.0.6, minimatch@3.0.3)
       └── uws@0.9.0
-----> Installing App Management
-----> Caching build
       Clearing previous node cache
       Saving 2 cacheDirectories (default):
       - node_modules
       - bower_components (nothing to cache)
-----> Build succeeded!
       ├── deepstream.io@1.1.1
       └── deepstream.io-client-js@1.1.1

-----> Uploading droplet (19M)

1 of 1 instances running

App started


OK

App deepstream was started using this command `./vendor/initial_startup.rb`

Showing health and status for app deepstream in org info@specify.io / space dev as info@specify.io...
OK

requested state: started
instances: 1/1
usage: 256M x 1 instances
urls: deepstream-marine-hardwall.eu-gb.mybluemix.net
last uploaded: Fri Nov 11 22:18:23 UTC 2016
stack: unknown
buildpack: SDK for Node.js(TM) (ibm-node.js-4.6.0, buildpack-v3.8-20161006-1211)

in the output above you find the URL which Cloud Foundry has assigned to you deepstream deployment. In the example it is "deepstream-marine-hardwall.eu-gb.mybluemix.net".

Step 2: Create a simple Client

Your deepstream server is up and running and you can connect some clients to it. Refer to the offical documentation to write a hello world client application.