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

KL RubyTuesdays - gem install natives

Huiming Teo
December 03, 2013

KL RubyTuesdays - gem install natives

An introduction to 'natives' gem, and stuff I learned when building it.

Huiming Teo

December 03, 2013
Tweet

More Decks by Huiming Teo

Other Decks in Technology

Transcript

  1. talk @ KL RubyTuesdays #6 (dec’13) • Problem • A

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

    ◦ we design & build ◦ web & mobile apps • @teohm • github.com/teohm • speakerdeck.com/teohm
  3. 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 ◦ ...
  4. Problem • Do it for dev machine • Do it

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

    packages • machine-readable (easy to automate) • works on both dev & prod environment
  6. natives list mac$ natives list capybara-webkit rmagick qt rmagick ubuntu$

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

    ubuntu# sudo apt-get install \ $(natives list capybara-webkit rmagick)
  8. 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.
  9. 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.
  10. 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)
  11. 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
  12. 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
  13. Stuff I learned • Do one thing • Gemfile parsing

    • Catalog format • Catalog testing • Related work
  14. 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)
  15. Stuff I learned: Gemfile parsing • Tried `bundle show` •

    Tried Bundler.load.specs • Now use Bundler::LockfileParser.new( Bundler.read_file(@lockfile_path))
  16. 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
  17. 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/
  18. Questions / Feedback? • For new updates, follow @teohm •

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