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.
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
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 firstname.lastname@example.org / space dev as email@example.com...
Creating route deepstream-marine-hardwall.eu-gb.mybluemix.net...
Binding deepstream-marine-hardwall.eu-gb.mybluemix.net to deepstream...
Uploading app files from: /private/tmp/deepstream-for-cf
Uploading 1.4K, 2 files
Starting app deepstream in org firstname.lastname@example.org / space dev as email@example.com...
-----> 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
-----> 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)
> firstname.lastname@example.org install /tmp/staged/app/node_modules/deepstream.io/node_modules/uws
> node-gyp rebuild > build_log.txt 2>&1 || exit 0
└── email@example.com (firstname.lastname@example.org, email@example.com, firstname.lastname@example.org,
email@example.com, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org, email@example.com,
├── firstname.lastname@example.org (email@example.com)
├── firstname.lastname@example.org (email@example.com)
├── firstname.lastname@example.org (email@example.com, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org,
├── email@example.com (firstname.lastname@example.org, email@example.com)
├── firstname.lastname@example.org (email@example.com, firstname.lastname@example.org)
├── email@example.com (firstname.lastname@example.org, email@example.com, firstname.lastname@example.org, email@example.com,
-----> Installing App Management
-----> Caching build
Clearing previous node cache
Saving 2 cacheDirectories (default):
- bower_components (nothing to cache)
-----> Build succeeded!
-----> Uploading droplet (19M)
1 of 1 instances running
App deepstream was started using this command `./vendor/initial_startup.rb`
Showing health and status for app deepstream in org firstname.lastname@example.org / space dev as email@example.com...
requested state: started
usage: 256M x 1 instances
last uploaded: Fri Nov 11 22:18:23 UTC 2016
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.