February 8, 2016 | Written by: Twana Daniel
Categorized: Compute Services | How-tos
Share this post:
Bluemix is an implementation of IBM’s Open Cloud Architecture, leveraging Cloud Foundry to enable developers to rapidly build, deploy, and manage applications and services. Although Microsoft Azure, another popular PaaS platform, shares quite a few similarities with Cloud Foundry, several elements still need to be addressed when porting Microsoft Azure applications to IBM Bluemix.
This tutorial will take you step-by-step from creating a Node.js app on Azure and then migrating that app onto IBM Bluemix; it will also give you the key differences between Microsoft Azure and IBM Bluemix from a developer’s point of view. This application is a simple Node.js app and services are not discussed in this first tutorial.
Below is a screenshot of the migrated application:
Source code of this application is in the IBM-Bluemix/Migrate-Node-App project on GitHub.
There are a few things to be aware of when porting a Microsoft Azure application to IBM Bluemix:
- The environment variables for service binding. In Bluemix, all the bound service credentials are stored in an environment variable named
VCAP_SERVICES. However, for Microsoft Azure, the environment variables for service binding can be different depending on the services. To address this gap, the environment variables must be reconfigured so that they can be mapped correctly, and the original Microsoft Azure application needs to be modified before migrating to Bluemix.
- Different sets of services. When porting an application to IBM Bluemix, you need to consider services. IBM Bluemix has a very big catalog of services from both IBM services and open source services. When porting your app to Bluemix, you need to consider the services available to you and configure the service within your app.
- When porting your app to IBM Bluemix I recommend to add a Manifest.yml file where you declare the application setup (this will be covered in the steps below).
- On Bluemix we are using Node version 4.2.6, but you have the flexibility to use the version you want; you just need to specify in the
package.JSON file where Azure’s Node.js version 4.2.3 is used.
Following is a step-by-step process describing how to migrate a sample application from Microsoft Azure to IBM Bluemix. The sample Azure application, named MigrateNodeApp, is a Node.js application; it consumes a JSON Data file as the back-end data to retrieve the app data.
Migration Steps to Bluemix
First you will need to register and download some tools. Specifically you will need:
In order to migrate the app from Azure to Bluemix, you will need to make few small changes to the source code.
Step 1: Verify Node.js engine is specified
package.json file excerpt below:
"auther": "Twana Dnaiel",
"start": "node ./bin/www"
Step 2: Add a manifest.yml file to your root of your application
The manifest.yml contains the application configuration that will be running on Bluemix (see Deploying with Application Manifests for more details). Our example manifest file is as follows:
- path: .
Step 3: Connect to database (optional)
For our sample application, we are loading the data from a JSON file, but if your application is connected to a database and reads and writes to the database, then the environment variables must be reconfigured so that they can be mapped correctly. In Bluemix, all the bound service credentials are stored in an environment variable named
VCAP_SERVICES. However, for Microsoft Azure, the environment variables for service binding can be different depending on the services. If you want to see working sample Node.js code with connection to a database, see Sample Node App with Cloudant.
Step 4: Navigate to the folder directory and push the app to Bluemix
Verify the name of the folder is the same name in which you have it named in your manifest file. For example, the sample web app is called MigrateNodeApp. Then run the following commands to login, navigate to your space on Bluemix, and push your app to Bluemix:
$ cd MigrateNodeApp ### Navigate to the application directory
$ cf login ### Login to Bluemix and navigate to your space
$ cf push MigrateNodeApp ### Push app to Bluemix
You should now be able to access your application in its staging domain xxxxxx.mybluemix.net. In my case, it is located in migratenodeapp.mybluemix.net. In the next post, we will bind a Cloudant database service to load the data instead of loading data from a JSON data file as in this post’s example. In the meantime, if you have any questions or need help, please contact me at @twanawebtech or leave a comment below.