copyright | lastupdated | ||
---|---|---|---|
|
2017-10-27 |
{:shortdesc: .shortdesc} {:new_window: target="_blank"} {:codeblock: .codeblock} {:screen: .screen} {:tip: .tip} {:pre: .pre}
This tutorial walks you through creating, securing, and deploying a web application across multiple regions by using a continuous delivery pipeline. Among many other starter applications in IBM Cloud, you use a Node.js starter application for this tutorial.
- Create a starter Node.js application.
- Set up source control and continuous delivery.
- Deploy to another region.
- Map a custom domain to your application.
- Bind an SSL certificate to your application.
- Monitor application performance.
This tutorial uses the following products:
- SDK for Node.js Cloud Foundry App
- Continuous Delivery Service for DevOps

This tutorial involves an active/passive scenario where two copies of the application are deployed in two different regions but only one copy is serving client requests. The DNS configuration initially points to the first region. If the first region fails, the DNS configuration should be updated to point to the other region.
Some DNS providers may include capabilities to detect this situation and automatically route traffic to the other region. Another option would be to deploy a global load balancer in front of the applications and have the load balancer spread the traffic. This tutorial does not explore these options.
{: #create}
Start by creating a Node.js starter application that runs in a Cloud Foundry environment.
- Click Catalog from the menu bar in the IBM Cloud console.
- Click Cloud Foundry Apps under Platform on the left pane and select SDK for Node.js .
- Enter a unique name for your application, which will also be your host name, for example: myusername-nodeapp. And click Create.
- After the application starts, click the Visit URL link on the Overview page to see your application LIVE on a new tab.
Great start! You have your very own Node.js starter application running in IBM Cloud.
Next, let's push the source code of your application to a repository and deploy your changes automatically.
{: #devops}
In this step, you set up a git source control repository to store your code and then create a pipeline, which deploys any code changes automatically.
-
On the left pane of your application you just created, select Overview and scroll to find Continuous delivery. Click Enable.
-
Keep the default options and click Create. You should now have a default toolchain created.
-
Select the Git tile under Code. You're then directed to your git repository page.
-
If you haven't set up SSH keys yet, you should see a notification bar at the top with instructions. Follow the steps by opening the add an SSH key link in a new tab or if you want to use HTTPS instead of SSH, follow the steps by clicking create a personal access token. Remember to save the key or token for future reference.
-
Select SSH or HTTPS and copy the git URL. Clone the source to your local machine.
git clone <your_repo_url> cd <name_of_your_app>
Note: If you're prompted for a user name, provide your git user name. For the password, use an existing SSH key or personal access token or the one created you created in the previous step.
-
Open the cloned repository in an IDE of your choice and navigate to
public/index.html
. Now, let's update the code. Try changing "Hello World" to something else. -
Run the application locally by running the commands one after another
npm install
,npm build
,npm start
and visitlocalhost:<port_number>
in your browser. <port_number> as displayed on the console. -
Push the change to your repository with three simple steps: Add, commit, and push.
git add public/index.html git commit -m "my first changes" git push origin master
-
Go to the toolchain you created earlier and click the Delivery Pipeline tile.
-
Wait for the DEPLOY stage to complete.
-
Click the application url under Last Execution result to view your changes live.
Continue making further changes to your application and periodically commit your changes to your git repository. If you don't see your application updating, check the logs of the DEPLOY and BUILD stages of your pipeline.
{: #deploy_another_region}
Next, we will deploy the same application to a different IBM Cloud region. We can use the same toolchain but will add another DEPLOY stage to handle the deployment of the application to another region.
-
Navigate to Application Overview and scroll to find View toolchain.
-
Select Delivery Pipeline from Deliver.
-
Click the Gear icon on the DEPLOY stage and select Clone Stage.
-
Rename stage to "Deploy to UK" and select JOBS.
-
Change Target to United Kingdom. Create a space if you don't have one.
-
Change Deploy script to
cf push "${CF_APP}" -d eu-gb.mybluemix.net
-
Click Save and run the new stage by clicking the Play button.
{: #add_domain}
When deploying a real world application, you will likely want to use your own domain instead of the IBM-provided mybluemix.net domain.
-
Buy a domain from a registrar such as http://godaddy.com.
-
Switch to the US region by clicking your account name from the menu bar in the IBM Cloud console.
-
Navigate to Application Overview > Routes > Manage Domains.
-
Click Add Domain and enter your domain URL.
-
Navigate to Application Overview > Edit Routes > Choose your domain.
{: #map_domain}
Map the custom domain name to the secure endpoint for the IBM Cloud region where your application is running.
- Set up a 'CNAME' record for the custom domain name on your DNS server. The steps for setting up the CNAME record vary depending on your DNS provider. For example, if you are using GoDaddy, you follow the Domains Help
guidance from GoDaddy.
- Set the CNAME record to the US-South endpoint.
secure.us-south.bluemix.net
For more information, see the related documentation.
{: #ssl}
- Obtain a SSL certificate. For example, you can purchase from https://www.godaddy.com/web-security/ssl-certificate or generate a free one at https://letsencrypt.org/.
- Navigate to Application Overview > Routes > Manage Domains.
- Click the SSL Certificate upload button and upload the certificate.
- Access your application with https instead of http.
{: #monitor}
Lets check the health of your multi-region application.
Availability Monitoring runs synthetic tests from locations around the world, around the clock to proactively detect and fix performance issues before users are impacted. If you configured a custom route for your application, change the test definition to access your application through its custom domain.
- Delete the toolchain
- Delete the two Cloud Foundry applications deployed in the two regions
- Delete the DNS configuration