12 factor app: best practices for jvm deployment

69
12 Factor App Best Practices for JVM Deployment

Upload: joe-kutner

Post on 21-Apr-2017

7.431 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: 12 Factor App: Best Practices for JVM Deployment

12 Factor AppBest Practices for JVM Deployment

Page 2: 12 Factor App: Best Practices for JVM Deployment

12 Factor AppBest Practices for JVM Deployment

Java doesn’t suck when you do things this way

Page 3: 12 Factor App: Best Practices for JVM Deployment
Page 4: 12 Factor App: Best Practices for JVM Deployment

Java Servlet API 2.2 includes one new feature so significant it may change the way the Web works. That feature: Web applications.

- Javaworld.com, 1999

“”

Page 5: 12 Factor App: Best Practices for JVM Deployment

With Web apps, the entire application can be contained in a single archive file and deployed by placing the file into a specific directory.

- Javaworld.com, 1999

“”

Page 6: 12 Factor App: Best Practices for JVM Deployment

.war

Traditional JVM Deployment

Page 7: 12 Factor App: Best Practices for JVM Deployment

.war

Modern JVM Deployment

Page 8: 12 Factor App: Best Practices for JVM Deployment

JavaDoesn’t

Suck

Page 9: 12 Factor App: Best Practices for JVM Deployment

12 Factor App

Page 10: 12 Factor App: Best Practices for JVM Deployment

Joe Kutner@codefinger

JVM Langs Owner@Heroku

Joe Kutner

Page 11: 12 Factor App: Best Practices for JVM Deployment

12 Factor Appa methodology

ScalabilityMaintainability

Portability

Page 12: 12 Factor App: Best Practices for JVM Deployment

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Page 13: 12 Factor App: Best Practices for JVM Deployment

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Page 14: 12 Factor App: Best Practices for JVM Deployment

Graceful shutdown

Quick startup

Resilience to failure

| Disposability |

Page 15: 12 Factor App: Best Practices for JVM Deployment

Application Servers…

| Disposability |

Page 16: 12 Factor App: Best Practices for JVM Deployment

Application Servers are not disposable

| Disposability |

Page 17: 12 Factor App: Best Practices for JVM Deployment

| Disposability |

Microservices are disposable

Page 18: 12 Factor App: Best Practices for JVM Deployment

| Disposability |

Microservices

JavaGroovy

ScalaClojure

Scala Scala

Page 19: 12 Factor App: Best Practices for JVM Deployment

Bootable ➤ Disposable

| Disposability |

Page 20: 12 Factor App: Best Practices for JVM Deployment

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Page 21: 12 Factor App: Best Practices for JVM Deployment

dev

sqlite

postgres

stage

mysql

postgres

prod

postgres

postgres

=

=

=

=

| Disposable | Parity |

Page 22: 12 Factor App: Best Practices for JVM Deployment

dev

files

files

stage

files

files

prod

war

files

=

=

=

=

| Disposable | Parity |

Page 23: 12 Factor App: Best Practices for JVM Deployment

dev

jetty

jetty

stage

tomcat

jetty

prod

jboss

jetty

=

=

=

=

| Disposable | Parity |

Page 24: 12 Factor App: Best Practices for JVM Deployment

| Disposable | Parity |

dev

jetty

{}

stage

tomcat

{}

prod

jboss

{}

=

=

=

=

Page 25: 12 Factor App: Best Practices for JVM Deployment

.war

Traditional JVM Deployment

Page 26: 12 Factor App: Best Practices for JVM Deployment

.jar

Modern JVM Deployment

Page 27: 12 Factor App: Best Practices for JVM Deployment

Reproducible ➤ Parity

| Disposable | Parity |

Page 28: 12 Factor App: Best Practices for JVM Deployment

Reproducible ➤ Disposable

| Disposable | Parity |

Page 29: 12 Factor App: Best Practices for JVM Deployment

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Page 30: 12 Factor App: Best Practices for JVM Deployment

Configuration belongs in the environment,

not in the application

Configuration should be strictly separated

from code

| Disposable | Parity | Config |

Page 31: 12 Factor App: Best Practices for JVM Deployment

Linux

Tomcat

WAR

server.xml

context.xml

web.xml

/etc/...

| Disposable | Parity | Config |

Page 32: 12 Factor App: Best Practices for JVM Deployment

Environment

Java Application

PATH

DATABASE_URL

AWS_ACCESS_TOKEN

JAVA_OPTS

| Disposable | Parity | Config |

Page 33: 12 Factor App: Best Practices for JVM Deployment

Containerless ➤ Separation

| Disposable | Parity | Config |

Page 34: 12 Factor App: Best Practices for JVM Deployment

Containerless ➤ Parity

| Disposable | Parity | Config |

Page 35: 12 Factor App: Best Practices for JVM Deployment

Containerless ➤ Disposable

| Disposable | Parity | Config |

Page 36: 12 Factor App: Best Practices for JVM Deployment

Containerless ➤ 12 Factor App

| Disposable | Parity | Config |

Page 37: 12 Factor App: Best Practices for JVM Deployment

Containerless Containerless Containerless

| Disposable | Parity | Config |

Page 38: 12 Factor App: Best Practices for JVM Deployment

The container is deadLong live the container

