Slide 1

Slide 1 text

how does bundler work, anyway?

Slide 2

Slide 2 text

how does bundler work, anyway?

Slide 3

Slide 3 text

a brief (?) history of dependency management

Slide 4

Slide 4 text

André Arko @indirect

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

let’s share ruby code

Slide 9

Slide 9 text

Gemfile gem “foo”

Slide 10

Slide 10 text

Terminal $ bundle install

Slide 11

Slide 11 text

Terminal $ bundle exec foo

Slide 12

Slide 12 text

done! pretty cool, right?

Slide 13

Slide 13 text

but… what just happened?

Slide 14

Slide 14 text

iiiiit’s History ⚔ Time

Slide 15

Slide 15 text

1994 2000 2003 2009 dependency timeline require setup.rb RubyGems Bundler

Slide 16

Slide 16 text

require it loads the codes

Slide 17

Slide 17 text

def require(filename) eval File.read(filename) end

Slide 18

Slide 18 text

i’m sure it’s fine run code twice?

Slide 19

Slide 19 text

$LOADED_FEATURES = [] def require(filename) if $LOADED_FEATURES.include?(filename) return true end eval File.read(filename) $LOADED_FEATURES << filename end

Slide 20

Slide 20 text

probably fine too only absolute paths?

Slide 21

Slide 21 text

$LOAD_PATH = [] def require(filename) full_path = $LOAD_PATH.first do |path| File.exist?(File.join(path, filename)) end eval File.read(full_path) end

Slide 22

Slide 22 text

load paths are ⛄ pretty ❄ cool

Slide 23

Slide 23 text

but now we need… setup.rb

Slide 24

Slide 24 text

how do setup.rb? ruby setup.rb setup ruby setup.rb config ruby setup.rb install

Slide 25

Slide 25 text

use ruby libraries 1. Find a cool library 2. Download the library 3. Untar the library 4. Run `ruby setup.rb all`

Slide 26

Slide 26 text

no versions no uninstall but it’s fine, I’m sure

Slide 27

Slide 27 text

maybe a little bit incredibly tedious

Slide 28

Slide 28 text

what if you could… gem install gem uninstall gem list rails

Slide 29

Slide 29 text

bonus round! gem install rails -v 4.1 gem install rails -v 4.2 gem install rails -v 5.0

Slide 30

Slide 30 text

gem "rack", "1.0" require "rack"

Slide 31

Slide 31 text

$ rackup _1.2.2_ -p 3000

Slide 32

Slide 32 text

so many gems! 100,000 gems 1,000,000 versions

Slide 33

Slide 33 text

but gem apps don’t play well with others

Slide 34

Slide 34 text

welcome to the team here’s your machine we expect setting up to take a week

Slide 35

Slide 35 text

# config/application.rb […] config.gem “rack” config.gem “rails” config.gem “what?” […]

Slide 36

Slide 36 text

“why is this broken in production?” “dunno, it works on every developer machine” 3 days of debugging later… “oh, look, one production server has frobnitz 1.1.3, but the others have 1.1.4” “welp. that explains those exceptions ”

Slide 37

Slide 37 text

version conflicts gem install rails rails s cd ../other-project rails s

Slide 38

Slide 38 text

activation errors how common can they be, really?

Slide 39

Slide 39 text

$ rails s Gem::LoadError: can't activate rack (~> 1.0.0., runtime) for ["actionpack-2.3.5"], already activated rack-1.1.0 for ["thin-1.2.7"] activation errors

Slide 40

Slide 40 text

the moral runtime resolution install-time resolution

Slide 41

Slide 41 text

wait… how do we resolve at install-time?

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

addressable (2.3.7) arel (6.0.0) bcrypt (3.1.10) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) builder (3.2.2) byebug (3.5.1) columnize (~> 0.8) debugger-linecache (~> 1.2) slop (~> 3.6) celluloid (0.16.0) Gemfile.lock

Slide 44

Slide 44 text

bundle install my old friend 1. Read the Gemfile (and lock, if it's there) 2. Ask RubyGems.org for a list of every gem we need 2. Find gems allowed by the Gemfile that work together 3. Write down those versions in the lock for future installs 4. Install gems until every locked gem is installed

Slide 45

Slide 45 text

bundle exec everyone’s nemesis 1. Read the Gemfile (and lock, if it's there) 2a. Use locked gems if possible OR 2b. Find versions that work to put in the lock 3. Remove any existing gems the $LOAD_PATH 4. Add each gem in the lock to the $LOAD_PATH

Slide 46

Slide 46 text

pro tip no more bundle exec! $ bundle binstubs rspec-core $ bin/rspec repeat as needed for other gems

Slide 47

Slide 47 text

was that the end? in a word, no.

Slide 48

Slide 48 text

I want YOU to contribute 2 @bundlerio [email protected]

Slide 49

Slide 49 text

or if you’re too busy, fund this work. http://rubytogether.org/join