DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js
-
Upload
neil-shannon -
Category
Documents
-
view
23 -
download
3
Transcript of DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js
![Page 1: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/1.jpg)
Building and Deploying 12 Factor Apps in Scala, Java,
Ruby, and Node.js
Neil Shannon
February 24, 2017
![Page 2: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/2.jpg)
About Me
Polyglot Developer/Architect
Founder at NTS Development LLC
Staff Software Engineer @ The Home Depot
@ntshannon | [email protected]
https://linkedin.com/in/neilshannon
https://github.com/neilshannon
![Page 3: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/3.jpg)
Agenda
What is a 12-factor app and why do I care?
How do I build a 12 factor app in Java? Scala? Ruby? Node.js?
How do I deploy my app to Pivotal Cloud Foundry?
![Page 4: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/4.jpg)
12 factors for the ImpatientI. Codebase - use version control (e.g. git)
II. Dependencies - use a dependency manager (e.g. gradle/maven/sbt)III. Config - separate configuration from code (use the OS environment)IV. Backing Services - reference resources such as DBs by URLs in the configV. Build release run - separate build from run. Use versions.
VI. Processes - run the app as one or more stateless processes.VII. Port binding - app should be self-contained. No app server.VIII. Concurrency - scale horizontally
IX. Disposability - fast startup, graceful shutdownX. Dev/Prod parity - keep environments similarXI. Logs - treat logs as event streams (no FileAppenders!)XII. Admin Processes - treat admin processes as one-off events
![Page 5: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/5.jpg)
A 12-factor app is an application designed to be deployed in the cloud.
![Page 6: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/6.jpg)
Deployment Environment
![Page 7: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/7.jpg)
The Environment
development uat
mLab service: devnexus (dev mongodb credentials)
mLab service: devnexus (dev mongodb credentials)
![Page 8: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/8.jpg)
encironment
Same access to config
Same code
Same● Application Code● Access to config● Build model● Deployment model● Environment
Different● Config values● Endpoint URIs● Number of
instances
![Page 9: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/9.jpg)
What are we going to do next?
We’re going to build an executable JAR file containing a Java web service and its dependencies.
We will tell Pivotal Cloud Foundry how to execute our application using a cloud manifest (manifest.yml).
We’re going to push our JAR to Pivotal Cloud Foundry and boot up our application.
![Page 10: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/10.jpg)
Let’s Get Started
$ git clone https://github.com/neilshannon/devnexus-microservices
![Page 11: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/11.jpg)
Prepare Environment
1. Create org in Pivotal Web Services2. Create space in Pivotal Web Services3. Create MongoLab service
![Page 12: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/12.jpg)
Prepare cloud manifest
---applications:- name: devnexus-microservices-scala buildpack: java_buildpack path: target/scala-2.11/devnexus-microservices-scala-assembly-0.1.0-SNAPSHOT.jar services: - devnexus
manifest.yml
![Page 13: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/13.jpg)
Scala Stack
![Page 14: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/14.jpg)
Scala Stack
Build - sbt
Test - specs2
Platform - Scalatra hosted in embedded Jetty container
Persistence - ReactiveMongo
REST - Scalatra
Deploy - Cloud Foundry
![Page 15: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/15.jpg)
Scala pitfalls and caveats!
Scala generates a lot of code with long class names.
CloudFoundry aufs only supports file lengths of a maximum of 243 characters.
Guess how many characters this generated class has...
Copying into the container failed: stream-in: nstar: error streaming in: exit status 2. Output: tar: shapeless/TupleTypeableInstances$$anon$17$$anonfun$cast$17$$anonfun$app$$$$9e2cdc6fa02ebaeef8cffbef37753221$$$$$128$$anonfun$apply$129$$anonfun$apply$130$$anonfun$apply$131$$anonfun$apply$132$$anonfun$apply$133$$anonfun$apply$134$$anonfun$apply$135.class: Cannot open: File name too long
![Page 16: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/16.jpg)
Java Stack
![Page 17: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/17.jpg)
Java Stack
Build - gradle
Test - JUnit
Platform - Spring Boot
Persistence - Spring Data MongoDB
REST (with hypermedia!)- Spring Data REST
Deploy - Cloud Foundry (Pivotal Web Services)
![Page 18: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/18.jpg)
Ruby Stack
rack-test
![Page 19: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/19.jpg)
Ruby Stack
Build - bundler
Test - Minitest, rack-test
Platform - Sinatra
Persistence - mongodb (Ruby official driver)
REST - Sinatra
Deploy - Cloud Foundry (Pivotal Web Services)
![Page 20: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/20.jpg)
Node Stack
![Page 21: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/21.jpg)
Node Stack
Build - npm
Test - mocha, chai
Platform - restify
Persistence - mongodb (official Node.js MongoDB driver)
REST - restify
Deploy - Cloud Foundry (Pivotal Web Services)
![Page 22: DevNexus 2017 - Building and Deploying 12 Factor Apps in Scala, Java, Ruby, and Node.js](https://reader034.fdocuments.us/reader034/viewer/2022042600/58b88fd41a28ab3e3a8b57dd/html5/thumbnails/22.jpg)
Resources
The 12 Factor App - http://12factor.net
Cloud Foundry - https://www.cloudfoundry.org/
Pivotal Web Services - https://run.pivotal.io/