• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
[OSDC12]相依性管理 - 以Ruby開發為例
 

[OSDC12]相依性管理 - 以Ruby開發為例

on

  • 4,614 views

 

Statistics

Views

Total Views
4,614
Views on SlideShare
648
Embed Views
3,966

Actions

Likes
2
Downloads
4
Comments
0

13 Embeds 3,966

http://blog.miaout17.net 3893
http://feeds.feedburner.com 26
http://localhost:4000 19
http://meow.miaout17.net 5
http://awww.miaout17.net 4
http://localhost 4
http://webcache.googleusercontent.com 3
http://blog.miaout17.net.s3-website-us-east-1.amazonaws.com 3
http://silverreader.com 2
http://fsadfawww.miaout17.net 2
http://miaout17.net 2
http://127.0.0.1 2
http://www.miaout17.net 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    [OSDC12]相依性管理 - 以Ruby開發為例 [OSDC12]相依性管理 - 以Ruby開發為例 Presentation Transcript

    • 相依性管理 以Ruby開發為例大貓 (@miaout17)
    • About Me• 大貓 (YC Ling, @miaout17)• 2004年因為奇妙的機緣開始學習Ruby – RPG Maker XP – Rails? 能吃嗎?
    • About Me• 大貓 (YC Ling, @miaout17)• 業餘Ruby遊戲開發者(2004~2007)• C++/Lua/ActionScript遊戲開發者(2007~2010)• Java/Ruby Web開發者(2010~now)• 業餘Functional Programming愛好者• Github: https://github.com/miaout17
    • 這場分享• 不是來傳Ruby教的• 沒什麼Ruby程式碼,不會Ruby也能聽懂• 分享我對「高階語言相依性管理」的想法 – Ruby開發流程很方便 – 自Ruby開發流程抽取與語言無關的概念
    • Top 10 Programmer Excuses Google: 2011 COSCUP Lightning Talk 嵌入式開發的故事
    • Top 10 Programmer WTF
    • 相依性!
    • 高階語言開發的相依性 ApplicationsHow can we make Librariesit more smooth? Virtual Machine/Interpreter/Compiler Abstraction! Native Code / LibrariesWrite once, debugrun anywhere OS Hardware
    • High-Level Languages Development in 2012 should…1. 容易安裝、切換執行環境2. 容易安裝函式庫3. 確保所有開發者、部署環境使用相同版本 的函式庫4. 使用版本控制系統,程式化地管理相依性5. 函式庫應使用一致的版號規則描述相容性
    • “Getting Started” Scenario Install environment Clone the project Install project dependencies Run the program Execute unit test TDD
    • 安裝 Ruby Rubies Install environment$ apt-get install ruby$ yum –y install ruby Clone the project Install project• Not always up-to-date dependencies• Always not up-to-date• Multiple Rubies: MRI Execute unit test 1.8.7, 1.9.2, 1.9.3, REE, JRuby, Ru TDD binius, IronRuby, MacRuby, …
    • RVM (Ruby Version Manager)安裝RVM Install environment$ curl -L get.rvm.io | bash -s stable Clone the project安裝Rubies$ rvm install 1.8.7 Install project$ rvm install 1.9.3-p125 dependencies$ rvm install jruby切換不同Rubies Execute unit test$ rvm use 1.8.7$ rvm use 1.9.3 --default TDD See Also: PerlBrew, PythonBrew, PHPBrew…
    • .rvmrc提醒您使用正確的Ruby環境
    • 安裝環境$ rvm install 1.9.3 Install environment Clone the project Install project dependencies Execute unit test TDD
    • 下載專案源始碼 Install environment$ git clone git://github.com/rails/rails.git Clone the project Install project dependencies Execute unit test TDD
    • Library Management in Ruby• 主流工具: Install environment – RubyGems: 管理Ruby套件 – Bundler: 管理Application與Gem的 Clone the project 相依性 Install project dependencies Execute unit test TDD
    • RubyGems安裝gem及其相依的gems$ gem install rails$ gem install rails –v=2.3.5更新gems$ gem update發佈gems$ gem push foo-1.0.0.gem Yes. A lot of languages can do this. See Also: pip, cpan, pear, onion, cabal, npm, maven, ivy…
    • Gemspec
    • Gem 相依性固定版本 Devises.add_dependency ’devise, ‘1.5.0 2.0.0最小版本 Broken! Devises.add_dependency ’devise, ‘>= 1.5.0 1.6.0版本範圍 Library Devises.add_dependency ’devise, ‘>= 1.5’, ‘< 2.0’ Foobar 1.5.0“Twiddle Wakka”s.add_dependency ’devise, ‘~> 1.5’ # ‘>= 1.5’, ‘< 2.0’s.add_dependency ’devise, ‘~> 1.5.1’ # ‘>=1.5.1’, ‘< 1.6’ Just a shortcut?
    • Semantic Versioning• Authored by Tom Preston-Werner, inventor of Gravatars and cofounder of GitHub• 一致的版號規則: Major.Minor.Patch• Rails 3.1.10 – Major version: 3 – Minor version: 1 – Patch version: 10
    • Semantic Versioning• Major version change – 不向下相容 – Ex. Rails 2.3.7 -> 3.0.0• Minor version change – 向下相容,增加新功能 – Ex. Rails 3.0.10 -> 3.1.0• Patch version change – 向下相容,只修正bug – Ex. Rails 3.1.0 -> 3.1.1
    • Semantic Versioning• 例外: Major version 0為早期開發 – 0.0.1, 0.0.2, 0.9.4 什麼都可能不相容• 更多細節請見 http://semver.org/ – Pre-release – Tag name – Semantic versioning v2.0.0-rc1• See also: Apache APR Version Numbering
    • Semantic Versioning • Semantic Version + Twiddle Wakka – 使用一致的版號規則描述相容性 – 簡潔地指定「相容的版本區間」s.add_dependency ’devise, ‘~> 1.5’ # ‘>= 1.5’, ‘< 2.0’s.add_dependency ’devise, ‘~> 1.5.0’ # ‘>=1.5.0’, ‘< 1.6’ • Encouraged by the Ruby community – http://robots.thoughtbot.com/post/2508037841/twiddle-wakka – http://www.slideshare.net/copiousfreetime/gemology – 許多專案Follow此規則
    • 為什麼需要Bundler? Installed Gems Rails Broken! 3.0.0Execute with Rails Sqlite3 Execute with 2.3.7 1.3.3 Bundler Bundler Project Project Alala Devise Wahaha 2.0.0 JSON 1.2.1
    • Gem v.s. Bundler• Gem – 安裝/反安裝/發佈gem – Gemspec管理gem與gem的相依性• Bundler – 管理application與gem的相依性 • 幫你把application需要的gem一次全部裝好 • 確保所有開發者及部署使用相同版本的gem – 題外話:bundler也能拿來開發gem
    • Bundler在Gemfile中設定相依性 See Also: gradle, maven, ivy, sbt, virtualenv, carton
    • Bundler bundle install執行`bundle install`:1. 計算並安裝所需要的gem2. 產生 “Gemfile.lock”
    • Gemfile.lock
    • Bundler Ensure you are using right gems在Shell中執行:$ bunlde exec ruby your_app.rb或是在程式啟始點:require "rubygems"require "bundler/setup"建議:所有的Ruby專案都可以使用Bundler
    • Bundler with git修改Gemfile$ vim Gemfile$ bundle install # or bundle update$ git add Gemfile Gemfile.lock; git commit更新Gems $ bundle update $ git add Gemfile.lock; git commit
    • 安裝相依之函式庫 Install environment Clone the project Install project$ bundle install dependencies Execute unit test TDD
    • 執行單元測試… 使用正確版本的函式庫 Install environment Clone the project Install project dependencies$ bundle exec rake test Execute unit test TDD
    • Wrapping up$ rvm install 1.9.3-p125 Install environment$ git clone git://github.com/rails/rails.git Clone the project$ cd rails Install project dependencies$ bundle install$ bundle exec rake test Execute unit test TDD
    • 結論
    • High-Level Languages Development in 2012 should…1. 容易安裝、切換執行環境2. 容易安裝函式庫3. 確保所有開發者、部署環境使用相同版本 的函式庫4. 使用版本控制系統,程式化地管理相依性5. 函式庫應使用一致的版號規則描述相容性
    • 這些概念與語言無關
    • PHPBrew, Onionhttps://github.com/c9s/phpbrewBrew & manage PHP versions in purePHP at HOMEhttps://github.com/c9s/OnionOnion, The fast approach tobuild/bundle PEAR packages for PHP.
    • CartonCarton is a new command to manage Perlmodule dependencies for your applications.Like gem bundler for Ruby, Carton solves theissue of "upgrading CPAN modules broke mycode" by allowing you to lock and freezedependencies. Carton makes it easy tomanage and reproduce module installationson any environments.
    • 不要走開,接下來是iHower大大精彩的分享「那些Functional Programming教我的事」 Any Question?