3 ms·
Vagrant author here. Allow me to address both of your points. First, the "Java-ish" Ruby: I am using the middleware pattern. The classes are used to build up c
by mitchellh 14y ago
Vagrant author here. Allow me to address both of your points.
First, the "Java-ish" Ruby: I am using the middleware pattern. The classes are used to build up complex sequences of actions[1]. They are reusable and very easily testable. Why classes? Why not modules with functions? It actually started out as modules with functions, but middleware was so _painfully_ the RIGHT way to do things, I can't imagine doing it any other way. Instead of explaining it all, I guide you to this talk I gave on the pattern: http://confreaks.com/videos/961-mwrc2012-rack-middleware-as-a-general-purpose-abstraction http://confreaks.com/videos/961-mwrc2012-rack-middleware-as-...
Next, on Vagrant being "overkill." Write a shell script that does the following: Import a virtual machine, setup host only networking, setup shared folders, boots the machine, runs a provisioner within the machine. Wow that is simple. Oh, wait, I need that script to work on Mac, Linux, and Windows. Oh, VirtualBox has some bugs so can you work around that?[2] Also, host only networking requires some guest OS specific setup (Ubuntu different from Fedora different from FreeBSD etc.), so you have to handle that. Right, and it'd be nice if the script didn't setup networking that collided with other machines on the network, so please write in checks that ports and IPs don't collide. Maybe the script should also verify that Guest Additions are properly installed. AND shared folder performance in VirtualBox sucks, so can you modify that script to use NFS? But only on non-Windows, because Windows doesn't support NFS. Did I mention that NFS requires specialized configuration depending on the host OS AND guest OS? So if you're running Mac + Ubuntu its totally different from Linux + FreeBSD. Have fun!
Now, make all of that REUSABLE and EXTENSIBLE, while adding in some other features (other types of networking, host name setting, and so on).
Yeah, I'd say Vagrant's 3000 line of code count is pretty spot on, and pretty good.
[1]: https://github.com/mitchellh/vagrant/blob/391dc392675c73518ebf04252d824fe916e8860b/plugins/providers/virtualbox/action.rb#L124 https://github.com/mitchellh/vagrant/blob/391dc392675c73518e...
[2]: https://github.com/mitchellh/vagrant/blob/391dc392675c73518ebf04252d824fe916e8860b/plugins/providers/virtualbox/action/clean_machine_folder.rb https://github.com/mitchellh/vagrant/blob/391dc392675c73518e...
- alexangelini 14y agoIt is worth searching through all these comments and reading what Mitchell (mitchellh) has to say. It's been very informative getting the author's perspective on every important issue brought up in this thread.
- snprbob86 14y agoMitchell: First allow me to apologize for the tone of my comment. Re-reading it now, I realize that I glossed over a key point: I used Vagrant every day for a team of 5 people. In general, it worked very well, rarely broke in any way, saved us a whole bunch of time getting up and running. So thank you for your small, but real, contribution to my startup. > middleware was so _painfully_ the RIGHT way to do things I did see how you were composing the operations and I'm familiar with the middleware pattern; thanks for sharing your talk. However, I think this is one of those cases where OOP has a name for something that FP just takes for granted: function composition. Regardless, Clojure's Rack equivilant does provide middleware as functions of request -> response maps. It's much nicer to work with, but that might be a result of Clojure's design vs Ruby's and unrelated to Vagrant: https://github.com/ring-clojure/ring/wiki/Concepts https://github.com/ring-clojure/ring/wiki/Concepts > Write a shell script that does the following I don't have any of those requirements. I only need to support OSX as the host OS. The team's MacBook Airs don't have enough resources to run more than one VM, so I don't ever worry about port collisions. I need to configure my network adapters anyway for my production deployment, so I just need an if statement or two in that config file template. Hell, I don't even need the ability to turn off a VM gracefully, since kill -9 seemed like a decent way to test crash recovery. Even thought I don't have those requirements: I used Vagrant. It saved me some time up front. But that complexity has a cost. Running `vagrant ssh`, for example, took 3ish seconds on my machine. Again, this is probably due to RubyGems, which is painfully slow. I had to explain to the team to run `vagrant ssh-config >> ~/.ssh/config`, then to go tweak that a bit, so that they could write `ssh dev` and have it be instantaneous. Worth noting however, is that I already needed a way to generate local ssh config for each production box to be able to talk to specific other production boxes, and for client machines to talk to our cluster. Vagrant's ssh-config command was just one more extra moving part to concern myself with, so I manually put the correct config into a cat script along with the production needs, and added it to the build process. There was one or two more of these little things that escape my memory now. > make all of that REUSABLE and EXTENSIBLE I think my main complaint about Vagrant is one which you seem to be fixing, starting with the very commit that this HN thread is attached to: You're pulling out the REUSABLE bit of abstracting away various virtualization platforms across a variety of host and guest operating systems. However, I'm a big believer that EXTENSIBLE does not belong in library code. Extensibility belongs at user layers. Furthermore, extensibility is really fucking hard. 99% of the time, I'd rather the core be more reusable and allow me to bypass extensibility. I think that Git is a perfect example of this design. They call it plumbing and porcelain. The plumbing commands offer zero extensibility. They don't have any creature comforts, as their output is tuned for parsing. The goal of these commands is to manipulate the abstractions of the underlying system. The porcelain, by contrast, does offer extensibility via git-foo.sh scripts on your path, aliases and configuration, commit hooks, etc. I'd see a lot of value in something like this for virtual machine management. Another example would be Chef & Puppet's facts systems. I forgot what they are called. Ohai? Something like that. They provide OS-independent interfaces for gathering facts about machines. Those components should be hoisted to first class project status! Unfortunately, Vagrant does not, yet, provide a plumbing vs porcelain split. In many ways, I view Vagrant like SVN: It's a damn solid piece of software. Lot's of people get a ton of milage out of it. However, it's underlying concepts are slightly muddled together and there are huge gains to be reaped from deep thought and careful modularization. When those big gains do come, they will only work on a single platform, maybe one or two guest operating systems, people will bitch about it's low ease of use, despite it's inherent simplicity, but the people who deeply understand machine provisioning and management will adopt it in droves, until eventually Windows support doesn't suck too bad, all the various use cases are more or less covered, and people are wondering "How can you possibly still use that old thing?" I think you've got a good start towards that goal in Vagrant, but my complexity sense is tingling. > I'd say Vagrant's 3000 line of code count is pretty spot on I just ran cloc on the master branch locally; I see 12355 lines of Ruby ;-)