2. 10.1
IBM Bluemix
Hands On Workshop
Nguyen Tai Dzung (Dũng)
Cloud Solution Architect + Bluemix Evangelist
IBM Clouds and Ecosystem Development
Email:
dzungnt@vn.ibm.com
ntaidung@gmail.com
Please register:
https://bluemix.net
https://hub.jazz.net
3. IBM Bluemix – Hands On Workshop
Contents
1. Module 1 – IBM Bluemix Overview
2. Module 2 – Tour of IBM Bluemix
3. Module 3 – First Deploy
Exercise – First Deploy Exercises (Bluemix UI, CF CLI and Eclipse)
4. Module 4 – DevOps Services
Exercise – Bluemix integration with DevOps Services
5. Module 5 – Create your application
Exercise – Your first Node.js application
6. Module 6 – Services
Exercise – Adding a service to an application
7. Module 7 – How it works
Exercise – Specifying a buildpack when deploying an application
8. Module 8: Containers
4. IBM Bluemix – Hands On Workshop
Contents
9. MobileFirst on Bluemix
10. Big Data on Bluemix
11. Internet of Things (IoT)
10. IBM Bluemix – Hands On Workshop
So what is Bluemix?
10
Bluemix is an open-standards, cloud-based platform for
building, running, and managing applications.
Build your apps, your way
Use the most prominent
compute technologies to
power your app: Cloud
Foundry, Docker, OpenStack.
Extend apps with services
A catalog of IBM, third party,
and open source services
allow the developer to stitch
an application together
quickly.
Scale more than just
instances
Development, monitoring,
deployment, and logging tools
allow the developer to run
and manage the entire
application.
Layered Security
IBM secures the platform and
infrastructure and provides you
with the tools to secure your
apps.
Deploy and manage hybrid
apps seamlessly
Get a seamless dev and
management experience across
a number of hybrid
implementations options.
Flexible Pricing
Try compute options and
services for free and, when
you’re ready, pay only for what
you use. Pay as you go and
subscription models offer
choice and flexibility.
Coming Summer 2015
13. IBM Bluemix – Hands On Workshop
How does Bluemix work?
Bluemix is underlined by three key open compute technologies: Cloud Foundry, Docker, and
OpenStack.
It extends each of these with a growing number of services, robust DevOps tooling,
integration capabilities, and a seamless developer experience.
13
Flexible Compute Options to Run Apps / Services
Instant Runtimes Containers Virtual Machines
Platform Deployment Options that Meet Your Workload Requirements
Bluemix
Public
Bluemix
Dedicated
Bluemix
Local*
DevOps
Tooling Your Own Hosted Apps / Services
Integration
and API
Mgmt
Powered by IBM SoftLayer In Your Data Center
+ + +
+ +
+ Always focused on what’s next
Catalog of Services that Extend Apps’ Functionality
Web Data Mobile AnalyticsCognitive IoT Security Yours
+
*Bluemix Local coming Summer
14. IBM Bluemix – Hands On Workshop
More openness and choice than ever before
14
Bluemix is anything but locked down. You choose how you build, deploy, and
manage your apps. Bluemix takes care of the rest.
Compute
Choose the level of
infrastructure
abstraction based on
your app’s
architectural needs.
Dev Tooling
From editors to source
code management to
continuous delivery, you
can use Bluemix’
powerful tooling or
easily bring your own.
Location
Deploy apps to Bluemix
Public (in a growing
number of geos), your
own dedicated cloud
Bluemix, or one that runs
within your data center
(Local*).
Services
Pick from a catalog of
IBM, third party, open
source, or your own
services to extend your
apps.
IBM
Third Party
Open Source
Yours
*Bluemix Local coming Summer 2
99. 99
IBM MobileFirst reduces your mobile
back-end effort so that you can focus on creating value
where it matters most – your customers’ experiences
Today, most organizations have no choice but to focus
mobile efforts
“under the surface”
Development
Engagement
Security
Operations
Development
Engagement
Security
Operations
The right mobile technologies enable you to deliver great apps
101. 101
b
The MobileFirst platform provides flexibility for you to consume and
compose the capabilities you need – on premise or in the cloud
Quality Assurance
Application Scanning
On Premise or Private Cloud Modules
Application Scanning
Detect code security vulnerabilities at the time of
development
Quality Assurance
Collect beta test feedback, crashes and analyze
user sentiment
Foundation
Development environment, continuous delivery,
operations, security and integration
As Services in Bluemix
Cloud APIs
Cloudant NoSQL DB, Workflow, Business Analytics,
more
Foundation
Services in IBM Bluemix
102. 102
The MobileFirst Platform is integrated into IBM Bluemix Cloud Services
Mobile
Application
Security
Mobile Quality
Assurance
Embeddable
Reporting
Cloudant
NoSQL DB
Cloud
Integration
Workflow
Business
Rules
Cloud
Storage for
mobile data
management
Security
to prevent
unauthorized
access to data
Integration
Connect with
APIs & Systems
of Record
Workflow
to automate
next actions
Analytics
for reporting
and insight
104. 104
Offline Mobile Cloud Application
Fat Clients with presentation and business logic processed
locally.
Data downloaded from backend when on WIFI /
Occasionally
Advantages: Well Integrated and can be Optimized for
Performance
Availability: even without network connectivity.
Disadvantages: No Portability, Complex Code.
105. 105
All processing done online presentation layer at the client.
Many times assumes constant connectivity with backend
Advantages: Multiplatform, Direct and Instantaneous
Accessibility to better services.
Disadvantages: Excessive latency for real time responsiveness, no
access to device features, sometimes difficult to maintain sessions
for a long time.
Online Mobile Cloud Application
106. 106
WHAT IS MOBILE CLOUD ?
• MC refers to an infrastructure where both the data storage and
data processing happen outside of the mobile device.
• Mobile cloud applications move the computing power and
data storage away from the mobile devices and into powerful
and centralized computing platforms located in clouds, which
are then accessed over the wireless connection based on a thin
native client.
• MOBILE CLOUD = MOBILE COMPUTING + CLOUD
COMPUTING
107. 107
WHY DO WE NEED MOBILE CLOUD?
–Mobile devices face many resource challenges (battery
life, storage, bandwidth etc.)
–Cloud computing offers advantages to users by allowing
them to use infrastructure, platforms and software by
cloud providers at low cost and elastically in an on-
demand fashion.
–Mobile cloud computing provides mobile users with data
storage and processing services in clouds, obviating the
need to have a powerful device configuration (e.g. CPU
speed, memory capacity etc), as all resource-intensive
computing can be performed in the cloud.
109. 109
IBM Mobile Offerings in Data and Push Services
Persistent cloud with ability to Notify on
Events or completion of processing
01010
10101
0101
110101
010001
01
0101
0
000111
000101
01
∆
135. More and more of the world’s activity is being expressed
digitally by billions of interconnected devices…
135
Smarter
cities
Smarter
vehicles
Smarter
home
Smarter
health
Smarter
factories
Smarter
transportatio
n
…providing businesses with the ability to learn more about their
operating environment, and identify and act with the potential to
create new value.
136. DATA
Unlocked from billions of connected devices
CLOUD
Standards based connectivity from anywhere
ENGAGEMENT
New revenue opportunities created from insights
Today 3 technology forces are converging
that are accelerating IoT
137. SilverHook Powerboats – develops app 40%
faster, enhancing racer and fan experience
“It changes the paradigm in a lot of different areas if we can develop this type
of technology at this speed. It gives other projects a benchmark to live up to.”
—Nigel Hook, president of SilverHook Powerboats
Solution components
Software
•IBM® Bluemix™
•IBM Internet of Things Foundation
The transformation: Powerboat racers and fans both needed real-
time insight into what was happening during races. With IBM®
Bluemix™ and IBM Internet of Things Foundation, the SilverHook
Powerboat team developed an application 40% faster, streaming
sensor data to the cloud and using analytics to deliver information
and alerts to racers. Partner company Virtual Eye also used the
data to create a rich 3-D visualization for fans.
Improves
decision-making and safety during the
race by providing critical data to
drivers
Enhances
fan experience of races with real-
time 3D data visualization
40% faster
application development process
MSP03109-USEN-00
Video:- https://www.youtube.com/watch?v=rpsjxnoNc-U
139. Intel® Edison Board
Small, Powerful & Adaptable Hardware
Dual-core Intel® Atom™ processor 500MHz
Integrated Wi-Fi*, Bluetooth® Low-Energy (LE)
• 32-bit Intel® Quark™ microcontroller at 100 MHz
• 1 GB of RAM, 4 GB of Storage
• 40 multiplexed GPIO interfaces with expansion board options for total
project design and flexibility
• Yocto Project* Linux*
Module 2 –The Intel Edison board
140. Expansion options
Module 2 –The Intel Edison board
Partner
Expansion
Boards
Intel
Expansion Boards
Built to Order
Expansion
Boards
141. Intel® Edison
•70 pin connector
•Hirose DF40 Series
•Easy to build your own board
Intel currently offers 2 boards
•Breakout Board
•Arduino* expansion board
Module 2 –The Intel Edison board
Intel extension Boards
142. Intel® Edison
Development
Board with Arduino*
•20 digital input/output pins including
•4 pins as PWM outputs
•6 analog inputs
•1 UART (RX/TX)
•1 I2C input connector
•1 ICSP 6-pin header (SPI)
Module 2 –The Intel Edison board
143. Connect to your Edison
board
what are connectors/cables for ?
Module 2 –The Intel Edison board
Device mode micro USB for :
• 5V power
• Arduino IDE
• Ethernet over USB
• Flash memory
Host / device mode switch
Micro USB for Serial
commands
to Edison via terminal/putty to :
• Flash firmware
• Configure Edison
• IP address
Standard size USB – Host mode for
•Mouse
•Keyboard
•webcam
Barrel (7V-15V) DC power
connector
144. Intel® Edison
Breakout Board
•I/O: array of through-hole solder points
•USB OTG with USB Micro (AB)
•Battery charger
•USB micro (B) [UART]
•DC power supply jack (7 to 15 VDC)
Module 2 –The Intel Edison board
146. Collaborate.
Learn. Share.
Succeed.•Intel® Developer Zone is where developers are tapping
into everything they need to successfully bring their
connected ideas to life.
Software tools and testing equipment —
Code samples and how to guides —
Dev Kits, hardware, sensors and more —
Forums, online events and meet-ups —
Peer review and expert insights —
A global community —
Module 2 –The Intel Edison board
software.intel.com/
iot
148. IBM Internet of Things Foundation Service
Connect
Collect
Manage
Assemble
• Secure Device Registration
• Scalable Device Connectivity
• Device Management new!
• PAYG SaaS pricing
• Sandbox QuickStart service
• Powered by IBM MessageSight technology
Platform
149. IoT Zone on Bluemix an intro to
IoTF
IoT Zone in Bluemix https://bluemix.net/solutions/iot
152. Getting Started with IBM Bluemix
Hands-On Workshop
Module 3: First Deploy Exercises
153. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
2
Table of Contents
Workshop overview..................................................................................................................................... 3
Exercise 3a: Deploy your first application................................................................................................... 3
Exercise 3b: Deploy and then update the application by using the CLI...................................................... 5
Exercise 3c: Working with Eclipse and Bluemix ....................................................................................... 13
154. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
3
Workshop overview
In this workshop, you will:
• Deploy a simple application from the Bluemix web interface.
• Use the cf command line to modify and deploy the application.
• Configure Eclipse so that you can create IBM Bluemix as a runtime in Eclipse
Exercise 3a: Deploy your first application
This exercise will show you how to deploy a simple application from the IBM Bluemix web
interface.
1. In a browser, navigate to one of the following regions:
• https://bluemix.net: This link should take you to your default location.
o https://console.ng.bluemix.net (Region: US South)
o https://console.eu-gb.bluemix.net (Region: United Kingdom)
o https://console.au-syd.bluemix.net (Region: Sydney)
2. Click LOG IN and then enter your login information on the IBM id page and click Sign in.
You should see your dashboard view:
3. Click CATALOG.
155. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
4
4. Select the Node.js Cloudant DB Web Starter from the Boilerplates section.
5. Enter a name for your application as shown above. The host name information is
automatically entered. The host name must be unique on Bluemix, so enter a name with
your company name or initials to make the name unique.
6. Click CREATE.
After a short while your application should be running. You can launch the application by clicking
on the route.
156. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
5
Exercise 3b: Deploy and then update the application by using the
CLI
In this exercise, you use the cf command-line interface (CLI) to work with Bluemix. You use this
tool in a terminal or command window on your workstation.
Use the same sample application that was used in exercise 3a.
1. Click Start Coding and then click Download Starter Code.
2. After the starter package is downloaded, move it to a directory on your workstation where
you want to work, such as the Bluemix directory in your Documents folder.
3. Extract the package by double-clicking or right-clicking and click Extract or Unarchive.
Do not delete the .zip file: you will need it in Exercise 3c.
157. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
6
4. Delete the deployed application so that you can deploy it from the command line. Click
the Overview page for the application, click the gear wheel in the application, and then
click Delete App.
5. Delete the service and the route with the application by selecting the checkbox in the
Services tab and the Routes tab:
6. Click OK to delete the application.
7. Open a command or terminal window and change the directory to the location where you
extracted the downloaded sample application. (The file package.json should be in your
current directory.)
8. Log in to Bluemix by issuing one of the following commands. Use the same region that
you used in the Bluemix web UI:
cf l -a https://api.ng.bluemix.net (Region: US South)
cf l -a https://api.eu-gb.bluemix.net (Region: United Kingdom)
cf l -a https://api.au-syd.bluemix.net (Region: Sydney)
9. Enter the email and password that you used to log in to the Bluemix web UI. If prompted,
select the organization and space that you want to work in.
158. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
7
10.Before you deploy the application, deploy a Cloudant database. View the available
services by running this command:
cf marketplace
11.In the list of services, find the cloudantNoSQLDB service.
12.Create the service by running this command:
cf cs cloudantNoSQLDB Shared BICloudant
• CloudantNoSQLDB is the name of the service from the cf marketplace command.
• Shared is the name of the service plan that you want to use from the cf
marketplace command.
• BICloudant is the name of the service instance that you want to use. Enter your
own name rather than BICloudant. You will use this new name when connecting
(binding) the service to the application.
13.Refresh your web UI to you see the deployed service.
14.Deploy the application.
Push the application to Bluemix by entering the following command. Change the application
name to your unique name:
cf push BI-MyFirstDeploy-3 -c "node app.js" -m 128M --no-manifest --no-start
• BI-myFirstDeploy-3 is the application name and host name.
• -c specifies the command to start the application.
• -m specifies the amount of memory to allocate to each application instance. The
default is 1 GB.
159. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
8
• --no-manifest instructs to CLI tool to ignore the supplied manifest, which will be
explained later.
• --no-start instructs to CLI tool not to automatically start the application.
Don’t want to allow the application to automatically start because it needs a database to run.
You must link the Cloudant database instance to the application before you start the
application.
15.Link the database and application by using the following command. Substitute the
application name and service instance names that you used previously:
cf bs BI-MyFirstDeploy-3 BICloudant
• BI-myFirstDeploy-3 is the application name used when the application is
deployed.
• BICloudant is the service instance name used when the service is deployed.
If you refresh the web UI, you see that the application and service are linked, but the
application is still stopped.
16.Start an application by running the following command. Substitute the name of your
application:
cf start BI-MyFirstDeploy-3
• BI-myFirstDeploy-3 is the application that you want to start.
If you refresh the web UI, you should see the application running. If not, you can start the
application from the Dashboard.
17.Launch the application by clicking on the route in the web UI
160. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
9
18.In a text editor, open the file app.js and modify the name of the file, the file description,
and the value (lines 306, 307 and 310):
• Line 306: Change the docName from 'sample_doc' to 'test_doc'
• Line 307: Change the docDesc from 'A sample Document' to 'A test Document'
• Line 310: Change the value from 'A sample Document' to 'A test Document'
Save the file when you’re finished editing.
When the application starts for the first time, it creates the sample document in the database.
We have just modified the code that creates the sample document in the database. The
document must be deleted from the database before you restart the application to allow the
database to be populated again.
161. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
10
19.In the Bluemix web UI, select the Cloudant Service instance and then start the Cloudant
Dashboard.
20.Launch the Cloudant console.
You should see a single database. Select the database:
162. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
11
21.Edit the database document.
22.Delete the document.
23.Confirm the deletion when prompted.
24.Redeploy the updated application with the push command. This time, you don’t need to
include the --no-start or memory parameter.
cf push BI-MyFirstDeploy-3 -c "node app.js" --no-manifest
25.After the application has restarted, test it to ensure that your changes are now running.
163. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
12
After the application is tested to confirm that the modified code is running, the application can be
deleted to release resources for the next exercise.
26.Delete the application and service and confirm the deletion when prompted by running
the following two commands:
Delete the application:
cf d BI-MyFirstDeploy-3 –r
• BI-myFirstDeploy-3 is the application name to be deleted.
• -r instructs Bluemix to also delete the routes attached to the application.
Delete the service:
cf ds BICloudant
• BICloudant is the name of the service instance to be deleted.
Confirm the deletion of the application and service.
164. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
13
Exercise 3c: Working with Eclipse and Bluemix
This exercise shows you how to work with Eclipse and Bluemix.
1. Launch Eclipse and switch to the JavaScript perspective. You should use a new
workspace, but this is not essential.
2. Configure Eclipse to use Bluemix as a server by opening Eclipse Preferences and
clicking Server > Runtime Environments.
3. Click Add. Then, select IBM Bluemix Runtime and select the Create a new local
server checkbox.
165. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
14
4. Click Next.
5. Select the appropriate URL to match the region that you have been using.
6. Enter your email and password, which are the credentials that you used to log into
Bluemix. Click Validate Account to ensure that all details are valid and then click Next.
7. Select the organization and space that you want to use and then click Finish. Click OK to
close the Preferences page.
If you want to work with multiple spaces in Eclipse, you must create multiple server
configurations.
8. Open the Servers view in Eclipse. If it’s not showing, click Window > Show View >
Servers.
166. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
15
Use the same application that you used in the last session. You should have the archive file
that you downloaded in the last exercise on your workstation. If not, deploy the Node.js
Cloudant Web Starter application from the Bluemix web UI, click View Guide, and then
download the starter application.
9. Import the starter application package to Eclipse by clicking File > Import.
10.In the Import dialog, click General > Existing Projects into Workspace.
11.Click Next. Then, select the downloaded Zip file and click Finish.
167. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
16
The project will be created.
Before JavaScript applications can be deployed to Bluemix by the plug-in, those applications
must be identified as a project suitable for Bluemix deployment by assigning a facet to the
project.
12.Right-click the project in the Project Explorer view and click Properties.
13.Click Project Facets > Convert to faceted form.
168. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
17
14.When you see the facets, select the Node.js Application facet. Click OK to close the
dialog.
15.Delete the manifest.yml file by right-clicking it and clicking Delete.
16.Deploy the application. Right-click IBM Bluemix. If you have multiple definitions in the
Servers view, select the server definition for the space that you want to deploy the
application to.
169. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
18
17.Click Add and Remove.
18.Select the cloudant_boilerplate_nodejs in the Available column and click Add to move
it to the Configured column.
19.Click Finish.
20.In the Deploy dialog, change the application name to something unique. Click Next.
Ensure that the URL contains a string that will be unique and then click Next.
21.On the Services selection window, click the Add a Service ( ) icon to add a service.
170. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
19
22.When the list of available services is shown, select the CloudantNoSQLDB service.
23.Click Finish and Finish again to close the application Deploy dialog.
The application is now being deployed to Bluemix. Eclipse should automatically switch to the
Console view where you see details of the deployment.
171. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
20
24.After the application is running, switch to the Server view and expand the Bluemix
server. You should see the application in the list. Start the application from Eclipse by
right-clicking the application in the Servers view and clicking Open Home Page.
Tip: In Eclipse, you can change the browser that’s used to start applications by clicking
Window > Web Browser and selecting your preferred browser.
25.Remove the sample document from the database to allow the application to create it
when the database launches. In the Bluemix web UI, select the Cloudant Service
instance and then launch the Cloudant Dashboard.
You should see a single database:
26.Select the database and then delete the document. Confirm the deletion.
27.In a text editor, open the file app.js:
172. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
21
28.Modify the name of the file, the file description and value (lines 306, 307, and 310) to
replace sample with test:
29.Save the changes by clicking File > Save.
Notice in the Server view that the state of the Bluemix server has changed to republish,
which means that an application has changed. However, the application has not yet been
published to Bluemix.
30.Select the cloudant_boilerplate_nodejs application in the Server view and right-click
and click Update and Restart.
31.After the application is restarted, test the application to ensure that the change is now
live.
After the project has been tested, the application can be deleted to release resources for
future exercises.
173. Exercise 3: First Deploy Getting Started with IBM Bluemix
Copyright IBM Corporation 2013-2015. All rights reserved.
22
32.Right-click the project in the Explorer view and click Delete to delete the project. Delete
project contents on disk and then click OK.
You are asked whether you want to delete the cloudantNoSQLDB service. Select the
checkbox to delete the service. In the Bluemix web UI, confirm that the application and
server have been deleted.
Important: Deleting a project that is deployed through Eclipse also deletes it from Bluemix.
174. Getting Started with IBM Bluemix
Hands-On Workshop
Module 4: Bluemix DevOps Services
175. Exercise 4: DevOps Services Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
2
Table of Contents
Bluemix Hands-On Workshop.....................................................Error! Bookmark not defined.
Section 4- DevOps Services ....................................... Error! Bookmark not defined.
Exercise 4.a - Bluemix integration with DevOps Services ...............................................................3
Exercise 4.b – working in DevOps Services....................................................................................5
176. Exercise 4: DevOps Services Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
3
Exercise 4.a - Bluemix integration with DevOps Services
This exercise looks at how Bluemix and DevOps Services work together
Log into Bluemix http://bluemix.net, https://console.eu-gb.bluemix.net or
https://console/au-syd.bluemix.net and deploy the Node.js Cloudant DB Web Starter
boilerplate from the Catalog.
Once the application is running, select the Overview page then select ‘ADD GIT’ on the
Application Overview page
if prompted, add your DevOps Service details and select ‘Sign In’. Ensure you leave the
option to populate the repository selected then select ‘CONTINUE’
In the overview page you will now see the option to ‘EDIT CODE’
select ‘EDIT CODE’ – you should be taken into DevOps Services with the sample
application code imported and ready to work with.
Select ‘BUILD & DEPLOY’. The project has automatically been set up to deploy code
changes to Bluemix when they are pushed to the Git repository.
You can now modify the code and deploy to Bluemix from DevOps Services. To test this,
select the 'run stage'icon in the Build Stage section of the pipeline. You will see the
Build 'Queued', then 'Running' and finally 'Succeeded'. Once the build has complete a
deploy operation should be queued, then run. You should see the deployment running
then Success – to launch the application you can click on the route:
177. Exercise 4: DevOps Services Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
4
You can view logs and history for the build and deploy by clicking the links in the Build and
Deploy stages.
178. Exercise 4: DevOps Services Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
5
Exercise 4.b – working in DevOps Services
In DevOps Services switch to the ‘EDIT CODE’ section so we can edit the code.
Open the views/index.html file and scroll to line 16 to find the string that are displayed on
the welcome page of the app :
Change the line from 'Get Started' to 'Start now'
save the changes by selecting 'File' from the menu, then 'Save'
179. Exercise 4: DevOps Services Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
6
To get the changes pushed to Bluemix we need to commit the changes to the Git
repository.
To work with the Git repository switch into the Git section
The files that have local changes are shown in the Changed Files section (Note, when a
project is first added to DevOps Services some configuration files are updated
automatically - the first 2 files in the list)
Select the html file you just modified, add a commit message and then press ‘COMMIT’
The commit was made to the local branch – the builder works from the remote branch, so
we need to push out changes back to the remote. In the left hand column, expand the
‘PUSH’ dropdown and select ‘Push All’
180. Exercise 4: DevOps Services Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
7
If you quickly jump to the BUILD & DEPLOY screen you will see a build has automatically
been started, which will then be automatically deployed to Bluemix if successful.
Once the deploy has completed test the application to verify the code changes are now
running. You can launch the application by clicking on the link in the deploy stage:
181. Exercise 4: DevOps Services Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
8
Note: if a build fails you can click on the build in the builder and it will take you to a detailed
screen of build history, where you can get access to the logs, files and details of changes
included in the builds. This can help determine why the build failed.
182. Getting Started with IBM Bluemix
Hands-On Workshop
Module 5: Maximizing the Value of Bluemix
183. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
2
Table of Contents
Workshop overview..................................................................................................................................... 3
Exercise 5a: Creating the project source code repository .......................................................................... 4
Exercise 5b: Setting up development tooling............................................................................................ 16
Exercise 5c: Test-driven development...................................................................................................... 23
Implement the divisibleBy function .................................................................................................... 23
Implement the convertToFizzBuzz function....................................................................................... 28
Implement convertRangeToFizzBuzz (introduces Sinon.JS) ............................................................ 31
Exercise 5d: Adding the REST API and deploying to Bluemix ................................................................. 34
Configure a DevOps pipeline to automatically test and deploy code................................................. 37
184. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
3
Workshop overview
This workshop will demonstrate an approach for developing applications by using principles
from agile development and using DevOps processes and tooling.
You’ll develop a REST API that will calculate the FizzBuzz result for a given range.
FizzBuzz is a children's numeracy game where any number divisible by 3 is replaced by the
word Fizz, any number divisible by 5 is replaced with the word Buzz, and any number divisible
by both 3 and 5 is replaced with the word FizzBuzz.
For example, for the range 1 .. 20, the response is:
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14,
FizzBuzz, 16, 17, Fizz, 19, Buzz
You will use Node.js as the runtime and use test-driven development practices to create the
solution.
185. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
4
Exercise 5a: Creating the project source code repository
Before you write any code, you must have the correct tooling and a source code repository. For
this exercise, you’ll use the Git service from IBM DevOps Services for Bluemix.
1. Log in to DevOps Services for Bluemix: http://hub.jazz.net.
2. From your MyProjects page, click CREATE PROJECT.
3. Create a Git repository on Bluemix:
a. Enter a project name.
b. Create a new repository.
c. Create a Git repo on Bluemix.
186. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
5
4. Select to initialize the repository
5.
If you want to share your project and make it searchable to the public, do not select the
Private Project checkbox.
6. If you want to use the Track and Plan tool to support agile methodology, add features for
Scrum development.
7. Select the checkbox to make the project a Bluemix project. Then, provide the details of
the Bluemix space that the application will be deployed to.
187. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
6
8. Click CREATE to create the project.
The code repository has been created, and you can create a new Eclipse project that is
based on the repository.
9. In DevOps Services console, select the Git URL link and copy the URL. Use Ctrl+C or
Cmd C.
10.Start Eclipse and then from the main menu, click File > Import.
11.From the Select dialog, click Git > Project from Git and then click Next.
188. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
7
12.In the Git dialog, select Clone URI and then click Next.
13.In the next dialog, paste the Git repository URL into the URI Location field. This will
automatically populate the Host and Repository path.
14.Enter your DevOps services user name and password. Optionally, select to store the Git
credentials in a secure store in Eclipse. You will need to provide additional information to
initialize the secure store if this is the first time that you store credentials.
15.Click Next.
189. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
8
Eclipse will query the Git repository and list the next branch that’s available. Because you
just created the repository, only the master branch exists.
16.Leave the master branch selected and click Next.
The local destination is then chosen. The default location is <user home
directory>/git/<project name>. Use suggested default location. If you want to
change it, you must remember the location because you will need it later in the exercise.
17.Click Next.
190. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
9
18.Select the wizard to import as a general project and then click Next.
19.In the Import Projects dialog, enter an Eclipse project name. Use the same name as the
DevOps service project name, but you can change if needed.
20.Click Finish.
191. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
10
You now have an Eclipse project linked to your DevOps services Git repository. To
complete the project setup, configure Eclipse to support JavaScript development.
21.Switch Eclipse to the JavaScript perspective:
a. Click Add Perspective at the top right of the Eclipse window.
b. Select JavaScript from the list.
22.Enable the NodeJS facet on the project:
a. Right-click the project name and click Properties.
b. In the Project Facet dialog, click Project Facets and then click Convert to
faceted form.
192. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
11
c. When you see the list of facets, click Node.js Application. Click OK.
Adding the facet automatically creates a sample application in the project.
d. Remove the app.js and package.json files. Right-click each file, click Delete,
and confirm the deletion.
The project shows that there are changes to the local copy of the project. These are the
Eclipse project setting files. Don't save these as part of the source code.
23.Add a navigator view to see all the files in the project:
a. Click Window > Show View and then click Navigator.
193. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
12
b. Right-click the project name in the Navigator view and click New > File.
c. Name the file .gitignore and then click Finish.
d. Add the following two lines to the .gitignore file:
Windows: Leave the slash as specified; do not change it to .settings:
.project
.settings/
The project still shows that there are changes. This occurs because the .gitignore file
is a new file that is not committed and pushed to the master branch on the Git server.
194. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
13
24.Commit and push the .gitignore file:
a. Right-click the project name and click Team > Commit.
b. In the Commit Changes dialog, enter a commit message and select the
.gitignore file. Then, click Commit and Push.
c. Close the confirmation dialog by clicking OK.
The project will no longer show that there are outstanding changes.
Finally, you should add a new window to access the command line. However, this is not
necessary. Instead, you can use a command window outside Eclipse, but it’s more
convenient to have everything in Eclipse because it provides a better working
environment.
195. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
14
25.Create a terminals view:
a. From the main menu, click Window > Show View and then click Other.
b. In the dialog, click Terminals > Terminals and then click OK.
c. In the Terminals window, drag the tab to split the bottom section of the screen to
allow concurrent viewing of the terminal and the problem views.
If a command prompt isn’t shown, click the Open Terminal icon to start a new
terminal. Use the default setting. On some platforms, this happens automatically.
Drag and release
when window
outlines show 2
windows
196. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
15
197. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
16
Exercise 5b: Setting up development tooling
Using appropriate developer tooling with features to automatically check for errors, provide code
assist, and so on can make you more productive and help identify possible problems.
You’ll use the new project that you created in the previous section.
The first step is to ensure the JavaScript tooling is enabled and the test framework is created.
1. Create the JavaScript project:
a. In the Terminals view, change to the directory that contains the project:
• Mac & Linux default: cd <user home>/git/<project name>
• Windows default: cd <user home>git<project name>
If you want to verify where your project is located, right-click the project name in the
Project Explorer view and then click Properties.
Note the project location on the Resources tab:
198. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
17
b. In the Terminals window, run the npm init command and answer the prompts:
• Name - provide a unique name for your project
• Version - 0.0.0
• Description - REST API to calculate FizzBuzz value for a given range
• Entry point - server.js
• Test command - node_modules/.bin/mocha
• Git repository - hit enter to accept the default value
• Keywords - can leave blank
• Author - enter your name
• License - hit enter to accept the default value
Windows: Use the forward slash (/) when specifying the test command.
If the Terminals window is too small, double-click the tab to enlarge it to a full screen.
Double-clicking again will return it to its original size and location.
199. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
18
c. To move the created files into Eclipse, right-click the project name in the Project
Explorer view and click Refresh or press F5.
d. If the wizard truncated the test script to mocha, open the package.json file in the
Eclipse editor and change it back to node_modules/.bin/mocha.
e. Tests are expected to be in a directory named test, so create a test directory:
i. Right-click the project name in the Project Explorer view and click New > Folder.
ii. Name the folder test and then click Finish.
f. To be able to run tests, install the Mocha framework:
200. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
19
i. In the Terminals view, enter npm install mocha --save-dev
ii. Select the project name in the Project Explorer and click Refresh the project in
Eclipse to display the new files.
g. Test that everything works as expected by running a test:
i. In the Terminals view, enter npm test
Note that the test framework ran even though there are no tests defined.
JSHint is a lint program for JavaScript. It provides static analysis of code. It’s a good
practice to have this running in your tooling. Many development teams also include it as
part of their automated test suite.
h. Run JSHint from Mocha:
i. In the Terminals view, enter the following command:
npm install mocha-jshint --save-dev
ii. Select the test directory of the project in the Project Explorer view and then right-
click and click New > File. Name the file jshint.test.js.
iii. In the file, enter the following content and then save the file by clicking File >
Save or use these commands:
Windows and Linux: Ctrl+S
201. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
20
Mac: Cmd+S:
require('mocha-jshint')();
iv. Rerun the tests by entering the following command in the Terminals view:
npm test
There are many errors from the imported modules in the node_modules directory. You
do not control this is code, so it should be excluded from tests.
i. Configure JSHint to ignore the files by using a .jshintignore file:
i. Create a .jshintignore file by right-clicking the project name in the Project
Explorer view and clicking New > File.
ii. Add the following content to the file:
node_modules
test
iii. In the Terminals view, rerun the tests: npm test
JSHint is now enabled in the test suite, but ideally the code editor should provide
feedback from the problems.
JSHint is included in Eclipse, but you must configure it.
j. Enable JSHint in Eclipse:
i. Right-click the project name in the Project Explorer view and click Properties.
ii. In the dialog, click JSHint.
202. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
21
iii. Click Add next to the Enable JSHint for these files and folders box.
iv. Accept the defaults as shown above and click OK.
v. Click Add next to the But exclude these files and folders from validation box.
vi. Click All files and then select in folder and add the node_modules folder. Select
the include all subfolders checkbox.
vii. Repeat the previous step to exclude the content of the test folder.
viii. Click OK to make the changes and close the dialog.
203. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
22
The project is now ready to implement the REST API, so now is a good time to commit
changes to the Git repository (repo).
There is some debate about whether dependencies should be checked in or re-fetched at
build time. To reduce the amount of traffic that you need to push to the Git repo for this
exercise, you will exclude the dependencies in node_modules.
k. Update the Git configuration and then commit and push changes to the Git repo:
I. Switch to the Navigator view to see files that start with a period ( . )
II. Double-click the .gitignore file to edit it and add the node_modules directory
to the file. Then, save the file: Ctrl+S or Cmd+S.
III. Right-click the project name and click Team > Commit. Click the link at the bottom
right of the dialog to open the Git Staging view.
IV. Drag the 4 files from the Unstaged Changes window to the Staged Changes
window. Then, enter a commit message.
V. Click Commit and Push.
VI. Verify that the commit completed successfully and then close the confirmation
dialog.
204. Exercise 5: Maximizing the Value of Bluemix Getting Started with IBM Bluemix
Copyright IBM Corporation 2015. All rights reserved.
23
Exercise 5c: Test-driven development
Implement the divisibleBy function
To implement the divisibleBy funtion, you generate the first test that the implementation must
pass. Solving the problem requires a function to discover whether one number is divisible by
another number, so the first test will check whether 3 is divisible by 3.
Before you write the test, you’ll add another test framework: Chai. Chai is a behavior-driven
development (BDD) and test-driven development (TDD) assertion library for Node.js and a
browser that can be paired with any JavaScript testing framework. Chai provides the test
capability to say "I expect this to be true" or "this should be true."
Before you write a test, install Chai and then configure Mocha to use Chai:
1. Install and configure Chai:
a. In the Terminals view, enter the following command:
npm install chai --save-dev
b. Select the project name in Project Explorer and press F5 to refresh the Eclipse
project content.
c. Create a new file in the test folder named support.js and add the following
content:
var chai = require("chai");
global.expect = chai.expect;
d. Create a new file in the test folder named mocha.opts and add the following
content:
--require test/support
e. Save both files.
The files configure Mocha to use the expect functionality from Chai.
2. Create the first test:
a. Create a new file in the test folder named fizzbuzz.test.js by right-clicking
the test folder in the Project Explorer view and then click New > File.