SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Downloaden Sie, um offline zu lesen
Codemotion Bluemix Lab
Building a Micro-Service System Using IBM
DevOps Services and Bluemix
March 28th
2015
3
Notices and Disclaimers
Copyright © 2015 by International Business Machines Corporation (IBM). No part of this document may be reproduced or transmitted in
any form without written permission from IBM.
U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM.
Information in these presentations (including information relating to products that have not yet been announced by IBM) has been
reviewed for accuracy as of the date of initial publication and could include unintentional technical or typographical errors. IBM shall have
no responsibility to update this information. THIS document is distributed "AS IS" without any warranty, either express or implied. In no
event shall IBM be liable for any damage arising from the use of this information, including but not limited to, loss of data, business
interruption, loss of profit or loss of opportunity. IBM products and services are warranted according to the terms and conditions of the
agreements under which they are provided.
Any statements regarding IBM's future direction, intent or product plans are subject to change or withdrawal without notice.
Performance data contained herein was generally obtained in a controlled, isolated environments. Customer examples are presented as
illustrations of how those customers have used IBM products and the results they may have achieved. Actual performance, cost, savings
or other results in other operating environments may vary.
References in this document to IBM products, programs, or services does not imply that IBM intends to make such products, programs or
services available in all countries in which IBM operates or does business.
Workshops, sessions and associated materials may have been prepared by independent session speakers, and do not necessarily reflect
the views of IBM. All materials and discussions are provided for informational purposes only, and are neither intended to, nor shall
constitute legal or other guidance or advice to any individual participant or their specific situation.
It is the customer’s responsibility to insure its own compliance with legal requirements and to obtain advice of competent legal counsel as
to the identification and interpretation of any relevant laws and regulatory requirements that may affect the customer’s business and any
actions the customer may need to take to comply with such laws. IBM does not provide legal advice or represent or warrant that its
services or products will ensure that the customer is in compliance with any law.
Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other
publicly available sources. IBM has not tested those products in connection with this publication and cannot confirm the accuracy of
performance, compatibility or any other claims related to non-IBM products. Questions on the capabilities of non-IBM products should be
addressed to the suppliers of those products. IBM does not warrant the quality of any third-party products, or the ability of any such third-
party products to interoperate with IBM’s products. IBM expressly disclaims all warranties, expressed or implied, including but not limited
to, the implied warranties of merchantability and fitness for a particular purpose.
The provision of the information contained herein is not intended to, and does not, grant any right or license under any IBM patents,
copyrights, trademarks or other intellectual property right.
• IBM, the IBM logo, ibm.com, Bluemix, Blueworks Live, CICS, Clearcase, DOORS®, Enterprise Document Management
System™, Global Business Services ®, Global Technology Services ®, Information on Demand, ILOG, Maximo®,
MQIntegrator®, MQSeries®, Netcool®, OMEGAMON, OpenPower, PureAnalytics™, PureApplication®, pureCluster™,
PureCoverage®, PureData®, PureExperience®, PureFlex®, pureQuery®, pureScale®, PureSystems®, QRadar®, Rational®,
Rhapsody®, SoDA, SPSS, StoredIQ, Tivoli®, Trusteer®, urban{code}®, Watson, WebSphere®, Worklight®, X-Force® and
System z® Z/OS, are trademarks of International Business Machines Corporation, registered in many jurisdictions worldwide.
Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available
on the Web at "Copyright and trademark information" at: www.ibm.com/legal/copytrade.shtml.
4
Contents
Introduction 5
Preparing Bluemix 5
Setting up the Nginx proxy 6
Forking Nginx proxy project 6
Setting up the delivery pipeline 6
Writing the first NodeJS micro-service 7
Adapting the code 7
Inspecting the structure 8
Setting up the delivery pipeline for Bluemix deployment 8
Hooking up the micro-service to the proxy 8
Enabling Facebook authentication 9
Registering Facebook OAuth client 9
Enabling authentication code 9
Switching to Redis session store 9
Adding another NodeJS micro-service 10
Forking the ‘Page 2’ project 10
Adding the new micro-service path to the proxy 11
5
Introduction
Welcome to the managed Codemotion Rome 2015 lab, where you are going to build a micro-service
system using NodeJS, Nginx, Redis, Facebook OAuth2 and other technologies using solely IBM
DevOps Services for development, and deploy it to IBM Bluemix PaaS. The fact that we only need a
browser for this is amazing and shows the power of both platforms.
Important: There are certain preconditions for participating in the lab:
1. You need to have an IBM ID and a Bluemix account (http://bluemix.net). If not, sign up at
ibm.biz/Bluemix2015 for both.
2. Once you have your IBM ID, you can use it to sign in into IBM DevOps Services
(http://hub.jazz.net). Verify you can do it before starting the work.
3. For the authentication portion of the lab, you need to have a Facebook account (I know,
crazy). You can use it to create a Facebook app and its credentials at
http://developers.facebook.com .
This lab assumes you have basic understanding of JavaScript and NodeJS, as well as Web
development.
The purpose of this lab is to gradually build a small micro-service system using techniques such as
UI composition and federated authentication. We will build it step by step, with success checkpoints
along the way.
Preparing Bluemix
Before we start writing applications and deploying them to Bluemix, we want to make sure we have
an organization and space where we will deploy our apps and services.
1. Log into the Bluemix dashboard
2. Verify that the organization you received as part of your trial account is being selected (top
left)
3. You should have at least one space created (dev). This is the space we will use to deploy all
our apps.
4. Select the ‘US South’ region in the top right drop-down menu and create a new space if
required (dev).
6
Setting up the Nginx proxy
We will proxy all the micro-services so that we have a feel that we are running a single app. We will
use Nginx for this purpose.
Forking Nginx proxy project
Start by forking a project in IBM DevOps Services (IDS in short):
1. Log into https://hub.jazz.net/. You should end up in the page called ‘My Stuff’.
2. Switch to ‘Explore’ and enter ‘codemotion-proxy-start’ in the search field. A single project
should appear. Follow the title link to go in.
3. Locate the ‘FORK PROJECT’ button in the upper right section, and press it. A dialog should
appear.
4. Name the project (use something that can also be useful as an app name and first segment
in the URL domain).
5. Leave it public, or make it private to you, deselect ‘features for Scrum development’, and
select ‘Deploy to Bluemix’ checkbox.
6. Chose the Bluemix ‘US South’ region, the org and space you previously set up.
Once the project has been forked, you will be in the project overview page. Click on ‘Edit Code’ to
switch to the Web IDE.
Before setting up the pipeline, make sure all code changes are committed:
1. Switch to the Source Control view in Web IDE (second tab on the left nav bar),
2. If there are changes, add some summary, Select All, Commit, and then Push (on the left side
of the screen). You should get the ‘Fast Forward’ green notification that the push succeeded.
3. Remember these steps – we will need to repeat them every time we change code so that the
code is committed to Git and picked up by the delivery pipeline.
Setting up the delivery pipeline
Observe the file ‘index.html’ – it contains some boilerplate text to show us we have Nginx running.
Now switch to ‘Build & Deploy’ button in the upper right corner of the page.
1. After reading the ‘Welcome’ message, you can close the panel. Click on ‘ADD STAGE’.
7
2. Accept the defaults on the first page of the dialog. Select ‘Jobs’ and ‘Add Job’. Pick ‘Build’
from the list, select ‘Simple’. Also name the stage (e.g. ‘Build’) and Save.
3. Add a new deployment stage by repeating steps (1) and (2), only this time select ‘Deploy’ as
the job type. Name the stage (e.g. ‘Deploy’).
4. Verify that the org and space are correct.
5. Modify the deploy script as follows:
cf push "${CF_APP}" -b https://github.com/cloudfoundry-community/staticfile-buildpack.git
6. Save.
Kick-start the pipeline by pressing the ‘Play’ button at the top of the Build stage. If all goes well, the
build will quickly finish, followed by automatic deployment to the domain <my app
name>.mybluemix.net
Verify the deployment by navigating to http://<my-app-name>.mybluemix.net. You can also switch to
Bluemix and observe the app running in the designated space.
Writing the first NodeJS micro-service
Go to Explore page and search for ‘codemotion-node1-start’ project. When you find it, click on it and
fork it into your own. Again, pick a name that will be useful for both the Bluemix app name and the
URL domain (e.g.: ‘IC2015-<initials>-Home’).
Adapting the code
You need to make changes to the forked project in several places:
1. Click on ‘package.json’ and change the name to reflect your app name it’s not already done.
2. Click on ‘manifest.yml’ and do the same for the app name, and host name (the first segment
of the URL before mybluemix.net).
3. Go into /config/app.json and change all occurrences of <app1-name> to your chosen
route/app name as specified in manifest.yml. Also change all occurrences of <proxy-name>
to the route name we picked for your Nginx proxy app.
4. Switch to the Source Control and commit and push all the changes as before.
8
Inspecting the structure
Take some time to inspect the structure of the project. This service is designed to have dual-purpose
– it serves two pages (/ and /about) and also serves the shared header (this header is going to be
reused by all micro-services). Shared header is served from /header path.
Some sections of the code are commented out now (mostly authentication and session sharing). We
will change that later on.
Setting up the delivery pipeline for Bluemix deployment
Repeat the delivery pipeline configuration.
1. When configuring the builder, select ‘Simple’ as before.
2. Configure the deployment stage by making sure org and space selections are correct. Accept
the default choices for the rest.
3. Build and deploy. When done, navigate to the app URL to verify it is working.
Hooking up the micro-service to the proxy
Switch to the Nginx proxy project and edit ‘nginx.conf’ ‘server’ section to add a reverse proxy
section:
server {
listen <%= ENV["PORT"] %>;
location / {
proxy_pass https://<node1-app-name>.mybluemix.net/;
}
Switch to the Source Control view, Select All file changes on the right, add the commit summary,
Commit and Push the change.
Switch to the Delivery Pipeline and wait for the deployment to finish.
When done, navigate to the proxy URL and verify that we are seeing the Node app instead of our
index.html dummy content.
9
Enabling Facebook authentication
We now want to enable authentication that is already part of the Node app.
Registering Facebook OAuth client
Before proceeding, we need to obtain credentials from Facebook.
1. Log into Facebook and navigate to http://developers.facebook.com
2. Click on ‘My Apps’ in the header and select ‘Add new app’
3. Select ‘Website’ from the list of choices (the last one)
4. Select ‘Skip and Create App ID’ in the upper right
5. Select ‘Settings’ on the left, then ‘Advanced’ at the top
6. Scroll down to ‘Security’, ‘Valid OAuth redirect URIs’
7. Enter the direct URL of your node App (https://<app-name>.mybluemix.net) as well as
proxied URl (https://<proxy-name>.mybluemix.net). Save changes.
8. Go back to ‘Basic’ and copy ‘App ID’ and ‘App Secret’ values. You need to copy them into
‘/config/auth.json’ file in our NodeJS into ‘client’ and ‘secret’ properties.
Enabling authentication code
Go into app.js and uncomment the sections that are currently commented (but only those marked
with ‘Uncomment to enable authentication’. Once done, switch to Source Control and commit/push
the changes to Git.
Switch to the Delivery Pipeline and wait the deployment to finish.
Navigate to your proxy URL and click on ‘Login’ link in the upper right. Verify that log in works and
that you are now rendered in the authenticated state, with your profile picture showing and the body
of the Home page showing your user name.
Switching to Redis session store
We now want to switch from in-memory to Redis session store. Before using it, we will need to bind
a Redis service to our app.
10
1. Go to Bluemix Dashboard and navigate to your Node app running in our org and space.
2. Click on ‘Add a service’ button to open the catalog.
3. Chose ‘redis’ service from Web and App category (last service in the list).
4. Ensure that Space and App in the upper right of the service page is your space and app.
Press ‘Create’. Wait for the app to restage.
5. Switch to Web IDE and open app.js. Scroll down near the end where session is configured.
6. Comment the lines marked with ‘Comment this to disable memory store’
7. Uncomment the lines marked with ‘Uncomment this to enable Redis store’
8. Switch to Source Control view, Select All, add summery, commit and push.
9. Switch to the Build & Deploy and wait until the app has been deployed.
10. Navigate to the proxy URL and verify that authentication still works as before.
Adding another NodeJS micro-service
The demo so far has everything working vertically, but it is needlessly complex for just one micro-
service. We will now add another and it will become clear why the complexity was needed.
Forking the ‘Page 2’ project
We will start by creating a new project by forking the existing Node micro-service project written to
provide ‘Page 2’ for the micro-service system:
1. Go to ‘Explore’ and search for a project with a name ‘codemotion-node2-start’
2. Navigate into it and fork it. As before, give it a name that can be used as a unique app name,
and also as a first segment of the URL.
3. Switch to Code.
4. Edit ‘manifest.yml’ to change the app and route name.
5. Edit ‘/config/auth.json’ and copy Facebook app ID and secret from the first micro-service.
6. Edit ‘/config/app.json’ and change the header URL property to use the domain of your own
NodeJS app serving the header (the first one we created). Also change the references to
‘codemotion-proxy’ to the name of your proxy app.
11
7. Now switch to the Source Control page and commit and push these changes to the Git repo.
8. Switch to the Delivery Pipeline and configure the builder to ‘NPM’, add a stage and configure
it to deploy to your org and space.
9. Request a build and wait until it finished deploying.
10. Go to Bluemix dashboard and bind the app to the same Redis instance as the first page app.
Adding the new micro-service path to the proxy
Navigate to your proxy project, go into Web IDE and open nginx.conf. Add the line to proxy the
‘page2’ path:
location / {
proxy_pass https://<node1-app-name>.mybluemix.net/;
}
location /page2/ {
proxy_pass https://<node2-app-name>.mybluemix.net/page2/;
}
Switch to the source control, commit and push this change and let it build and deploy.
Try it out. You should see something like this (with different URLs of course).
12
Fall
Figure 1 The final demo state
Congratulations – you have built a micro-service system with Nginx proxy, two Node micro-services
and session backed by Redis store.
You can now go and build a real-world site using these ideas. Have fun during the rest of
Codemotion Rome 2015!

Weitere ähnliche Inhalte

Was ist angesagt?

1-01: Introduction To Web Development
1-01: Introduction To  Web  Development1-01: Introduction To  Web  Development
1-01: Introduction To Web Development
apnwebdev
 
High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)
Nicholas Zakas
 

Was ist angesagt? (20)

The Future of the Web - Cold Front conference 2016
The Future of the Web - Cold Front conference 2016The Future of the Web - Cold Front conference 2016
The Future of the Web - Cold Front conference 2016
 
Ajax
Ajax Ajax
Ajax
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
 
1-01: Introduction To Web Development
1-01: Introduction To  Web  Development1-01: Introduction To  Web  Development
1-01: Introduction To Web Development
 
jQuery 1.9 and 2.0 - Present and Future
jQuery 1.9 and 2.0 - Present and FuturejQuery 1.9 and 2.0 - Present and Future
jQuery 1.9 and 2.0 - Present and Future
 
Introduction To Umbraco
Introduction To UmbracoIntroduction To Umbraco
Introduction To Umbraco
 
Polytechnic 1.0 Granada
Polytechnic 1.0 GranadaPolytechnic 1.0 Granada
Polytechnic 1.0 Granada
 
Mobile Information Architecture
Mobile Information ArchitectureMobile Information Architecture
Mobile Information Architecture
 
Web Application Development Process presented by @Cygnismedia
Web Application Development Process presented by @CygnismediaWeb Application Development Process presented by @Cygnismedia
Web Application Development Process presented by @Cygnismedia
 
JOSA TechTalks - RESTful API Concepts and Best Practices
JOSA TechTalks - RESTful API Concepts and Best PracticesJOSA TechTalks - RESTful API Concepts and Best Practices
JOSA TechTalks - RESTful API Concepts and Best Practices
 
Azure and Umbraco CMS
Azure and Umbraco CMSAzure and Umbraco CMS
Azure and Umbraco CMS
 
Social Connections VI Prague - An introduction to ibm connections as an appde...
Social Connections VI Prague - An introduction to ibm connections as an appde...Social Connections VI Prague - An introduction to ibm connections as an appde...
Social Connections VI Prague - An introduction to ibm connections as an appde...
 
Wordpress development 101
Wordpress development 101Wordpress development 101
Wordpress development 101
 
High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)High Performance JavaScript (CapitolJS 2011)
High Performance JavaScript (CapitolJS 2011)
 
Responsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and TechniquesResponsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and Techniques
 
Web workers
Web workersWeb workers
Web workers
 
Intro to Web Development
Intro to Web DevelopmentIntro to Web Development
Intro to Web Development
 
5 Reasons Why Your Website Is[n’t] a Native App (PrDC 2015)
5 Reasons Why Your Website Is[n’t] a Native App (PrDC 2015)5 Reasons Why Your Website Is[n’t] a Native App (PrDC 2015)
5 Reasons Why Your Website Is[n’t] a Native App (PrDC 2015)
 
Introduction to React for Frontend Developers
Introduction to React for Frontend DevelopersIntroduction to React for Frontend Developers
Introduction to React for Frontend Developers
 

Andere mochten auch

Lean@core lean startup e cloud- - Codemotion Rome 2015
Lean@core   lean startup e cloud- - Codemotion Rome 2015Lean@core   lean startup e cloud- - Codemotion Rome 2015
Lean@core lean startup e cloud- - Codemotion Rome 2015
Codemotion
 
Engineering Design for Facebook
Engineering Design for FacebookEngineering Design for Facebook
Engineering Design for Facebook
Codemotion
 

Andere mochten auch (20)

Lean@core lean startup e cloud- - Codemotion Rome 2015
Lean@core   lean startup e cloud- - Codemotion Rome 2015Lean@core   lean startup e cloud- - Codemotion Rome 2015
Lean@core lean startup e cloud- - Codemotion Rome 2015
 
Matteo Valoriani - How Augment your Reality: different perspective on the Rea...
Matteo Valoriani - How Augment your Reality: different perspective on the Rea...Matteo Valoriani - How Augment your Reality: different perspective on the Rea...
Matteo Valoriani - How Augment your Reality: different perspective on the Rea...
 
Massimo Bonanni - L'approccio ai microservizi secondo Service Fabric - Codemo...
Massimo Bonanni - L'approccio ai microservizi secondo Service Fabric - Codemo...Massimo Bonanni - L'approccio ai microservizi secondo Service Fabric - Codemo...
Massimo Bonanni - L'approccio ai microservizi secondo Service Fabric - Codemo...
 
Nicola Corti - Building UI Consistent Android Apps - Codemotion Milan 2017
Nicola Corti - Building UI Consistent Android Apps - Codemotion Milan 2017Nicola Corti - Building UI Consistent Android Apps - Codemotion Milan 2017
Nicola Corti - Building UI Consistent Android Apps - Codemotion Milan 2017
 
Gabriele Nocco - Massive distributed processing with H2O - Codemotion Milan 2017
Gabriele Nocco - Massive distributed processing with H2O - Codemotion Milan 2017Gabriele Nocco - Massive distributed processing with H2O - Codemotion Milan 2017
Gabriele Nocco - Massive distributed processing with H2O - Codemotion Milan 2017
 
Steve Sfartz - How to embed Messaging and Video in your apps - Codemotion Mil...
Steve Sfartz - How to embed Messaging and Video in your apps - Codemotion Mil...Steve Sfartz - How to embed Messaging and Video in your apps - Codemotion Mil...
Steve Sfartz - How to embed Messaging and Video in your apps - Codemotion Mil...
 
Tiffany Conroy - Remote device sign-in – Authenticating without a keyboard - ...
Tiffany Conroy - Remote device sign-in – Authenticating without a keyboard - ...Tiffany Conroy - Remote device sign-in – Authenticating without a keyboard - ...
Tiffany Conroy - Remote device sign-in – Authenticating without a keyboard - ...
 
Gabriele Petronella - Mythical trees and where to find them - Codemotion Mila...
Gabriele Petronella - Mythical trees and where to find them - Codemotion Mila...Gabriele Petronella - Mythical trees and where to find them - Codemotion Mila...
Gabriele Petronella - Mythical trees and where to find them - Codemotion Mila...
 
James Williams - Demystifying Constraint Layout - Codemotion Milan 2017
James Williams - Demystifying Constraint Layout - Codemotion Milan 2017James Williams - Demystifying Constraint Layout - Codemotion Milan 2017
James Williams - Demystifying Constraint Layout - Codemotion Milan 2017
 
9
99
9
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
 
Anna Makarudze - Django Girls: Inspiring women to fall in love with programmi...
Anna Makarudze - Django Girls: Inspiring women to fall in love with programmi...Anna Makarudze - Django Girls: Inspiring women to fall in love with programmi...
Anna Makarudze - Django Girls: Inspiring women to fall in love with programmi...
 
Claudio Carboni - ArcGIS platformthe foundation of your idea - Codemotion Mil...
Claudio Carboni - ArcGIS platformthe foundation of your idea - Codemotion Mil...Claudio Carboni - ArcGIS platformthe foundation of your idea - Codemotion Mil...
Claudio Carboni - ArcGIS platformthe foundation of your idea - Codemotion Mil...
 
6
66
6
 
5
55
5
 
Engineering Design for Facebook
Engineering Design for FacebookEngineering Design for Facebook
Engineering Design for Facebook
 
Vincenzo Chianese - REST, for real! - Codemotion Milan 2017
Vincenzo Chianese - REST, for real! - Codemotion Milan 2017Vincenzo Chianese - REST, for real! - Codemotion Milan 2017
Vincenzo Chianese - REST, for real! - Codemotion Milan 2017
 
Maurizio Moriconi - ARKit: Augmented Reality made simple - Codemotion Milan 2017
Maurizio Moriconi - ARKit: Augmented Reality made simple - Codemotion Milan 2017Maurizio Moriconi - ARKit: Augmented Reality made simple - Codemotion Milan 2017
Maurizio Moriconi - ARKit: Augmented Reality made simple - Codemotion Milan 2017
 
Demi Ben-Ari - Monitoring Big Data Systems Done "The Simple Way" - Codemotion...
Demi Ben-Ari - Monitoring Big Data Systems Done "The Simple Way" - Codemotion...Demi Ben-Ari - Monitoring Big Data Systems Done "The Simple Way" - Codemotion...
Demi Ben-Ari - Monitoring Big Data Systems Done "The Simple Way" - Codemotion...
 
Giovanni Laquidara - Hello ARCore - Codemotion Milan 2017
Giovanni Laquidara - Hello ARCore - Codemotion Milan 2017Giovanni Laquidara - Hello ARCore - Codemotion Milan 2017
Giovanni Laquidara - Hello ARCore - Codemotion Milan 2017
 

Ähnlich wie Codemotion rome 2015 bluemix lab tutorial -- Codemotion Rome 2015

Ähnlich wie Codemotion rome 2015 bluemix lab tutorial -- Codemotion Rome 2015 (20)

Codemotion Rome 2015 Bluemix Lab Tutorial
Codemotion Rome 2015 Bluemix Lab TutorialCodemotion Rome 2015 Bluemix Lab Tutorial
Codemotion Rome 2015 Bluemix Lab Tutorial
 
Become an IBM Cloud Architect in 40 Minutes
Become an IBM Cloud Architect in 40 MinutesBecome an IBM Cloud Architect in 40 Minutes
Become an IBM Cloud Architect in 40 Minutes
 
MQ Light in IBM MQ: IBM Interconnect 2015 session AME4182
MQ Light in IBM MQ:  IBM Interconnect 2015 session AME4182MQ Light in IBM MQ:  IBM Interconnect 2015 session AME4182
MQ Light in IBM MQ: IBM Interconnect 2015 session AME4182
 
2829 liberty
2829 liberty2829 liberty
2829 liberty
 
OpenWhisk Introduction
OpenWhisk IntroductionOpenWhisk Introduction
OpenWhisk Introduction
 
Exposing auto-generated Swagger 2.0 documents from Liberty!
Exposing auto-generated Swagger 2.0 documents from Liberty!Exposing auto-generated Swagger 2.0 documents from Liberty!
Exposing auto-generated Swagger 2.0 documents from Liberty!
 
SHARE2016: DevOps - IIB Administration for Continuous Delivery and DevOps
SHARE2016:  DevOps - IIB Administration for Continuous Delivery and DevOpsSHARE2016:  DevOps - IIB Administration for Continuous Delivery and DevOps
SHARE2016: DevOps - IIB Administration for Continuous Delivery and DevOps
 
BP205: There’s an API for that! Why and how to build on the IBM Connections P...
BP205: There’s an API for that! Why and how to build on the IBM Connections P...BP205: There’s an API for that! Why and how to build on the IBM Connections P...
BP205: There’s an API for that! Why and how to build on the IBM Connections P...
 
2449 rapid prototyping of innovative io t solutions
2449   rapid prototyping of innovative io t solutions2449   rapid prototyping of innovative io t solutions
2449 rapid prototyping of innovative io t solutions
 
How to Adopt Docker Within Your Enterprise Using IBM UrbanCode Deploy (Interc...
How to Adopt Docker Within Your Enterprise Using IBM UrbanCode Deploy (Interc...How to Adopt Docker Within Your Enterprise Using IBM UrbanCode Deploy (Interc...
How to Adopt Docker Within Your Enterprise Using IBM UrbanCode Deploy (Interc...
 
Design, Auto-Generate and Expose RESTful Microservices Using Open Source and ...
Design, Auto-Generate and Expose RESTful Microservices Using Open Source and ...Design, Auto-Generate and Expose RESTful Microservices Using Open Source and ...
Design, Auto-Generate and Expose RESTful Microservices Using Open Source and ...
 
Using Bluemix and Node-RED for Fast Prototyping
Using Bluemix and Node-RED for Fast PrototypingUsing Bluemix and Node-RED for Fast Prototyping
Using Bluemix and Node-RED for Fast Prototyping
 
6329 get hands on with kubernetes v2
6329 get hands on with kubernetes v26329 get hands on with kubernetes v2
6329 get hands on with kubernetes v2
 
The Bluemix Quadruple Threat
The Bluemix Quadruple ThreatThe Bluemix Quadruple Threat
The Bluemix Quadruple Threat
 
Docking DevOps 2015-03-01
Docking DevOps 2015-03-01Docking DevOps 2015-03-01
Docking DevOps 2015-03-01
 
Docking DevOps 2015-03-01
Docking DevOps 2015-03-01Docking DevOps 2015-03-01
Docking DevOps 2015-03-01
 
InterConnect 2017 : Git for COBOL and PL/I?—Yes, It Can Make Sense
InterConnect 2017 : Git for COBOL and PL/I?—Yes, It Can Make SenseInterConnect 2017 : Git for COBOL and PL/I?—Yes, It Can Make Sense
InterConnect 2017 : Git for COBOL and PL/I?—Yes, It Can Make Sense
 
Improving Software Delivery with Software Defined Environments (IBM Interconn...
Improving Software Delivery with Software Defined Environments (IBM Interconn...Improving Software Delivery with Software Defined Environments (IBM Interconn...
Improving Software Delivery with Software Defined Environments (IBM Interconn...
 
Cloud Roundtable | Your PaaS to DevOps
Cloud Roundtable | Your PaaS to DevOpsCloud Roundtable | Your PaaS to DevOps
Cloud Roundtable | Your PaaS to DevOps
 
IBM Collaboration Solutions Application Development - Frequently Asked Questions
IBM Collaboration Solutions Application Development - Frequently Asked QuestionsIBM Collaboration Solutions Application Development - Frequently Asked Questions
IBM Collaboration Solutions Application Development - Frequently Asked Questions
 

Mehr von Codemotion

Mehr von Codemotion (20)

Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
 
Pompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyPompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending story
 
Pastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaPastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storia
 
Pennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserPennisi - Essere Richard Altwasser
Pennisi - Essere Richard Altwasser
 
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
 
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
 
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
 

Codemotion rome 2015 bluemix lab tutorial -- Codemotion Rome 2015

  • 1. Codemotion Bluemix Lab Building a Micro-Service System Using IBM DevOps Services and Bluemix March 28th 2015
  • 2. 3 Notices and Disclaimers Copyright © 2015 by International Business Machines Corporation (IBM). No part of this document may be reproduced or transmitted in any form without written permission from IBM. U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM. Information in these presentations (including information relating to products that have not yet been announced by IBM) has been reviewed for accuracy as of the date of initial publication and could include unintentional technical or typographical errors. IBM shall have no responsibility to update this information. THIS document is distributed "AS IS" without any warranty, either express or implied. In no event shall IBM be liable for any damage arising from the use of this information, including but not limited to, loss of data, business interruption, loss of profit or loss of opportunity. IBM products and services are warranted according to the terms and conditions of the agreements under which they are provided. Any statements regarding IBM's future direction, intent or product plans are subject to change or withdrawal without notice. Performance data contained herein was generally obtained in a controlled, isolated environments. Customer examples are presented as illustrations of how those customers have used IBM products and the results they may have achieved. Actual performance, cost, savings or other results in other operating environments may vary. References in this document to IBM products, programs, or services does not imply that IBM intends to make such products, programs or services available in all countries in which IBM operates or does business. Workshops, sessions and associated materials may have been prepared by independent session speakers, and do not necessarily reflect the views of IBM. All materials and discussions are provided for informational purposes only, and are neither intended to, nor shall constitute legal or other guidance or advice to any individual participant or their specific situation. It is the customer’s responsibility to insure its own compliance with legal requirements and to obtain advice of competent legal counsel as to the identification and interpretation of any relevant laws and regulatory requirements that may affect the customer’s business and any actions the customer may need to take to comply with such laws. IBM does not provide legal advice or represent or warrant that its services or products will ensure that the customer is in compliance with any law. Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other publicly available sources. IBM has not tested those products in connection with this publication and cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products. IBM does not warrant the quality of any third-party products, or the ability of any such third- party products to interoperate with IBM’s products. IBM expressly disclaims all warranties, expressed or implied, including but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The provision of the information contained herein is not intended to, and does not, grant any right or license under any IBM patents, copyrights, trademarks or other intellectual property right. • IBM, the IBM logo, ibm.com, Bluemix, Blueworks Live, CICS, Clearcase, DOORS®, Enterprise Document Management System™, Global Business Services ®, Global Technology Services ®, Information on Demand, ILOG, Maximo®, MQIntegrator®, MQSeries®, Netcool®, OMEGAMON, OpenPower, PureAnalytics™, PureApplication®, pureCluster™, PureCoverage®, PureData®, PureExperience®, PureFlex®, pureQuery®, pureScale®, PureSystems®, QRadar®, Rational®, Rhapsody®, SoDA, SPSS, StoredIQ, Tivoli®, Trusteer®, urban{code}®, Watson, WebSphere®, Worklight®, X-Force® and System z® Z/OS, are trademarks of International Business Machines Corporation, registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at: www.ibm.com/legal/copytrade.shtml.
  • 3. 4 Contents Introduction 5 Preparing Bluemix 5 Setting up the Nginx proxy 6 Forking Nginx proxy project 6 Setting up the delivery pipeline 6 Writing the first NodeJS micro-service 7 Adapting the code 7 Inspecting the structure 8 Setting up the delivery pipeline for Bluemix deployment 8 Hooking up the micro-service to the proxy 8 Enabling Facebook authentication 9 Registering Facebook OAuth client 9 Enabling authentication code 9 Switching to Redis session store 9 Adding another NodeJS micro-service 10 Forking the ‘Page 2’ project 10 Adding the new micro-service path to the proxy 11
  • 4. 5 Introduction Welcome to the managed Codemotion Rome 2015 lab, where you are going to build a micro-service system using NodeJS, Nginx, Redis, Facebook OAuth2 and other technologies using solely IBM DevOps Services for development, and deploy it to IBM Bluemix PaaS. The fact that we only need a browser for this is amazing and shows the power of both platforms. Important: There are certain preconditions for participating in the lab: 1. You need to have an IBM ID and a Bluemix account (http://bluemix.net). If not, sign up at ibm.biz/Bluemix2015 for both. 2. Once you have your IBM ID, you can use it to sign in into IBM DevOps Services (http://hub.jazz.net). Verify you can do it before starting the work. 3. For the authentication portion of the lab, you need to have a Facebook account (I know, crazy). You can use it to create a Facebook app and its credentials at http://developers.facebook.com . This lab assumes you have basic understanding of JavaScript and NodeJS, as well as Web development. The purpose of this lab is to gradually build a small micro-service system using techniques such as UI composition and federated authentication. We will build it step by step, with success checkpoints along the way. Preparing Bluemix Before we start writing applications and deploying them to Bluemix, we want to make sure we have an organization and space where we will deploy our apps and services. 1. Log into the Bluemix dashboard 2. Verify that the organization you received as part of your trial account is being selected (top left) 3. You should have at least one space created (dev). This is the space we will use to deploy all our apps. 4. Select the ‘US South’ region in the top right drop-down menu and create a new space if required (dev).
  • 5. 6 Setting up the Nginx proxy We will proxy all the micro-services so that we have a feel that we are running a single app. We will use Nginx for this purpose. Forking Nginx proxy project Start by forking a project in IBM DevOps Services (IDS in short): 1. Log into https://hub.jazz.net/. You should end up in the page called ‘My Stuff’. 2. Switch to ‘Explore’ and enter ‘codemotion-proxy-start’ in the search field. A single project should appear. Follow the title link to go in. 3. Locate the ‘FORK PROJECT’ button in the upper right section, and press it. A dialog should appear. 4. Name the project (use something that can also be useful as an app name and first segment in the URL domain). 5. Leave it public, or make it private to you, deselect ‘features for Scrum development’, and select ‘Deploy to Bluemix’ checkbox. 6. Chose the Bluemix ‘US South’ region, the org and space you previously set up. Once the project has been forked, you will be in the project overview page. Click on ‘Edit Code’ to switch to the Web IDE. Before setting up the pipeline, make sure all code changes are committed: 1. Switch to the Source Control view in Web IDE (second tab on the left nav bar), 2. If there are changes, add some summary, Select All, Commit, and then Push (on the left side of the screen). You should get the ‘Fast Forward’ green notification that the push succeeded. 3. Remember these steps – we will need to repeat them every time we change code so that the code is committed to Git and picked up by the delivery pipeline. Setting up the delivery pipeline Observe the file ‘index.html’ – it contains some boilerplate text to show us we have Nginx running. Now switch to ‘Build & Deploy’ button in the upper right corner of the page. 1. After reading the ‘Welcome’ message, you can close the panel. Click on ‘ADD STAGE’.
  • 6. 7 2. Accept the defaults on the first page of the dialog. Select ‘Jobs’ and ‘Add Job’. Pick ‘Build’ from the list, select ‘Simple’. Also name the stage (e.g. ‘Build’) and Save. 3. Add a new deployment stage by repeating steps (1) and (2), only this time select ‘Deploy’ as the job type. Name the stage (e.g. ‘Deploy’). 4. Verify that the org and space are correct. 5. Modify the deploy script as follows: cf push "${CF_APP}" -b https://github.com/cloudfoundry-community/staticfile-buildpack.git 6. Save. Kick-start the pipeline by pressing the ‘Play’ button at the top of the Build stage. If all goes well, the build will quickly finish, followed by automatic deployment to the domain <my app name>.mybluemix.net Verify the deployment by navigating to http://<my-app-name>.mybluemix.net. You can also switch to Bluemix and observe the app running in the designated space. Writing the first NodeJS micro-service Go to Explore page and search for ‘codemotion-node1-start’ project. When you find it, click on it and fork it into your own. Again, pick a name that will be useful for both the Bluemix app name and the URL domain (e.g.: ‘IC2015-<initials>-Home’). Adapting the code You need to make changes to the forked project in several places: 1. Click on ‘package.json’ and change the name to reflect your app name it’s not already done. 2. Click on ‘manifest.yml’ and do the same for the app name, and host name (the first segment of the URL before mybluemix.net). 3. Go into /config/app.json and change all occurrences of <app1-name> to your chosen route/app name as specified in manifest.yml. Also change all occurrences of <proxy-name> to the route name we picked for your Nginx proxy app. 4. Switch to the Source Control and commit and push all the changes as before.
  • 7. 8 Inspecting the structure Take some time to inspect the structure of the project. This service is designed to have dual-purpose – it serves two pages (/ and /about) and also serves the shared header (this header is going to be reused by all micro-services). Shared header is served from /header path. Some sections of the code are commented out now (mostly authentication and session sharing). We will change that later on. Setting up the delivery pipeline for Bluemix deployment Repeat the delivery pipeline configuration. 1. When configuring the builder, select ‘Simple’ as before. 2. Configure the deployment stage by making sure org and space selections are correct. Accept the default choices for the rest. 3. Build and deploy. When done, navigate to the app URL to verify it is working. Hooking up the micro-service to the proxy Switch to the Nginx proxy project and edit ‘nginx.conf’ ‘server’ section to add a reverse proxy section: server { listen <%= ENV["PORT"] %>; location / { proxy_pass https://<node1-app-name>.mybluemix.net/; } Switch to the Source Control view, Select All file changes on the right, add the commit summary, Commit and Push the change. Switch to the Delivery Pipeline and wait for the deployment to finish. When done, navigate to the proxy URL and verify that we are seeing the Node app instead of our index.html dummy content.
  • 8. 9 Enabling Facebook authentication We now want to enable authentication that is already part of the Node app. Registering Facebook OAuth client Before proceeding, we need to obtain credentials from Facebook. 1. Log into Facebook and navigate to http://developers.facebook.com 2. Click on ‘My Apps’ in the header and select ‘Add new app’ 3. Select ‘Website’ from the list of choices (the last one) 4. Select ‘Skip and Create App ID’ in the upper right 5. Select ‘Settings’ on the left, then ‘Advanced’ at the top 6. Scroll down to ‘Security’, ‘Valid OAuth redirect URIs’ 7. Enter the direct URL of your node App (https://<app-name>.mybluemix.net) as well as proxied URl (https://<proxy-name>.mybluemix.net). Save changes. 8. Go back to ‘Basic’ and copy ‘App ID’ and ‘App Secret’ values. You need to copy them into ‘/config/auth.json’ file in our NodeJS into ‘client’ and ‘secret’ properties. Enabling authentication code Go into app.js and uncomment the sections that are currently commented (but only those marked with ‘Uncomment to enable authentication’. Once done, switch to Source Control and commit/push the changes to Git. Switch to the Delivery Pipeline and wait the deployment to finish. Navigate to your proxy URL and click on ‘Login’ link in the upper right. Verify that log in works and that you are now rendered in the authenticated state, with your profile picture showing and the body of the Home page showing your user name. Switching to Redis session store We now want to switch from in-memory to Redis session store. Before using it, we will need to bind a Redis service to our app.
  • 9. 10 1. Go to Bluemix Dashboard and navigate to your Node app running in our org and space. 2. Click on ‘Add a service’ button to open the catalog. 3. Chose ‘redis’ service from Web and App category (last service in the list). 4. Ensure that Space and App in the upper right of the service page is your space and app. Press ‘Create’. Wait for the app to restage. 5. Switch to Web IDE and open app.js. Scroll down near the end where session is configured. 6. Comment the lines marked with ‘Comment this to disable memory store’ 7. Uncomment the lines marked with ‘Uncomment this to enable Redis store’ 8. Switch to Source Control view, Select All, add summery, commit and push. 9. Switch to the Build & Deploy and wait until the app has been deployed. 10. Navigate to the proxy URL and verify that authentication still works as before. Adding another NodeJS micro-service The demo so far has everything working vertically, but it is needlessly complex for just one micro- service. We will now add another and it will become clear why the complexity was needed. Forking the ‘Page 2’ project We will start by creating a new project by forking the existing Node micro-service project written to provide ‘Page 2’ for the micro-service system: 1. Go to ‘Explore’ and search for a project with a name ‘codemotion-node2-start’ 2. Navigate into it and fork it. As before, give it a name that can be used as a unique app name, and also as a first segment of the URL. 3. Switch to Code. 4. Edit ‘manifest.yml’ to change the app and route name. 5. Edit ‘/config/auth.json’ and copy Facebook app ID and secret from the first micro-service. 6. Edit ‘/config/app.json’ and change the header URL property to use the domain of your own NodeJS app serving the header (the first one we created). Also change the references to ‘codemotion-proxy’ to the name of your proxy app.
  • 10. 11 7. Now switch to the Source Control page and commit and push these changes to the Git repo. 8. Switch to the Delivery Pipeline and configure the builder to ‘NPM’, add a stage and configure it to deploy to your org and space. 9. Request a build and wait until it finished deploying. 10. Go to Bluemix dashboard and bind the app to the same Redis instance as the first page app. Adding the new micro-service path to the proxy Navigate to your proxy project, go into Web IDE and open nginx.conf. Add the line to proxy the ‘page2’ path: location / { proxy_pass https://<node1-app-name>.mybluemix.net/; } location /page2/ { proxy_pass https://<node2-app-name>.mybluemix.net/page2/; } Switch to the source control, commit and push this change and let it build and deploy. Try it out. You should see something like this (with different URLs of course).
  • 11. 12 Fall Figure 1 The final demo state Congratulations – you have built a micro-service system with Nginx proxy, two Node micro-services and session backed by Redis store. You can now go and build a real-world site using these ideas. Have fun during the rest of Codemotion Rome 2015!