Deply Yur First Clud Fundry App t Any Clud Fundry Service Prvider cludwrkshp.rg/cludfundry Presenter: Dave Nielsen Clud Cmputing Evangelist @davenielsen May 2015 Dave Nielsen dnielsen@gmail.cm twitter.cm/davenielsen linkedin.cm/in/dnielsen 1
Table f Cntents: 1. ABOUT THIS WORKSHOP... 3 2. TARGET AUDIENCE... 3 3. PRE- REQUISITES... 3 Exercise 1: Deply Hell Clud app... 3 Exercise 2: Deply "Cntact Frm" with a database... 6 2
1. Abut This Wrkshp: This wrkshp will teach anyne with basic IT understanding hw t deply his r her first Clud Fundry Web app. 2. Target Audience: Other than installing sftware and typing cmmands in a terminal, we dn t use any advanced tls, s IT prs, develpers, architects, and prject managers shuld be able t cmplete this wrkshp. 3. Pre-requisites: Fr this wrkshp, yu will need: Yur wn Windws, Mac, r Linux cmputer with internet access A Clud Fundry Service Prvider (CFSP): Pivtal Web Services r IBM Bluemix. Other Clud Fundry service prviders may be used, but these instructins have nt been tested with them: Pivtal Web Services: run.pivtal.i (30-day trial) IBM Bluemix: bluemix.net (30-day trial) Stackat (by ActiveState): activestate.cm/stackat/sandbx (30 day trial) HP Helin Dev Platfrm (cming sn) CenturyLink (cming sn) An e-mail address. Like many free Clud Cmputing services, Clud Fundry service prviders require that yu have a valid e-mail. Nte: Pivtal Web Services als requires that yu prvide an SMS-enabled phne number, t verify that yu are nt a bt. Exercise 1: Deply and Scale the Hell Clud app 1. Prepare yur applicatin: a. Dwnlad (r create) yur first applicatin Yu can dwnlad the Hell Clud app created fr this exercise frm http://cludwrkshp.rg/cludfundry Unzip the hellclud.zip archive int any directry yu want (such as c:/wrkshp (r ~/wrkshp). Navigate t the new hellclud app flder (such as c:/wrkshp/hellclud (r ~/wrkshp/hellclud). Mdify the text in the manifest.yml file as required t deply yur app. Change hst: prperty frm cf-nde-hellclud-dcn t a unique hstname with yur initials. Fr example, yu might change the last three letters t that f yur wn initials, such as xyz (such as cf-nde-hellclud-xyz). 3
Quiz: What happens if yu run this app cde n a server that is nt Clud Fundry? 2. Create yur accunt: a. Sign-up fr yur free trial: Pivtal Web Services, 60-day trial: http://run.pivtal.i IBM Bluemix, 30-day trial: http://bluemix.net b. Check yur e-mail. Click the link t verify yur e-mail address. Pivtal will als require that yu cnfirm yur mbile phne number via SMS text message. c. Create an rg, e.g., mydevteam. Nte: Bluemix will create an rg fr yu based n yur e-mail address. 3. Setup yur develpment space: a. Dwnlad the Clud Fundry CLI: Visit http://github.cm/cludfundry/cli Scrll dwn t the "Dwnlads" sectin f the github page Dwnlad the apprpriate (stable) installer b. Install the Clud Fundry CLI: Fr Windws: Unzip the installer-windws.zip file yu dwnladed abve. Run the cf_installer.exe that was unzipped by the previus step This will create a flder: C:\Prgram Files (x86)\cludfundry Add the C:\Prgram Files (x86)\cludfundry t yur %PATH% variable Open the Cmmand app (cmd.exe) Type the fllwing cmmand t make sure the CLI was installed crrectly: Fr Mac: > cf help Open the Terminal applicatin. Type the fllwing cmmand t make sure the CLI was installed crrectly: $ cf help c. Run the fllwing cmmand t lg int yur Clud Fundry service prvider accunt: > cf lgin -a https://api.run.pivtal.i r > cf lgin -a https://api.ng.bluemix.net When prmpted, enter the e-mail address and passwrd yu used t create yur Clud Fundry Service Prvider accunt. d. Run the fllwing cmmands t see details abut yur rg and space: 4
> cf apps > cf rgs > cf spaces > cf target - [rg] -s [space] example: > cf target - mydevteam -s develpment e. Push yur app (run this cmmand frm within yur hellclud app flder): > cf push f. Run the apps cmmand again and see yur new app listed: > cf apps g. Run the app cmmand t see health and status details abut a specific app: > cf app [app name] example: > cf app hellclud h. Run the scale cmmand t increase the number f instances running yur new app: > cf scale [app name] -i [# f instances] example: > cf scale hellclud i 2 i. Open yur Web brwser t the URL prvided by the utput f the cf push prcess. It shuld lk smething like this: Fr Pivtal Web Services: cf-nde-hellclud-<yur initials>.cfapps.i Fr IBM Bluemix: cf-nde-hellclud-<yur initials>.mybluemix.net j. Open the Web cnsle and view the dashbard fr yur app: See yur app listed within the develper space dashbard. Click n yur app t see the app s dashbard. Click the Plus (+) buttn tw mre times t add a cuple mre instances t yur app. View yur app in the Web brwser again t see the new instances in use. Yu may have t refresh the Web brwser a few times. k. G back t yur terminal and shut dwn yur app: Reduce the number f app instances t ne: > cf scale [app name] -i 1 Then stp yur instance, s yu dn t use up any mre f yur free trial hurs: > cf stp [app name] > cf apps Finally, delete yur instance, s yu dn t take up any space at all > cf delete [app name] 5
> cf apps l. View the lgs and events yu have generated s far: T view Events: > cf events [app name] T view Lgs: > cf lgs [app name] m. View ther infrmatin f interest, such as buildpacks and qutas: > cf buildpacks > cf qutas Exercise 2: Deply Cntact Frm and a Database Service 1. Prepare yur applicatin: a. Dwnlad (r create) yur applicatin (http://www.cludwrkshp.rg/cludfundry/) Unzip it int c:/wrkshp/cntactfrm (r ~/wrkshp/cntactfrm). Navigate int this new app flder. Mdify the surce cde in the manifest.yml file. Change hst prperty frm cf-nde-cntactfrm t a unique hstname. Fr example, yu might add yur wn initials t cntactfrm t create a unique hstname, such as cntactfrm-dcn. b. (Optinal) Setup a runtime envirnment n yur cmputer and test yur app: Install Nde.js: http://ndejs.rg/dwnlad Install MySQL: http://dev.mysql.cm/dwnlads/ Install MySQL Wrkbench: http://dev.mysql.cm/dwnlads/wrkbench/ c. Push yur app: > cf push d. Test yur app: Open yur Web brwser t the URL prvided by the utput f the push cmmand. It shuld lk smething like this: Fr Pivtal Web Services: cf-nde-cntactfrm-dcn.cfapps.i Fr IBM Bluemix: cf-nde-cntactfrm-dcn.mybluemix.net Enter any name, e-mail, and message int the frm fields. Press Enter t submit the Web frm. Yu will see an errr message. Can yu guess why? It s because yu dn t have a database setup fr yur app yet. 6
2. Add a database service t yur applicatin: a. View the list f marketplace services prvided by yur CFSP and add the ClearDB service. ClearDB is a highly available MySQL service which will be used by this cntact frm app. Cmmand line: > cf marketplace > cf marketplace s cleardb Web cnsle: Click Marketplace n the Web cnsle dashbard. b. Add a database service t yur app. There are three ways f cnsuming service instance credentials within yur applicatin: Aut-cnfiguratin, CFRuntime, and manual. We will use the manual prcess. Use the Web Cnsle t bind a ClearDB service t yur app: In yur web brwser, select the Develpment space n the menu n the left side f the screen. Select Add Service. Brwse the different services available. Sme f these may be hsted by yur CFSP, thers may be hsted utside f yur CFSP. Select ClearDB MySQL Database. Click Select this plan t select the free plan. Enter an Instance Name, e.g., cf-nde-cntactfrm-mysql-dcn. Bind the service t the app: Select yur app, e.g., cf-nde-cntactfrm-dcn. Click Add. Use the cmmand line: > cf start cf-nde-cntactfrm > cf create-service cleardb spark cleardb-mine > cf bind-service cf-nde-cntactfrm clear-db-mine c. Find the service variables: In yur terminal windw, type: > cf env [app name] example: > cf env cf-nde-cntactfrm Lk fr the fllwing ClearDB prperties: hstname: username: passwrd: name: 7
Find and replace these prperty values in the server.js file and replace them with the envirnmental variables frm abve: hstname -> hst username -> user passwrd -> passwrd name -> database Use MySQL Wrkbench r any ther tl yu are familiar with t cnnect t yur ClearDB database service. Then create a database table called cntact with the fllwing fields: name varchar(50) email varchar(50) message text(50) 3. Re-pen yur Web brwser t the URL prvided by the utput f the cf push prcess. Use cf app [app name] t view the URL again. Enter yur name, e-mail, and message int the cntact frm. Press Enter t submit the frm. Yu will n lnger see an errr message because yur database nw wrks. Exercise 3: Registratin Frm with e-mail verificatin Cming sn Exercise 4: Registratin Frm with SMS verificatin Cming sn Fr mre infrmatin visit http://cludwrkshp.rg/cludfundry 8