DockerHeroku

Docker+Heroku

Application Server

Servlet Container

Page 39: 12 Factor App: Best Practices for JVM Deployment

Docker

Page 40: 12 Factor App: Best Practices for JVM Deployment

Host OS

Gue

st O

S

App

Gue

st O

S

App

Traditional Virtualization

Hypervisor

Page 41: 12 Factor App: Best Practices for JVM Deployment

Host OS

App App App App

Docker Containers

Con

tain

er

Con

tain

er

Con

tain

er

Con

tain

er

Docker Engine

Page 42: 12 Factor App: Best Practices for JVM Deployment

App App App App

Host OS

Dyn

o

Dyn

o

Dyn

o

Dyn

o

Heroku Dynos

Heroku

Page 43: 12 Factor App: Best Practices for JVM Deployment

App App App App

Host OS

Dyn

o

Dyn

o

Dyn

o

Dyn

o

Heroku Dynos

HerokuSlug

Page 44: 12 Factor App: Best Practices for JVM Deployment

Host OS

App App App App

Docker Containers

Con

tain

er

Con

tain

er

Con

tain

er

Con

tain

er

Docker EngineImage

Page 45: 12 Factor App: Best Practices for JVM Deployment

Dockerize!

Page 46: 12 Factor App: Best Practices for JVM Deployment

FROM heroku/cedar:14

...

RUN /opt/heroku/bin/setup.sh /opt/heroku

...

ENTRYPOINT /opt/heroku/bin/run.sh

Dockerfile

https://github.com/jkutner/heroku-java-docker

REPRODUCIB

LE

Base Image ➤

InstallJava

Run App ➤

Page 47: 12 Factor App: Best Practices for JVM Deployment

web: java -cp target/app.jar com.foo.Main

Procfile

https://github.com/jkutner/heroku-java-docker

BOOTABLE

Page 48: 12 Factor App: Best Practices for JVM Deployment

@Configuration@EnableAutoConfiguration@ComponentScanpublic class Main { public static void main(String[] args) { SpringApplication.run(Main.class, args); }}

CONTAINERL

ESS

Page 49: 12 Factor App: Best Practices for JVM Deployment

import org.eclipse.jetty.server.Server;import org.eclipse.jetty.servlet.*;

public class Main { public static void main(String[] args) throws Exception { Server server = new Server(); ServletContextHandler context = new ServletContextHandler( ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); context.addServlet(new ServletHolder(new App()), "/*"); server.start(); server.join(); }}

Page 50: 12 Factor App: Best Practices for JVM Deployment

(defn -main [& [port]] (jetty/run-jetty (site #'app) {:port port :join? false}))

Page 51: 12 Factor App: Best Practices for JVM Deployment

// Play example does not require any code

Page 52: 12 Factor App: Best Practices for JVM Deployment

Dropwizard

Page 53: 12 Factor App: Best Practices for JVM Deployment

Demo…

Page 54: 12 Factor App: Best Practices for JVM Deployment

Host OS

Docker EngineImage

$ docker build ...

Page 55: 12 Factor App: Best Practices for JVM Deployment

Host OS

Docker EngineImage

App

Con

tain

er

$ docker run ...$ docker build ...

Page 56: 12 Factor App: Best Practices for JVM Deployment

Host OS

App

Con

tain

er

Docker EngineImage

App

Con

tain

er

App App

Con

tain

er

Con

tain

er

$ docker run ...$ docker build ...

$ docker run ...

Page 57: 12 Factor App: Best Practices for JVM Deployment

Host OS

Docker Engine

$ docker run ...$ docker build ...

$ docker run ...

Page 58: 12 Factor App: Best Practices for JVM Deployment

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Page 59: 12 Factor App: Best Practices for JVM Deployment

| Disposable | Parity | Config | Admin |

Admin tasks should be run in isolated processes

Page 60: 12 Factor App: Best Practices for JVM Deployment

web1

web2

web3

admin

| Disposable | Parity | Config | Admin |

Page 61: 12 Factor App: Best Practices for JVM Deployment

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Page 62: 12 Factor App: Best Practices for JVM Deployment

| Disposable | Parity | Config | Admin | Concurrency |

Scale UpAND

Scale Out

Page 63: 12 Factor App: Best Practices for JVM Deployment

| Disposable | Parity | Config | Admin | Concurrency |

web.1

web.2

worker.1 clock.1

Workload Diversity

Num

ber o

f Pro

cess

es

worker.2

worker.3

Page 64: 12 Factor App: Best Practices for JVM Deployment

TAKE AWAYS!

Page 65: 12 Factor App: Best Practices for JVM Deployment

• Install the JDK• Clone the SCM repo• Run the app

1) Three Steps to Setup

Page 66: 12 Factor App: Best Practices for JVM Deployment

• Get a stopwatch• Time your app’s startup• Get it under 30 seconds

2) Make Startup Quick

Page 67: 12 Factor App: Best Practices for JVM Deployment

• Provision a new environment, deploy the app,handle requests

3) Deploy in One Step

Page 68: 12 Factor App: Best Practices for JVM Deployment

http://12factor.net

Page 69: 12 Factor App: Best Practices for JVM Deployment

Joe Kutner@codefinger

JVM Languages Owner@Heroku