• No results found

12 Factor App. Best Practices for Scala Deployment

N/A
N/A
Protected

Academic year: 2021

Share "12 Factor App. Best Practices for Scala Deployment"

Copied!
83
0
0

Loading.... (view fulltext now)

Full text

(1)

12

Factor App

(2)

2005

2015

WAR files

JAR files

App Servers

Microservices

Java

Scala

(3)

Joe Kutner

@codefinger

JVM Platform Owner @Heroku

(4)

12

Factor App

a methodology

Scalability

Maintainability

(5)

Immutable

Ephemeral

Declarative

(6)
(7)

addSbtPlugin(

"com.typesafe.sbt" % "sbt-native-packager" % "0.7.6"

)

(8)
(9)
(10)

The

12

Factors

• Codebase

• Dependencies • Config

• Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(11)

Thank You! Goodbye! (just kidding)

(12)

The

12

Factors

• Codebase

• Dependencies • Config

• Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(13)

The

12

Factors

• Codebase

• Dependencies • Config

• Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(14)
(15)
(16)
(17)
(18)

BAD

(19)

my-project ! build.sbt ! app ! conf ! public ! my-library ! build.sbt ! src ! main ! scala

(20)

my-project ! build.sbt ! app ! conf ! public ! my-library ! my-sub-project ! build.sbt ! src ! main ! scala BAD

(21)
(22)
(23)

The

12

Factors

• Codebase

• Dependencies

• Config

• Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(24)
(25)
(26)

Never rely on implicit existence of system-wide

packages Explicitly declare

and isolate dependencies

(27)

global local BAD GOOD

Dependencies

~/.m2 ~/.ivy2 (ok in dev) target/
(28)

Vendoring

(29)

$ sbt stage ... $ tree target/universal/stage/lib/ target/universal/stage/lib/ "## ch.qos.logback.logback-classic-1.1.1.jar "## ch.qos.logback.logback-core-1.1.1.jar "## com.fasterxml.jackson.core.jackson-annotations-2.3... "## com.fasterxml.jackson.core.jackson-core-2.3.2.jar "## com.fasterxml.jackson.core.jackson-databind-2.3.2.jar "## com.google.guava.guava-16.0.1.jar ...

(30)

The

12

Factors

• Codebase

• Dependencies

• Config

• Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(31)
(32)

Or was it “DUH”?

(33)

Can you make your app open source

at any moment, without compromising any credentials?

(34)

• Resource handles to the database,

Memcached, and other backing services • Credentials to external services such as

Amazon S3 or Twitter

• Per-deploy values such as the canonical hostname for the deploy

Anything that changes between deployment environments:

(does not include things like conf/routes)

(35)

Configuration belongs in the environment,

not in the application Configuration should

be strictly separated

(36)

db.default.url=${DATABASE_URL}

(37)

The

12

Factors

• Codebase

• Dependencies • Config

• Backing services

• Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(38)

db.default.url=${DATABASE_URL}

(39)

The

12

Factors

• Codebase

• Dependencies • Config

• Backing services

• Build, release, run

• Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(40)
(41)

$ sbt stage ... $ sbt deployHeroku ... # in the cloud! $ target/universal/stage/bin/my-app build release run

(42)

$ sbt run

BAD

(43)
(44)

The

12

Factors

• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(45)
(46)

$ sbt stage ... $ sbt deployHeroku ... # in the cloud! $ target/universal/stage/bin/scaladays build release run

(47)

The

12

Factors

• Codebase

• Dependencies • Config

• Backing services • Build, release, run

• Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(48)
(49)

sticky sessions 😞

(50)

The

12

Factors

• Codebase

• Dependencies • Config

• Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(51)

The twelve-factor app

is completely self-contained

The web app exports HTTP as a service by binding to a port

(52)

.war

(53)

.jar

(54)

The

12

Factors

• Codebase

• Dependencies • Config

• Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(55)

Actors

Futures

Agents

(56)

Scale Up

(57)

web.1 web.2 worker.1 clock.1 Workload Diversity Number of Pr ocesses worker.2 worker.3

(58)

The

12

Factors

• Codebase

• Dependencies • Config

• Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(59)

Graceful shutdown Quick startup

(60)

Servers are not pets

(61)

Application Servers are not disposable

(62)

Microservices are disposable

(63)

Easy to replace

Decoupled from

external infrastructure Easy to modify

(64)
(65)

The

12

Factors

• Codebase

• Dependencies • Config

• Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(66)

dev

sqlite

postgres

stage

mysql

postgres

prod

postgres

postgres

=

=

=

=

(67)

dev

jetty

jetty

stage

tomcat

jetty

prod

jboss

jetty

=

=

=

=

(68)

dev

jetty

{}

stage

tomcat

{}

prod

jboss

{}

=

=

=

=

(69)
(70)

disposable

reproducible

(71)

The

12

Factors

• Codebase

• Dependencies • Config

• Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(72)

The

12

Factors

• Codebase

• Dependencies • Config

• Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(73)

Admin tasks should be run in isolated processes

(74)

$ heroku run console

Running `console` attached to terminal... up, run.2581

Picked up JAVA_TOOL_OPTIONS: -Djava.rmi.server.useCode... Failed to created JLineReader: java.lang.NoClassDefFou... Falling back to SimpleReader.

Welcome to Scala version 2.11.1 (OpenJDK 64-Bit Server... Type in expressions to have them evaluated.

Type :help for more information. scala>

(75)

web1

web2

web3

(76)

$ heroku run sbt console

(77)
(78)

addSbtPlugin(

"com.typesafe.sbt" % "sbt-native-packager" % "0.7.6"

)

(79)

console: target/universal/stage/bin/my-app \ -main scala.tools.nsc.MainGenericRunner \ -usejavacp Procfile worker: target/universal/stage/bin/my-app \ -main com.example.MyWorker

(80)

The

12

Factors

• Codebase

• Dependencies • Config

• Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes

(81)

http://

12

factor

.

net

(82)

Add sbt-native-packager 1. Run `sbt stage` 2. Deploy to Heroku? 3.

Go to the sbt-native-packager talk

4.

(83)

Joe Kutner

@codefinger

JVM Platform Owner @Heroku

http://12

References

Related documents

It is the (education that will empower biology graduates for the application of biology knowledge and skills acquired in solving the problem of unemployment for oneself and others

Demographic change on its own creates growth opportunities in pension saving, investment management, corporate longevity de-risking, housing and real assets. Ageing populations

This section outlines the method to find the best allocation of n distinguishable processors to m dis- tinguishable blocks so as to minimize the execution time.. Therefore,

No.3 IP Fixed Mobile All-IP based FMC Single Platform Box Module Site or Central Office One Cabinet One Site 9KW 3×3KW Smart modularized power management 2KW

16 iSCSI PDU ● PDU (Protocol Data Unit):  The initiator and target divide  their communications into  messages. The term "iSCSI 

Other ways that equality and diversity has been promoted in the college to raise awareness included College events to celebrate success and achievement such as Supported

The Department of Health, Physical Education, Recreation and Dance offers a Master of Science in Education in Health and Physical Education and a Master of Science in

We are now using the second part of our test database (see Figure 4 ) ; the boxpoints table which contains 3000 customer points, and the box table with 51 dierent sized bounding