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-jruby

687 views

Published on

12 Factor App: Best Practices for JRuby Deployment

Published in: Technology
  • Be the first to comment

12-factor-jruby

  1. 1. 12 Factor App Best Practices for JRuby Deployment
  2. 2. Joe Kutner @codefinger JVM Platform Owner @Heroku Joe Kutner
  3. 3. deployment, deployment, deployment, deployment
  4. 4. This book is wrong now!
  5. 5. .war Traditional Deployment
  6. 6. .jar Modern Deployment
  7. 7. Make JAR Not WAR
  8. 8. 2005 2015 WAR files JAR files App Servers Microservices Hot Deploy Continuous Deploy Server in a closet Heroku/AWS/etc
  9. 9. 12 Factor App a methodology Scalability Maintainability Portability
  10. 10. • Immutable • Ephemeral • Declarative • Automated
  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. Thank You! Goodbye! (just kidding)
  13. 13. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  14. 14. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  15. 15. Use Version Control
  16. 16. BAD
  17. 17. BAD App #1 App #2
  18. 18. Submodules
  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. Never rely on implicit existence of system-wide packages Explicitly declare and isolate dependencies
  21. 21. Don’t check JAR files into Git
  22. 22. JBundler
  23. 23. Jarfile jar 'org.yaml:snakeyaml' jar 'org.slf4j:slf4j-simple', '>1.1'
  24. 24. $ gem install jbundler ... $ jbundle install ... $ jbundle console ...
  25. 25. server.rb require 'jbundler' java_import 'org.slf4j.Logger'
  26. 26. $ 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
  27. 27. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  28. 28. • 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…
  29. 29. Configuration should be strictly separated from code
  30. 30. Don’t check passwords into Git
  31. 31. Can you make your app open source at any moment, without compromising any credentials? Litmus Test
  32. 32. Configuration belongs in the environment, not in the application
  33. 33. database.yml dev: username: everyone password: 1234567 … test: username: everyone password: 1234567 … production: username: admin password: 89haiusdf90fasd ... BAD
  34. 34. database.yml production: url: <%= ENV['DATABASE_URL']%> GOOD
  35. 35. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  36. 36. database.yml production: url: <%= ENV['DATABASE_URL']%>
  37. 37. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  38. 38. build, release, run
  39. 39. $ jrubyc ... $ rake assets:precompile $ warble executable war $ ./gradlew build build
  40. 40. $ heroku deploy:jar -j myapp.war $ mvn heroku:deploy $ scp myapp.war prod-server:~ $ docker push ... release
  41. 41. $ java -jar myapp.war $ bundle exec puma ... run $ /var/tomcat/start.sh $ service tomcat start $ torquebox start
  42. 42. $ git push heroku master build, release, & run
  43. 43. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  44. 44. DEMO!
  45. 45. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  46. 46. Processes should be stateless
  47. 47. sticky sessions 😞
  48. 48. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  49. 49. The twelve-factor app is completely self-contained The web app exports HTTP as a service by binding to a port
  50. 50. .war Traditional Deployment
  51. 51. .jar Modern Deployment
  52. 52. Dropwizard
  53. 53. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  54. 54. GIL RELAX BRO, I GOT THIS…
  55. 55. Scale Up Scale Out
  56. 56. web.1 web.2 worker.1 clock.1 Workload Diversity NumberofProcesses worker.2 worker.3
  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. Graceful shutdown Quick startup Resilience to failure
  59. 59. Servers are not pets Servers are cattle
  60. 60. Application Servers are not disposable
  61. 61. Microservices are disposable
  62. 62. Easy to replace Decoupled from external infrastructure Easy to modify
  63. 63. Microservices
  64. 64. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  65. 65. dev sqlite postgres stage mysql postgres prod postgres postgres = ≠ = = ≠ =
  66. 66. dev webrick puma stage puma puma prod unicorn puma = ≠ = = ≠ =
  67. 67. disposable reproducible parity
  68. 68. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  69. 69. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  70. 70. Admin tasks should be run in isolated processes
  71. 71. $ heroku run jirb Running `rails console` attached to terminal... up, run.1594 Loading production environment (Rails 4.1.4) irb(main):001:0>
  72. 72. web1 web2 web3 admin
  73. 73. The 12 Factors • Codebase • Dependencies • Config • Backing services • Build, release, run • Processes • Port binding • Concurrency • Disposability • Dev/prod parity • Logs • Admin processes
  74. 74. http://12factor.net http://jkutner.github.io
  75. 75. warble executable war1. gem install jbundle2. Remove all passwords3. Kill your app. Then restart it. Time it.4. What next?
  76. 76. Joe Kutner @codefinger JVM Platform Owner @Heroku http://www.slideshare.net/jkutner/12-factor-jruby

×