After having got an understanding of what is Bluemix from the previous chapter, let us now take the plunge. In this chapter, you will learn a few other important aspects of working with IBM Bluemix. You will be introduced to the Cloud Foundry command-line utility, which is a key component to work your way through the Bluemix platform. You will also learn how to use the command-line utility to deploy a hello world application that you will develop using the example in this chapter. This chapter will further discuss on how you can develop a hello world application using the web IDE on the Bluemix platform and how you can deploy changes to the application in an automated fashion using the DevOps services on Bluemix. Sounds exciting? Yes? Let us get started.
In this chapter, we will be looking at following topics:
Bluemix is a PaaS platform, which is based on open standards. Bluemix at its core is Cloud Foundry, which is an open source community-based project of open standards-based platform as-a-service offering.
To know more about Cloud Foundry, you can go to https://www.cloudfoundry.org/learn/features/ .
Cloud Foundry command line utility (cf cli) is an interface for the user to interact and work with the Cloud Foundry platform, since Bluemix at its heart is Cloud Foundry, the cf cli can be used to work with the Bluemix platform.
You can step through the following procedure to install the cf cli on your workstation or desktop:
cf cli installable is available for Mac OS X, Linux, and Windows operating systems. For updates on versions and support for operating systems, please make sure to check https://github.com/cloudfoundry/cli#downloads .
For example, installing from the .pkg
file on your Mac OS X would show the following window on successful installation:
cf
Last login: Mon Apr 18 12:19:04 on console xXXXX-MacBook-Pro:~ xxxxx$ cf NAME: cf - A command line tool to interact with Cloud Foundry USAGE: cf [global options] command [arguments...] [command options] VERSION: 6.17.0+5d0be0a-2016-04-15 GETTING STARTED: help Show help version Print the version login Log user in logout Log user out passwd Change user password target Set or view the targeted org or space ........... ........... xXXXX-MacBook-Pro:~ xXXXX$
After having installed cf cli, let us now learn how to log in to your Bluemix account using the cf cli. In this chapter, we will use a terminal window to explain how to use cf cli; the cf commands and steps explained are similar even if you were to use cf cli on Windows command prompt or Linux terminal.
Follow the steps given to log in to your Bluemix account:
cf login
https://api.ng.bluemix.net
https://api.eu-gb.bluemix.net
https://api.au-syd.bluemix.net
Since the account you have created in Chapter 1, Saying Hello to IBM Bluemix, is in the Sydney, Australia region, we will provide the API endpoint as https://api.au-syd.bluemix.net
:
You can log in to any region where you have Space created for your organization, by using the API endpoint. It can so happen that using cf login
may default to the API endpoint you have used earlier. To override this option, you can use the following command to log in:
cf login -a https://api.ng.bluemix.net
The following screenshot shows the output of the preceding command:
Here you see that since there is only one space in the organization for the user in the US region, the login command defaults the user to that Space, mydev.
There are a whole lot of operations you can do with cf cli, however we will learn more about using cf cli in our subsequent sections, where we will look at building a hello world application and deploying it on Bluemix.
In our first Hello World example we shall look at how easy it is to get started with a Hello World application using Bluemix. For this we will use the Bluemix dashboard to work with the platform. In the subsequent section we will look at using the same Hello World application and we will learn to use cf cli to deploy the application on Bluemix.
Before you start creating the Hello World application, there are a few aspects of the Bluemix dashboard that need understanding. Log in to your Bluemix account by going to https://console.au-syd.bluemix.net. You will be taken to the dashboard, as shown in the following screenshot:
You will see that from your dashboard you can work with applications and services. Applications are deployable code that can be run on a compute environment on the Bluemix platform. Applications are what you build and deploy.
Services are IBM, third-party or community software that is provided on the Bluemix platform. Users can create service instances and can bind them to the applications they develop and deploy on Bluemix. By doing this, their applications can leverage the functionality of the software offered as services on the Bluemix platform. An example of a service would be a database, which is a bare bones requirement for any modern or legacy applications, that deal with data.
Virtual Servers or VMs, Containers, and OpenWhisk are compute environments that provide options for users where they can deploy their applications. Cloud Foundry is the default compute environment for the Bluemix platform. At the time of writing this book the Sydney region does not have support for Containers and OpenWhisk.
The following screenshot shows the compute environments that we discussed, available in the US region:
Runtimes is the execution environment for your application code. For example, if you are developing a Java Spring-based web application then the execution environment for your application would require a web server or an application server that can run Java code additionally you would also need the execution environment to have the necessary libraries for the Spring framework, so that your application code can execute. This is typically what a runtime would be.
The runtime options available can be seen by clicking on CATALOG option on the Bluemix dashboard. At the time of writing this book the runtimes available are as shown in the following screenshot:
Buildpacks are a mechanism to define runtime environment along with dependencies to Cloud Foundry. Specifying a buildpack when deploying your application will make sure that Cloud Foundry can get the necessary dependencies to build your execution environment. Buildpack is an important mechanism of bringing in support for programming languages and frameworks that are not claimed to be supported out of the box on the Bluemix platform. We will learn more about it, later in this book. Community Buildpacks, shown in the following screenshot, explains how and where to get the Cloud Foundry-compatible buildpacks, so that you can deploy applications written in programming languages or frameworks that are not supported out of the box on the Bluemix platform:
The steps to deploy an application using Community buildpacks would be as follows:
cf
command: cf push {$APP_NAME} -b {$GIT_REPO_URL}
An example command would be :
cf push timeticker -b https://github.com/spiegela/cf-buildpack-erlang
Bluemix is an evolving platform and it is important to note that the screenshots may look different with the updates to Bluemix platform. The preceding screenshots on the runtimes supported are from the classic view of Bluemix console. At the time of writing this book, we have a newer version of the console that is available, which can be used by switching to it. Click the Try the new Bluemix link, to work with the newer Bluemix console:
The runtimes for Cloud Foundry-based applications on Bluemix, as shown in the following screenshot, is the newer version of the console:
Boilerplates are application development patterns, which have been standardized across categories and have been provided as templates for Bluemix user. The use of these boilerplates to create an application expedites the application development by seamlessly creating the necessary service instances and application stub with execution environment. Let us understand this further by looking at one of the boilerplate example from the list of supported boilerplate templates available on Bluemix, which is shown in the following screenshot. This screenshot is from the newer Bluemix console:
Clicking one of the preceding boilerplates, say the Java Cloud Web Starter boilerplate, would bring up the details related to this boilerplate as shown in the following screenshot:
Here you will notice that the boilerplate consists of a runtime for Java applications, which is the IBM Liberty for Java application server; the boilerplate also contains the Cloudant NoSQL DB as a service. Pricing plans are shown separately for the runtime and for the Cloudant service, which you can see by selecting the Cloudant NoSQL DB service. When a user selects this boilerplate to create an application, then the platform creates an execution environment for his web application by provisioning Liberty for Java. Additionally, a service instance of Cloudant NoSQL DB is created in the user space, an application stub in Java is created and deployed in Liberty runtime. The application stub will have minimalistic functions that involves talking to the Cloudant NoSQL DB service instance as well. What this provides is a great starting point for the user to build web applications that uses an application server and a database.
Similarly, you see that there are other boilerplates that allow you to get started with creating applications using different programming languages, frameworks, or services. We will be creating our first Hello World application using one of the boilerplates, and during this exercise you will learn the process of using boilerplates, editing application stub, and deploying and re-deploying application on Bluemix.
You can follow the steps given here to start creating your first application on Bluemix. We will use the boilerplate as our getting started mechanism. We will be using the newer Bluemix console for most of our screenshots in this section:
At the time of writing this book, the URL to directly go to the new Bluemix console in Sydney region is https://new-console.au-syd.bluemix.net/.
During the running of this example, if your free trial account is valid, you do not have to concern yourself with the pricing yet, you will be within the free tier usage for the runtime and service. If you would like to use the application or service beyond the free trial period, then refer to the procedure of converting your trial Bluemix account to a paid account and gain access to services with powerful and feature rich services along with continued use of resources to keep your application live. You can refer to www.bluemix.net/pricing .
Since your application status is Running, you will be able to launch your application by clicking on View App, as shown in the following screenshot:
This will take you to the application URL or Route, which is a public URL for your application, accessible over the Internet. In case of the application you have created, you will be taken to its route, which is http://java-pi-hw-01.mybluemix.net . The application brings up a UI that talks about the Personality Insights service and has a text box that allows your application user to enter any text, which can be analyzed for personality traits, leveraging the cognitive service of Personality Insights that you have used in your application. There is default text that prepopulates this text box. When you launch your application URL, when you hit on Analyze for this text, you will see the results of the personality traits derived from this text, as shown in the following screenshots:
Personality traits after analyzing the default text is shown as follows:
Details on the analysis and visualization is provided as a result, as well:
This application can be used to cognitively understand unstructured text and analyze it to look for personality traits to arrive at a view of personality data as derived from unstructured data related to a given personality. For example, you can search for Wikipedia text on any known personality, for example, in the following screenshots, we have demonstrated the personality traits of Swami Vivekananda as derived by using your application. The data on Swami Vivekananda we have input in the application is sourced from Wikipedia.
The results are as shown in the following screenshot:
Further analytics on the personality data is as shown in the following screenshot:
You have successfully created your first application on Bluemix. Next, we will see how you can work with the source files to make changes to your first application. Though this application is more than just a Hello World application, we can call it a Hello World as this is as good as your starting point on creating and deploying applications on Bluemix.
In this section, we will look at two aspects of application update, one is the update to the application source, and the other is the update to the application deployment on Bluemix.
Follow these steps given to download the source files for your application:
It is important to understand the manifest.yml
file. This is the file where you can specify parameters to instruct cloud foundry at application deployment time. You can define the number of instances, memory for your application, services used, and so on, within the manifest.yml
file. To know more about the manifest file, refer to
https://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html
.
manifest.yml
file, to see the deployable artifact for your application. This is how the manifest file for your application looks:
webApp.war
file.en.txt
file, inside the WebContent/text
folder. We shall edit the contents on this text file to show text from Wikipedia on any other famous personality, for example, Adolf Hitler. Once we edit and save locally the en.txt
file, we need to locally build the application files, for which we will use ant:
Instructions on installing ant on your local machine is beyond the scope of discussion here. You can refer to instructions here http://ant.apache.org/manual/install.html or to similar sites for information on installing ant on your local machine.
cf push java-pi-hw-01
en.txt
file, from the application files:
In this chapter, we learned about installing and using the Cloud Foundry command-line utility to work with Bluemix. Further, we learned about various concepts, such as services, runtimes, boilerplates, and so on, related to the Bluemix platform. We took the first step in application development and deployment by creating a starter or a Hello World application using boilerplate on Bluemix. In this chapter, you also learned how to get the starter code for your Hello World application and how to make changes to it locally, and how to push the updated application to Bluemix; we used cf cli to demonstrate this. In the next chapter, you will learn more ways and techniques to work with Bluemix and your applications. We will see how by learning how to extend existing applications.
18.118.198.81