12 Factor App: Best Practices for JVM Deployment
-
Upload
joe-kutner -
Category
Engineering
-
view
956 -
download
3
Transcript of 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
“”
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
“”
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
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
Configuration belongs in the environment,
not in the application
Configuration should be strictly separated
from code
| Disposable | Parity | Config |
Environment
Java Application
PATH
DATABASE_URL
AWS_ACCESS_TOKEN
JAVA_OPTS
| Disposable | Parity | Config |
The container is deadLong live the container
DockerHeroku
Docker+Heroku
Application Server
Servlet Container
Host OS
App App App App
Docker Containers
Con
tain
er
Con
tain
er
Con
tain
er
Con
tain
er
Docker Engine
Host OS
App App App App
Docker Containers
Con
tain
er
Con
tain
er
Con
tain
er
Con
tain
er
Docker EngineImage
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 ➤
web: java -cp target/app.jar com.foo.Main
Procfile
https://github.com/jkutner/heroku-java-docker
BOOTABLE
@Configuration@EnableAutoConfiguration@ComponentScanpublic class Main { public static void main(String[] args) { SpringApplication.run(Main.class, args); }}
CONTAINERL
ESS
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(); }}
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 ...
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
| 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