Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

12 Factor App: Best Practices for JVM Deployment

10,063 views

Published on

Twelve Factor apps are built for agility and rapid deployment. They enable continuous delivery and reduce the time and cost for new developers to join a project. At the same time, they are architected to exploit the principles of modern cloud platforms while permitting maximum portability between them. Finally, they can scale up without significant changes to tooling, architecture or development practices. In this talk, you’ll learn the principles and best practices espoused by the Twelve Factor app. We’ll discuss how to structure your code, manage dependencies, store configuration, run admin tasks, capture log files, and more. You’ll learn how modern Java deployments can benefit

Published in: Engineering
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

12 Factor App: Best Practices for JVM Deployment

  1. 1. 12 Factor App Best Practices for JVM Deployment
  2. 2. 12 Factor App Best Practices for JVM Deployment Java doesn’t suck when you do things this way
  3. 3. 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 “ ”
  4. 4. 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 “ ”
  5. 5. .war Traditional JVM Deployment
  6. 6. .war Modern JVM Deployment
  7. 7. Java Doesn’t Suck
  8. 8. 12 Factor App
  9. 9. Joe Kutner @codefinger JVM Langs Owner @Heroku Joe Kutner
  10. 10. 12 Factor App a methodology Scalability Maintainability Portability
  11. 11. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  12. 12. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  13. 13. Graceful shutdown Quick startup Resilience to failure | Disposability |
  14. 14. Application Servers…
 | Disposability |
  15. 15. Application Servers are not disposable | Disposability |
  16. 16. | Disposability | Microservices are disposable
  17. 17. | Disposability | Microservices Java Groovy Scala Clojure Scala Scala
  18. 18. Bootable ➤ Disposable | Disposability |
  19. 19. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  20. 20. dev sqlite postgres stage mysql postgres prod postgres postgres = ≠ = = ≠ = | Disposable | Parity |
  21. 21. dev files files stage files files prod war files = ≠ = = ≠ = | Disposable | Parity |
  22. 22. dev jetty jetty stage tomcat jetty prod jboss jetty = ≠ = = ≠ = | Disposable | Parity |
  23. 23. | Disposable | Parity | dev jetty {} stage tomcat {} prod jboss {} = ≠ = = ≠ =
  24. 24. .war Traditional JVM Deployment
  25. 25. .jar Modern JVM Deployment
  26. 26. Reproducible ➤ Parity | Disposable | Parity |
  27. 27. Reproducible ➤ Disposable | Disposable | Parity |
  28. 28. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  29. 29. Configuration belongs in the environment, not in the application Configuration should be strictly separated from code | Disposable | Parity | Config |
  30. 30. Linux Tomcat WAR server.xml context.xml web.xml /etc/... | Disposable | Parity | Config |
  31. 31. Environment Java Application PATH DATABASE_URL AWS_ACCESS_TOKEN JAVA_OPTS | Disposable | Parity | Config |
  32. 32. Containerless ➤ Separation | Disposable | Parity | Config |
  33. 33. Containerless ➤ Parity | Disposable | Parity | Config |
  34. 34. Containerless ➤ Disposable | Disposable | Parity | Config |
  35. 35. Containerless ➤ 12 Factor App | Disposable | Parity | Config |
  36. 36. Containerless Containerless Containerless | Disposable | Parity | Config |
  37. 37. The container is dead Long live the container Docker Heroku Docker+Heroku Application Server Servlet Container
  38. 38. Docker
  39. 39. Host OS GuestOS App GuestOS App Traditional Virtualization Hypervisor
  40. 40. Host OS App App App App Docker Containers Container Container Container Container Docker Engine
  41. 41. App App App App Host OS Dyno Dyno Dyno Dyno Heroku Dynos Heroku
  42. 42. App App App App Host OS Dyno Dyno Dyno Dyno Heroku Dynos HerokuSlug
  43. 43. Host OS App App App App Docker Containers Container Container Container Container Docker EngineImage
  44. 44. Dockerize!
  45. 45. 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 REPRODUCIBLE Base Image ➤ Install Java ➤ Run App ➤
  46. 46. web: java -cp target/app.jar com.foo.Main Procfile https://github.com/jkutner/heroku-java-docker BOOTABLE
  47. 47. @Configuration @EnableAutoConfiguration @ComponentScan public class Main { public static void main(String[] args) { SpringApplication.run(Main.class, args); } } CONTAINERLESS
  48. 48. 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(); } }
  49. 49. (defn -main [& [port]] (jetty/run-jetty (site #'app) {:port port :join? false}))
  50. 50. // Play example does not require any code
  51. 51. Dropwizard
  52. 52. Demo…
  53. 53. Host OS Docker EngineImage $ docker build ...
  54. 54. Host OS Docker EngineImage App Container $ docker run ... $ docker build ...
  55. 55. Host OS App Container Docker EngineImage App Container App App Container Container $ docker run ... $ docker build ... $ docker run ...
  56. 56. Host OS Docker Engine $ docker run ... $ docker build ... $ docker run ...
  57. 57. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  58. 58. | Disposable | Parity | Config | Admin | Admin tasks should be run in isolated processes
  59. 59. web1 web2 web3 admin | Disposable | Parity | Config | Admin |
  60. 60. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  61. 61. | Disposable | Parity | Config | Admin | Concurrency | Scale Up AND Scale Out
  62. 62. | Disposable | Parity | Config | Admin | Concurrency | web.1 web.2 worker.1 clock.1 Workload Diversity NumberofProcesses worker.2 worker.3
  63. 63. TAKE AWAYS!
  64. 64. • Install the JDK • Clone the SCM repo • Run the app 1) Three Steps to Setup
  65. 65. • Get a stopwatch • Time your app’s startup • Get it under 30 seconds 2) Make Startup Quick
  66. 66. • Provision a new environment, 
 deploy the app,
 handle requests 3) Deploy in One Step
  67. 67. http://12factor.net
  68. 68. Joe Kutner @codefinger JVM Languages Owner @Heroku

×