84
12 Factor App Best Practices for JRuby Deployment

12-factor-jruby

Embed Size (px)

Citation preview

12 Factor AppBest Practices for JRuby Deployment

Joe Kutner@codefinger

JVM Platform Owner@Heroku

Joe Kutner

deployment, deployment, deployment, deployment

This book is wrong now!

.war

Traditional Deployment

.jar

Modern Deployment

Make JAR

Not WAR

2005 2015

WAR files JAR files

App Servers Microservices

Hot Deploy Continuous Deploy

Server in a closet Heroku/AWS/etc

12 Factor Appa methodology

ScalabilityMaintainability

Portability

• Immutable• Ephemeral• Declarative• Automated

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Thank You!Goodbye!

(just kidding)

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Use Version Control

BAD

BAD

App #1 App #2

Submodules

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Never rely on implicit existence of system-wide

packages

Explicitly declare and isolate

dependencies

Don’t check JAR files into Git

JBundler

Jarfile

jar 'org.yaml:snakeyaml'jar 'org.slf4j:slf4j-simple', '>1.1'

$ gem install jbundler...

$ jbundle install...

$ jbundle console...

server.rb

require 'jbundler'

java_import 'org.slf4j.Logger'

$ jbundle install --vendor...

$ tree vendor/jars/vendor/jars/!"" io#   $"" netty#   $"" netty-all#   $"" 4.0.28.Final#   $"" netty-all-4.0.28.Final.jar$"" jbundler.rb

4 directories, 2 files

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

• 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 config/routes.rb)

Configuration is…

Configuration should be strictly separated

from code

Don’t check passwords into Git

Can you make your app open source at any moment, without compromising

any credentials?

Litmus Test

Configuration belongs in the environment,

not in the application

database.yml

dev: username: everyone password: 1234567 …

test: username: everyone password: 1234567 …

production: username: admin password: 89haiusdf90fasd ...

BAD

database.yml

production: url: <%= ENV['DATABASE_URL']%>

GOOD

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

database.yml

production: url: <%= ENV['DATABASE_URL']%>

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

build, release, run

$ jrubyc ...

$ rake assets:precompile

$ warble executable war

$ ./gradlew build

build

$ heroku deploy:jar -j myapp.war

$ mvn heroku:deploy

$ scp myapp.war prod-server:~

$ docker push ...

release

$ java -jar myapp.war

$ bundle exec puma ...

run

$ /var/tomcat/start.sh

$ service tomcat start

$ torquebox start

$ git push heroku masterbuild,

release,& run

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

DEMO!

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Processes should be stateless

sticky sessions 😞

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

The twelve-factor app is completely self-contained

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

.war

Traditional Deployment

.jar

Modern Deployment

Dropwizard

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

GIL

RELAX BRO, I GOT THIS…

Scale Up

Scale Out

web.1

web.2

worker.1 clock.1

Workload Diversity

Num

ber o

f Pro

cess

es

worker.2

worker.3

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Graceful shutdown

Quick startup

Resilience to failure

Servers are not pets

Servers are cattle

Application Servers are not disposable

Microservices are disposable

Easy to replace

Decoupled from external infrastructure

Easy to modify

Microservices

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

dev

sqlite

postgres

stage

mysql

postgres

prod

postgres

postgres

=

=

=

=

dev

webrick

puma

stage

puma

puma

prod

unicorn

puma

=

=

=

=

disposable

⇒reproducible

parity⇒

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

Admin tasks should be run in isolated processes

$ heroku run jirbRunning `rails console` attached to terminal... up, run.1594Loading production environment (Rails 4.1.4)irb(main):001:0>

web1

web2

web3

admin

The 12 Factors• Codebase

• Dependencies

• Config

• Backing services

• Build, release, run

• Processes

• Port binding

• Concurrency

• Disposability

• Dev/prod parity

• Logs

• Admin processes

http://12factor.net

http://jkutner.github.io

warble executable war1.

gem install jbundle2.

Remove all passwords3.

Kill your app. Then restart it. Time it.4.

What next?

Joe Kutner@codefinger

JVM Platform Owner@Heroku

http://www.slideshare.net/jkutner/12-factor-jruby