Successfully reported this slideshow.
Your SlideShare is downloading. ×

Crate - Packaging Standalone Ruby Applications

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 51 Ad

Crate - Packaging Standalone Ruby Applications

Download to read offline

This is the version of my Create talk I gave at Railsconf 2009.

Sometimes the best solution is a standalone application that you can give to a client or customer to just drop on a machine and run. Maybe it is a web service, or a desktop data entry application, or mass deployed background agent, or you have no control of the deployment environment. In any case, there are situations where deploying a full ruby stack may not be an option.

This talk will cover the Crate project and how it may be used to package your application, be it commandline, server, or web application. The end result is a statically built, standalone executable of the ruby interpreter and all dependent binary extensions. The application code, ruby stdlib, dependent gems, and other assets are packed into one or more SQLite databases.

This is the version of my Create talk I gave at Railsconf 2009.

Sometimes the best solution is a standalone application that you can give to a client or customer to just drop on a machine and run. Maybe it is a web service, or a desktop data entry application, or mass deployed background agent, or you have no control of the deployment environment. In any case, there are situations where deploying a full ruby stack may not be an option.

This talk will cover the Crate project and how it may be used to package your application, be it commandline, server, or web application. The end result is a statically built, standalone executable of the ruby interpreter and all dependent binary extensions. The application code, ruby stdlib, dependent gems, and other assets are packed into one or more SQLite databases.

Advertisement
Advertisement

More Related Content

Recently uploaded (20)

Advertisement

Crate - Packaging Standalone Ruby Applications

  1. CRATE Packaging Standalone Ruby Applications Jeremy Hinegardner jeremy@copiousfreetime.org @copiousfreetime
  2. COPIOUS FREE TIME Fedora Ruby Packaging Gems •beanstalkd •amalgalite •haproxy •crate •libtomcrypt •keybox •libtommath •launchy •nginx •heel •ragel •hitimes •tinyproxy •htauth •rabal •stickler
  3. Crate & Amalgalite
  4. SURVEY
  5. PRE HISTORY RubyConf 2007 (Charlotte, NC)
  6. PRE HISTORY RubyConf 2007 (Charlotte, NC) • Sploitin’ with Ruby • Aaron Bedra
  7. PRE HISTORY RubyConf 2007 (Charlotte, NC) • Sploitin’ with Ruby • Aaron Bedra • Deploying Ruby Runtimes • Bruce Williams & Rich Kilmer
  8. STORYTIME
  9. PERL 4, 1993
  10. NO CONTROL
  11. NO CONTROL • interpreters? - perl probably, python maybe, ruby most likely not
  12. NO CONTROL • interpreters? - perl probably, python maybe, ruby most likely not • what libraries? - openssl? zlib?
  13. NO CONTROL • interpreters? - perl probably, python maybe, ruby most likely not • what libraries? - openssl? zlib? • compiler? - quite possibly not
  14. What do you do, when only thing you know about your deployment location, is the Operating System?
  15. AND YOU LOVE RUBY.
  16. YOU MAKE CRATE.
  17. SO WHAT IS CRATE?
  18. embedded Ruby
  19. embedded Ruby + ruby extensions
  20. embedded Ruby + ruby extensions + main wrapper
  21. embedded Ruby + ruby extensions + main wrapper + standard library
  22. embedded Ruby + ruby extensions + main wrapper + standard library + application code
  23. embedded Ruby + ruby extensions + main wrapper + standard library + application code Crate based application
  24. RUBYSCRIPT2EXE ?
  25. http://www.erikveen.dds.nl/rubyscript2exe Ruby Application rubylib exe Extension dlls gems sitelib application.exe eee.exe eee.gz trailer
  26. MY NEEDS
  27. MY NEEDS • Minimally Invasive • do not unpack to a temporary location • small as can be
  28. MY NEEDS • Minimally Invasive • do not unpack to a temporary location • small as can be • Wide deployment capabilities • more than linux, mac, windows, cygwin
  29. embedded Ruby + ruby extensions + main wrapper + standard library + application code Crate based application
  30. embedded Ruby C + ruby extensions + main wrapper + standard library + application code Crate based application
  31. embedded Ruby C + ruby extensions + main wrapper + standard library Ruby + application code Crate based application
  32. Statically Compile embedded Ruby C + ruby extensions + main wrapper + standard library Ruby + application code Crate based application
  33. Statically Compile embedded Ruby C + ruby extensions + main wrapper + standard library Ruby + application code Crate based application Amalgalite
  34. Statically Compile embedded Ruby C + ruby extensions + main wrapper + standard library Ruby + application code Crate based application Pack into Amalgalite
  35. 1 CREATE TABLE rubylibs ( 2       id            INTEGER PRIMARY KEY AUTOINCREMENT, 3       filename      TEXT UNIQUE, 4       compressed    BOOLEAN, 5       contents      BLOB 6       );
  36. Inexact Size Measurements Executable + C Ruby libs extensions Ruby 1.8.6 2.4 M 8.4 M Crate/ruby 1.8.6 2.9 M 1.9 M
  37.  1 module Kernel  2   # alias the original require away to use later  3   alias :amalgalite_original_require :require  4  5   #  6   # hook into the system 'require' to allow for required text or blobs from an  7   # amalgalite database.    8   #  9   def require( filename ) 10     loaded = amalgalite_original_require( filename ) 11   rescue LoadError => load_error 12     if load_error.message =~ /#{Regexp.escape filename}z/ then 13       loaded = Amalgalite::Requires.require( filename ) 14     else 15       raise load_error 16     end 17   end 18 19   private :require 20   private :amalgalite_original_require 21 end
  38. Amalgalite ruby driver is bootstrapped in its C extension
  39. DEMO
  40. BOOTSTRAPPING
  41. ISSUE #1 - AUTOLOAD
  42. ISSUE #1 - AUTOLOAD • Problem • bypasses the require chain setup by amalgalite • used by rack, active_support, active_record
  43. ISSUE #1 - AUTOLOAD • Problem • bypasses the require chain setup by amalgalite • used by rack, active_support, active_record • Solution • Port tree style patches? • custom gem builds?
  44. ISSUE #2 - VIEWS IN WEB FRAMEWORKS
  45. ISSUE #2 - VIEWS IN WEB FRAMEWORKS • Problem • layout and templates loaded from disk
  46. ISSUE #2 - VIEWS IN WEB FRAMEWORKS • Problem • layout and templates loaded from disk • Solution • wait for Rails 3 • sinatra, others, make patches for upstream, if needed.
  47. ISSUE #3 - CLASS RELOADING • Problem • Development mode reloads classes • Solution ( for now ) • production mode when running as crate based apps
  48. ISSUE #4 - NOT WINDOWS FRIENDLY ( YET )
  49. QUESTIONS?

