$30 off During Our Annual Pro Sale. View Details »

如何透過 Warbler 在 JVM 上部署 Rails 應用

Jason Lee
September 11, 2015

如何透過 Warbler 在 JVM 上部署 Rails 應用

Jason Lee

September 11, 2015
Tweet

Other Decks in Technology

Transcript

  1. 如何透過 Warbler 在 JVM 上部署 Rails 應⽤用
    Jason Lee (LeeChSien)
    [email protected]
    2015 / 09 / 11

    View Slide

  2. 關於我
    • 李致賢 (Jason Lee) a.k.a LeeChSien
    • 即將畢業於政治⼤大學 (NCCU CS Master)
    • as a Ruby Developer since 2012
    • Web Developer in

    View Slide

  3. 想⽤用 Ruby / Rails 來開發產品, 但是...

    View Slide

  4. 客⼾戶的環境
    你想像中

    View Slide

  5. 客⼾戶的環境
    實際的情形

    View Slide

  6. 客⼾戶的環境
    • 環境沒有 Ruby Runtime
    • 產品需要封裝 (保護 Source Code)
    • Windows Only….

    View Slide

  7. Charles Nutter @ Taipei (2014/04/29)

    View Slide

  8. 嘗試使⽤用 JRuby ?

    View Slide

  9. JRuby
    Write once, run anywhere

    View Slide

  10. JRuby

    View Slide

  11. 如何使⽤用 JRuby 開發?

    View Slide

  12. JRuby 版本⽐比較
    JRuby 1.7.0 Ruby 1.9.3
    JRuby 1.7.4 Ruby 2.0
    JRuby 9.0.0.0 Ruby 2.2

    View Slide

  13. 使⽤用相容的 Gems
    • For example:activerecord-jdbc-adapter

    View Slide

  14. Migrate from MRI Rails 4.2
    • byebug -> disable
    • web-console -> disable
    • binding_of_caller
    • therubyracer -> therubyrhino

    View Slide

  15. C Extension Alternatives
    • Nokogiri - pure java version
    • RMagick - RMagick4J
    • therubyracer - therubyrhino
    JRuby Wiki:C-Extension-Alternatives

    View Slide

  16. Thread-safety
    • Rails 本⾝身是 Thread-safe
    • 第三⽅方 Gems 必須是 Thread-safe
    • Sidekiq Wiki:Problems-and-Troubleshooting#threading
    • 你的程式碼必須是 Thread-safe

    View Slide

  17. Thread-safety
    • Global variables
    • Class variables
    • Class instance variables

    View Slide

  18. Race condition

    View Slide

  19. View Slide

  20. Memoization

    View Slide

  21. View Slide

  22. View Slide

  23. Mutex Lock

    View Slide

  24. View Slide

  25. Archive Your App with Warbler

    View Slide

  26. Warbler
    • Warbler 將你的 App 打包為可執⾏行的 .war files
    https://github.com/jruby/warbler
    • Start Server?
    • Rake task?

    View Slide

  27. Warbler
    • Configuration
    • warble.rb
    • web.xml.erb
    Warbler 1.4.X JRuby 1.7.X
    Warbler 2.0.0 rc JRuby 9.0.0.0

    View Slide

  28. Compile .rb to .class
    warble.rb

    View Slide

  29. Compile .rb to .class

    View Slide

  30. JRuby-rack-worker
    web.xml.erb
    https://github.com/kares/jruby-rack-worker

    View Slide

  31. Unlimited Strength Crypto
    • Install the "Unlimited Strength" policy files from
    Oracle
    • Disable the crypto restriction programmatically
    JRuby Wiki:UnlimitedStrengthCrypto

    View Slide

  32. Tzinfo-data
    • No timezone data source could be found.

    To resolve this, either install TZInfo::Data

    View Slide

  33. Demo
    https://github.com/LeeChSien/rails-warbler-boilerplate

    View Slide

  34. Another Choice - TorqueBox

    View Slide

  35. Thank you!

    View Slide