Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RubySG Meetup - gem install natives

37ef5e5ddd4b05465000dbea5d4b22e2?s=47 Huiming Teo
November 19, 2013

RubySG Meetup - gem install natives

Introduce new ruby gem: natives -- list native packages required by gems.

37ef5e5ddd4b05465000dbea5d4b22e2?s=128

Huiming Teo

November 19, 2013
Tweet

Transcript

  1. gem install natives list native packages required by gems

  2. this talk @ RubySG meetup (nov’13) • Problem • A

    possible solution • Stuff I learned • Need helps :)
  3. About me • teo hui ming • work @ favoritemedium.com

    ◦ we design & build ◦ web & mobile apps • @teohm • github.com/teohm • speakerdeck.com/teohm
  4. Problem “Error installing gem capybara-webkit”

  5. Problem • Before bundle install, what native dependencies I need

    to install? ◦ Googling ◦ Stack Overflow ◦ Gem’s README.md, Wiki ◦ App’s README.md, setup.sh ◦ ...
  6. Problem • Do it for dev machine • Do it

    again .. for production server
  7. What if I have.. • a catalog of gem’s native

    packages • machine-readable (easy to automate) • works on both dev & prod environment
  8. Ruby gem: natives gem install natives

  9. natives list mac$ natives list capybara-webkit rmagick qt rmagick ubuntu$

    natives list capybara-webkit rmagick libqtwebkit-dev imagemagick libmagickwand-dev
  10. natives list mac$ brew install \ $(natives list capybara-webkit rmagick)

    ubuntu# sudo apt-get install \ $(natives list capybara-webkit rmagick)
  11. natives list --gemfile $ natives list --gemfile=/app1/Gemfile • First feature

    request (from our colleague, Karthik :) • Needs Gemfile.lock • Uses Bundler::LockfileParser to fetch a list of gems.
  12. natives detect $ natives detect platform: mac_os_x platform_version: 10.7.5 package_provider:

    homebrew • Uses Chef Ohai to detect platform. • Implemented a light-weight package provider detection based on Chef::Platform.
  13. natives catalog: YAML rubygems: capybara-webkit: homebrew: default: - qt apt:

    default: - libqtwebkit-dev ubuntu: [10.04,10.04.1,10.4.2]: - libqt4-dev • Shipped with gem (catalogs/rubygems.yaml) • Merge & overwrite with project-specific catalogs (./natives-catalogs/*.yaml)
  14. natives catalog: general purpose npm: sqlite3: apt: default: - libsqlite3-dev

    yum: default: - sqlite-devel $ natives list \ --catalog npm sqlite3 # can even do this! $ natives list \ --catalog apps app1
  15. natives version $ natives version 0.6.0 • It’s working now,

    but still alpha release • MIT license • Code-review/feedback/pull-request are welcomed! • need LOTS of helps to populate the catalog! :) • https://github.com/teohm/natives
  16. Stuff I learned • Do one thing • Gemfile parsing

    • Catalog format • Catalog testing
  17. Stuff I learned: Do one thing Evolved from: natives install

    capybara-webkit rmagick # run chef-solo with embedded cookbook.. # more responsibilities = more dependencies to: brew install \ $(natives list capybara-webkit rmagick)
  18. Stuff I learned: Gemfile parsing • Tried `bundle show` •

    Tried Bundler.load.specs • Now use Bundler::LockfileParser.new( Bundler.read_file(@lockfile_path))
  19. Stuff I learned: Catalog format • Started from Chef DSL:

    value_for_platform() http://docs.opscode.com/dsl_recipe_method_value_for_platform.html # proof-of-concept rubygems: capybara-webkit: mac_os_x: default: - qt # v0.1.0 rubygems: capybara-webkit: mac_os_x/homebrew: default: - qt # v0.6.0 rubygems: capybara-webkit: homebrew: mac_os_x: default: - qt
  20. Stuff I learned: Catalog testing • Need a testing framework

    to verify entries in catalog: ◦ for each gem in catalogs/rubygems.yaml ▪ launch platform ▪ install native packages (run natives list) ▪ install the gem ▪ SUCCESS if gem installed, otherwise FAILED • Current testing framework (see catalogs_test/): ◦ Vagrant + Docker + GNU Parallel ◦ TODO: try test-kitchen • Inspired by RelateIQ’s docker setup http://blog.relateiq.com/a-docker-dev-environment-in-24-hours-part-2-of-2/
  21. What’s next? • Populate rubygems.yaml catalog ◦ collaboration (pull-request, gdrive

    spreadsheet?) • Improve catalog testing framework
  22. Questions / Feedback? • For new updates, follow @teohm •

    To submit PR, https://github.com/teohm/natives