Editor's Notes




  • How many of you have full control over your application deployment?
    How many of your know how many instance of your application there will be?
    Desktop applications?
    IT Shops? distribute small apps to your company for command / control monitoring ?









  • Anyone, in the audience have any ideas?










  • eee is an exractor written in pascal
    eee.gz is ruby + extensions + the application
    trailer at the end.
    mac, windows, linux, cygwin
  • Shooes is pretty cool, and targeted towards gui based applications.
  • I do not want to worry about cleaning up temporary files.

    I want to deployt to Solaris, AIX, HPUX, virtually anywhere ruby can run, I want crate to run.
  • I do not want to worry about cleaning up temporary files.

    I want to deployt to Solaris, AIX, HPUX, virtually anywhere ruby can run, I want crate to run.





  • Create a table to store all the ruby code from the standard library and gems

  • Very similar to how rubygems works.


  • 1. initialize the ruby interpreter
    2. set ARGV for ruby
    3. initialize all statically compiled extensions
    4. bootstrap the Amalgalite driver
    5. remove all filesystem directories from the $LOAD_PATH
    6. switch to using Amalgalite backed require
    7. require the file in the C constant CRATE_MAIN_FILE
    8. instantiate a single instance of the class named in the C constant CRATE_MAIN_CLASS
    9. invoke run( ARGV, ENV) on the newly instantiated class
    10. exit







  • I left out a fair bit of nitty gritty details
    would you like me to expand on anything, show some more code, yell and scream at me,

×