bindler 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f92540bd8759863dabbcf7d51983981fc7dd7cc
4
+ data.tar.gz: ceaa5ec8e18626c1dd746f5124419aa0d0232144
5
+ SHA512:
6
+ metadata.gz: 2a775e0d0a5b2bd3b9af01c8b763a0fac0fffe2292b6987f6ee66a7485c064617f9009a20ebe72c6b7e68427d812078c79b2fe6f8be0e062433cb11da790abae
7
+ data.tar.gz: 974660a1913c32b5c1c851d101063f71f589db78162d38e4ac9746678642cfdd4559c405b28ec2be6acac317080fb33f65a495cb2ff48dafa6386b98a99f422f
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+ development/.vagrant
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bindler.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'vagrant', github: 'mitchellh/vagrant'
8
+ gem 'vagrant-lxc', github: 'fgrehm/vagrant-lxc'
9
+ gem 'vagrant-cachier', github: 'fgrehm/vagrant-cachier'
10
+ gem 'vagrant-pristine', github: 'fgrehm/vagrant-pristine'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ GIT
2
+ remote: git://github.com/fgrehm/vagrant-cachier.git
3
+ revision: f5d9ce507239535326a0a0395c890cc7a27d73f1
4
+ specs:
5
+ vagrant-cachier (0.3.0.dev)
6
+
7
+ GIT
8
+ remote: git://github.com/fgrehm/vagrant-lxc.git
9
+ revision: d2e354839f404ef426bdee38e50c9b3256e1e3c2
10
+ specs:
11
+ vagrant-lxc (0.4.1.dev)
12
+
13
+ GIT
14
+ remote: git://github.com/fgrehm/vagrant-pristine.git
15
+ revision: 5c400d7850fc5f98d9601b59f4c3bd74818650de
16
+ specs:
17
+ vagrant-pristine (0.2.0)
18
+
19
+ GIT
20
+ remote: git://github.com/mitchellh/vagrant.git
21
+ revision: 4b299c9fc22dfdb192993d4874670370b8e90122
22
+ specs:
23
+ vagrant (1.2.5.dev)
24
+ childprocess (~> 0.3.7)
25
+ erubis (~> 2.7.0)
26
+ i18n (~> 0.6.0)
27
+ log4r (~> 1.1.9)
28
+ net-scp (~> 1.1.0)
29
+ net-ssh (~> 2.6.6)
30
+
31
+ PATH
32
+ remote: .
33
+ specs:
34
+ bindler (0.1.0)
35
+
36
+ GEM
37
+ remote: https://rubygems.org/
38
+ specs:
39
+ childprocess (0.3.9)
40
+ ffi (~> 1.0, >= 1.0.11)
41
+ erubis (2.7.0)
42
+ ffi (1.9.0)
43
+ i18n (0.6.4)
44
+ log4r (1.1.10)
45
+ net-scp (1.1.2)
46
+ net-ssh (>= 2.6.5)
47
+ net-ssh (2.6.8)
48
+ rake (10.1.0)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ bindler!
55
+ bundler (~> 1.3)
56
+ rake
57
+ vagrant!
58
+ vagrant-cachier!
59
+ vagrant-lxc!
60
+ vagrant-pristine!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Fabio Rehm
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # NOTICE
2
+ **This plugin was initially released as Vundler and was just renamed to
3
+ Bindler to avoid confusion with [Vim's Vundle](https://github.com/gmarik/vundle),
4
+ please follow the steps to [revert its installation](https://github.com/fgrehm/bindler/blob/b12a69e599fc56e7b05108df52a466d022ef592c/README.md#help-things-are-falling-apart)
5
+ before upgrading to Bindler**
6
+
7
+ # Bindler
8
+ Dead easy Vagrant plugins management, think of it as soon-to-be "[Bundler](http://bundler.io/)
9
+ for Vagrant".
10
+
11
+ ## WARNING
12
+ This is highly experimental and things might go wrong. It basically does some
13
+ [heavy monkey patching](lib/vundler/bend_vagrant.rb) on Vagrant's core and should
14
+ not be considered "production-ready". Please keep that in mind and be ready to
15
+ [revert Bindler's installation](#help-things-are-falling-apart) in case things
16
+ go crazy.
17
+
18
+
19
+ ## Installation
20
+ Make sure you have Vagrant 1.2+ and run:
21
+
22
+ ```
23
+ vagrant plugin install bindler
24
+ vagrant bindler setup
25
+ ```
26
+
27
+ ## Usage
28
+ Add one of `plugins.json`, `.vagrant_plugins`, or `vagrant/plugins.json`
29
+ to your project root. The first matching file will be used as your
30
+ project's plugins.json file.
31
+
32
+ ```json
33
+ [
34
+ "vagrant-lxc",
35
+ {"vagrant-cachier": "0.2.0"}
36
+ ]
37
+ ```
38
+
39
+ And run `vagrant plugin bundle` to install missing dependencies:
40
+
41
+ ```
42
+ $ vagrant plugin bundle
43
+
44
+ Installing plugins...
45
+ -> vagrant-lxc already installed
46
+ -> vagrant-cachier (0.2.0)
47
+ ```
48
+
49
+ List installed plugins with `vagrant plugin list`:
50
+
51
+ ```
52
+ $ vagrant plugin list
53
+
54
+ vagrant-lxc (0.4.0)
55
+ bindler (0.1.0)
56
+
57
+ Project dependencies:
58
+ -> vagrant-lxc
59
+ -> vagrant-cachier 0.2.0
60
+ ```
61
+
62
+
63
+ ## Help! Things are falling apart!
64
+ First bring back Vagrant's default `plugins.json` file:
65
+
66
+ ```
67
+ mv $HOME/.vagrant.d/{global-,}plugins.json
68
+ ```
69
+
70
+ And then remove the `require 'bindler'` from your `$HOME/.vagrant.d/Vagrantfile`.
71
+
72
+ ## How does it work?
73
+ Have a look at [this blog post](http://fabiorehm.com/blog/2013/07/15/vundler-dead-easy-plugin-management-for-vagrant/).
74
+
75
+ # Development
76
+
77
+ ```bash
78
+ git clone bindler
79
+ cd bindler
80
+ bundle install
81
+
82
+ # Add some changes...
83
+ bundle exec rake build
84
+ vagrant plugin install pkg/bindler-VERSION.gem
85
+ ```
86
+
87
+ ## Contributing
88
+ 1. Fork it
89
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
90
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
91
+ 4. Push to the branch (`git push origin my-new-feature`)
92
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ Dir['./tasks/**/*.rake'].each { |f| load f }
data/bindler.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vundler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bindler"
8
+ spec.version = Bindler::VERSION
9
+ spec.authors = ["Fabio Rehm"]
10
+ spec.email = ["fgrehm@gmail.com"]
11
+ spec.description = %q{Dead easy Vagrant plugins management}
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/fgrehm/vundler"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,59 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.require_plugin 'vagrant-cachier'
5
+ Vagrant.require_plugin 'vagrant-pristine'
6
+ Vagrant.require_plugin 'vagrant-lxc'
7
+
8
+ Vagrant.configure("2") do |config|
9
+ config.vm.box = "quantal64"
10
+ config.vm.synced_folder "../", "/vagrant", id: 'vagrant-root', nfs: true
11
+
12
+ config.cache.auto_detect = true
13
+ config.cache.enable_nfs = true
14
+
15
+ config.vm.provider :lxc do |lxc|
16
+ # Required to boot nested containers
17
+ lxc.customize 'aa_profile', 'unconfined'
18
+ end
19
+
20
+ config.vm.provision :shell, inline: %[
21
+ if ! $(which lxc-create > /dev/null); then
22
+ cat <<STR > /etc/default/lxc
23
+ LXC_AUTO="true"
24
+ USE_LXC_BRIDGE="true"
25
+ LXC_BRIDGE="lxcbr0"
26
+ LXC_ADDR="10.0.253.1"
27
+ LXC_NETMASK="255.255.255.0"
28
+ LXC_NETWORK="10.0.253.0/24"
29
+ LXC_DHCP_RANGE="10.0.253.2,10.0.253.254"
30
+ LXC_DHCP_MAX="253"
31
+ LXC_SHUTDOWN_TIMEOUT=120
32
+ STR
33
+
34
+ apt-get update &&
35
+ apt-get upgrade -y &&
36
+ apt-get install -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' \
37
+ lxc redir htop vim
38
+ fi
39
+
40
+ if ! $(which vagrant > /dev/null); then
41
+ # Pick your Vagrant version:
42
+ # 1.2.3 -> http://files.vagrantup.com/packages/95d308caaecd139b8f62e41e7add0ec3f8ae3bd1/vagrant_1.2.3_x86_64.deb
43
+ # 1.2.2 -> http://files.vagrantup.com/packages/7e400d00a3c5a0fdf2809c8b5001a035415a607b/vagrant_1.2.2_x86_64.deb
44
+ # 1.2.1 -> http://files.vagrantup.com/packages/a7853fe7b7f08dbedbc934eb9230d33be6bf746f/vagrant_1.2.1_x86_64.deb
45
+ # 1.2.0 -> http://files.vagrantup.com/packages/f5ece47c510e5a632adb69701b78cb6dcbe03713/vagrant_1.2.0_x86_64.deb
46
+
47
+ wget http://files.vagrantup.com/packages/95d308caaecd139b8f62e41e7add0ec3f8ae3bd1/vagrant_1.2.3_x86_64.deb -O /tmp/vagrant.deb -q
48
+ dpkg -i /tmp/vagrant.deb
49
+ fi
50
+
51
+ if ! $(grep -q 'VAGRANT_DEFAULT_PROVIDER=lxc' /home/vagrant/.bashrc); then
52
+ echo 'export VAGRANT_DEFAULT_PROVIDER=lxc' >> /home/vagrant/.bashrc
53
+ fi
54
+
55
+ if [ `uname -r` = 3.5.0-17-generic ]; then
56
+ echo "Please restart the machine with 'vagrant reload'"
57
+ fi
58
+ ]
59
+ end
data/lib/bindler.rb ADDED
@@ -0,0 +1,6 @@
1
+ require_relative "vundler/version"
2
+ require_relative "vundler/plugin"
3
+ require_relative "vundler/logging"
4
+ require_relative 'vundler/plugin_not_found_error'
5
+ require_relative "vundler/local_plugins_manifest_ext"
6
+ require_relative "vundler/bend_vagrant"
@@ -0,0 +1,120 @@
1
+ # WARNING: Monkey patches ahead
2
+
3
+ Vagrant::Environment.class_eval do
4
+ include VagrantPlugins::Bindler::Logging
5
+ include VagrantPlugins::Bindler::LocalPluginsManifestExt
6
+
7
+ # UGLY HACK: This is required because we need to load project specific plugins
8
+ # before the `:environment_load` hook from Vagrant::Environment on [1]. In order
9
+ # to run the hook, Vagrantfile configs have to be parsed [2] to build a
10
+ # Vagrant::Action::Runner [3].
11
+ #
12
+ # [1] - https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/environment.rb#L135
13
+ # [2] - https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/environment.rb#L239
14
+ # [3] - https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/environment.rb#L498-L510
15
+ #
16
+ # DISCUSS: What if Vagrant had another hook that was called before `:environment_load`?
17
+ alias old_hook hook
18
+ def hook(name)
19
+ unless @__custom_plugins_loaded
20
+ bindler_debug 'Loading local plugins...'
21
+ __load_local_plugins
22
+
23
+ @__custom_plugins_loaded = true
24
+ end
25
+ old_hook name
26
+ end
27
+
28
+ # This method loads plugins from a project specific `plugins.json` file
29
+ def __load_local_plugins
30
+ unless bindler_plugins_file
31
+ lookup_paths = VagrantPlugins::Bindler::LocalPluginsManifestExt::PLUGINS_JSON_LOOKUP
32
+ bindler_debug "Local plugins manifest file not found, looked into #{lookup_paths.inspect}"
33
+ return
34
+ end
35
+
36
+ ARGV.each do |arg|
37
+ if !arg.start_with?("-") && arg == 'bindler'
38
+ bindler_debug 'bindler command detected, setting VAGRANT_NO_PLUGINS to 1'
39
+ ENV["VAGRANT_NO_PLUGINS"] = "1"
40
+ break
41
+ end
42
+ end
43
+
44
+ if ENV['VAGRANT_NO_PLUGINS']
45
+ bindler_debug 'VAGRANT_NO_PLUGINS is set to true, skipping local plugins manifest parsing'
46
+ return
47
+ end
48
+
49
+ # Prepend our local gem path and reset the paths that Rubygems knows about.
50
+ ENV["GEM_PATH"] = "#{local_data_path.join('gems')}#{::File::PATH_SEPARATOR}#{ENV["GEM_PATH"]}"
51
+ ::Gem.clear_paths
52
+
53
+ bindler_debug "#{bindler_plugins_file} data: #{bindler_plugins.inspect}"
54
+ bindler_plugins.each do |plugin|
55
+ if plugin.is_a?(String)
56
+ __load_plugin plugin
57
+ else
58
+ __load_plugin *plugin.first
59
+ end
60
+ end
61
+
62
+ if @__failed_to_load
63
+ plugins = @__failed_to_load.map do |plugin, version|
64
+ " -> #{plugin} (#{version || ">= 0"})"
65
+ end
66
+ raise VagrantPlugins::Bindler::PluginNotFoundError, plugins: plugins.join("\n")
67
+ end
68
+ end
69
+
70
+ def __load_plugin(plugin, version = nil)
71
+ bindler_debug "Loading #{plugin} (#{version.inspect})"
72
+ gem plugin, version
73
+ Vagrant.require_plugin plugin
74
+ rescue Gem::LoadError
75
+ (@__failed_to_load ||= []) << [plugin, version]
76
+ end
77
+ end
78
+
79
+ require Vagrant.source_root.join('plugins/commands/plugin/state_file').to_s
80
+ # Vagrant plugin commands manipulate a StateFile object that keeps track of system
81
+ # wide installed plugins. Since bindler is kept separately on `~/.vagrant.d/plugins`,
82
+ # we hard code a reference to it over here.
83
+ # If we don't do this, Bindler will be uninstalled after a system wide plugin install.
84
+ class BindlerStateFile < VagrantPlugins::CommandPlugin::StateFile
85
+ def installed_plugins
86
+ ['bindler'] + @data['installed']
87
+ end
88
+ end
89
+
90
+ require Vagrant.source_root.join('plugins/commands/plugin/command/base').to_s
91
+ # The patch makes sure Vagrant's system wide plugin commands manipulates the custom
92
+ # configuration file.
93
+ VagrantPlugins::CommandPlugin::Command::Base.class_eval do
94
+ alias old_action action
95
+ def action(callable, env=nil)
96
+ env = {
97
+ plugin_state_file: BindlerStateFile.new(@env.home_path.join("global-plugins.json")),
98
+ }.merge(env || {})
99
+
100
+ old_action(callable, env)
101
+ end
102
+ end
103
+
104
+ require Vagrant.source_root.join('plugins/commands/plugin/action/install_gem').to_s
105
+ # This patch ensures Bindler does not get a reference on `~/.vagrant.d/global-plugins.json`
106
+ VagrantPlugins::CommandPlugin::Action::InstallGem.class_eval do
107
+ include VagrantPlugins::Bindler::Logging
108
+
109
+ alias old_call call
110
+ def call(env)
111
+ if env[:plugin_name] == 'bindler'
112
+ bindler_debug 'Installing bindler to global plugins file'
113
+ # bindler is the only plugin that should be installed on the global state file
114
+ env[:plugin_state_file] = CommandPlugin::StateFile.new(env[:home_path].join("plugins.json"))
115
+ else
116
+ bindler_debug "Installing #{env[:plugin_name]} to $HOME/.vagrant.d"
117
+ end
118
+ old_call(env)
119
+ end
120
+ end
@@ -0,0 +1,23 @@
1
+ module VagrantPlugins
2
+ module Bindler
3
+ module LocalPluginsManifestExt
4
+ PLUGINS_JSON_LOOKUP = [
5
+ ENV['VAGRANT_PLUGINS_FILENAME'],
6
+ 'vagrant/plugins.json',
7
+ '.vagrant_plugins.json',
8
+ 'plugins.json'
9
+ ].compact
10
+
11
+ def bindler_plugins_file
12
+ @bindler_plugins_file ||= PLUGINS_JSON_LOOKUP.map do |path|
13
+ plugins = cwd.join(path)
14
+ plugins if plugins.file?
15
+ end.compact.first
16
+ end
17
+
18
+ def bindler_plugins
19
+ @bindler_plugins ||= bindler_plugins_file ? JSON.parse(bindler_plugins_file.read) : {}
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ module VagrantPlugins
2
+ module Bindler
3
+ module Logging
4
+ def bindler_debug(msg)
5
+ @logger.debug "[BINDLER] #{msg}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ I18n.load_path << File.expand_path(File.dirname(__FILE__) + '/../../locales/en.yml')
2
+ I18n.reload!
3
+
4
+ module VagrantPlugins
5
+ module Bindler
6
+ class Plugin < Vagrant.plugin('2')
7
+ name 'Bindler'
8
+
9
+ command("plugin") do
10
+ require_relative 'plugin_command/root'
11
+ PluginCommand::Root
12
+ end
13
+
14
+ command("bindler") do
15
+ require_relative 'bindler_command/root'
16
+ BindlerCommand::Root
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,94 @@
1
+ require_relative '../logging'
2
+
3
+ require Vagrant.source_root.join('plugins/commands/plugin/command/base').to_s
4
+ require "rubygems/dependency_installer"
5
+
6
+ module VagrantPlugins
7
+ module Bindler
8
+ module PluginCommand
9
+ # Based on https://github.com/mitchellh/vagrant/blob/master/plugins/commands/plugin/action/install_gem.rb
10
+ class Bundle < CommandPlugin::Command::Base
11
+ include VagrantPlugins::Bindler::Logging
12
+
13
+ def initialize(*)
14
+ super
15
+
16
+ if @env.local_data_path
17
+ @local_gems_path = @env.local_data_path.join('gems')
18
+ else
19
+ bindler_debug 'Local data path is not set'
20
+ end
21
+ end
22
+
23
+ def execute
24
+ if @env.bindler_plugins_file
25
+ bindler_debug "#{@env.bindler_plugins_file} data: #{@env.bindler_plugins.inspect}"
26
+
27
+ if @env.bindler_plugins.any?
28
+ # REFACTOR: Use I18n
29
+ @env.ui.info('Installing plugins...')
30
+
31
+ @env.bindler_plugins.each do |plugin|
32
+ if plugin.is_a?(String)
33
+ install plugin
34
+ else
35
+ install *plugin.first
36
+ end
37
+ end
38
+ exit_code = 0
39
+ else
40
+ # REFACTOR: Use I18n
41
+ @env.ui.info("No plugins specified on #{@env.bindler_plugins_file}")
42
+ end
43
+ else
44
+ # REFACTOR: Use I18n
45
+ @env.ui.error "No plugins manifest file found, looked up on #{Vagrant::Environment::PLUGINS_JSON_LOOKUP}"
46
+ exit_code = 1
47
+ end
48
+
49
+ exit_code
50
+ end
51
+
52
+ def gem_helper(path)
53
+ CommandPlugin::GemHelper.new(path)
54
+ end
55
+
56
+ def installed_gems
57
+ @installed ||= {}.tap do |installed|
58
+ # Combine project specific gems and global plugins
59
+ gem_helper("#{@local_gems_path}#{::File::PATH_SEPARATOR}#{@env.gems_path}").with_environment do
60
+ Gem::Specification.find_all.each do |spec|
61
+ (installed[spec.name] ||= {})[spec.version.to_s] = spec
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ def install(plugin_name, version = nil)
68
+ plugin_name_label = plugin_name
69
+ plugin_name_label += " (#{version})" if version
70
+
71
+ versions = installed_gems.fetch(plugin_name, {}).keys
72
+ bindler_debug "Installed versions for #{plugin_name}: #{versions}"
73
+
74
+ if (versions.include? version) || (version.nil? && versions.any?)
75
+ @env.ui.info(" -> #{plugin_name_label} already installed")
76
+ return
77
+ end
78
+
79
+ gem_helper(@local_gems_path).with_environment do
80
+ installer = Gem::DependencyInstaller.new(:document => [])
81
+
82
+ begin
83
+ @env.ui.info(" -> #{plugin_name_label} ")
84
+ installer.install(plugin_name, version)
85
+ rescue Gem::GemNotFoundException
86
+ raise Vagrant::Errors::PluginInstallNotFound,
87
+ :name => plugin_name
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,43 @@
1
+ require Vagrant.source_root.join('plugins/commands/plugin/command/list').to_s
2
+
3
+ module VagrantPlugins
4
+ module Bindler
5
+ module PluginCommand
6
+ # Override the built in `plugin list` command to output project specific
7
+ # plugins information
8
+ class List < CommandPlugin::Command::List
9
+ include VagrantPlugins::Bindler::Logging
10
+
11
+ def execute
12
+ return unless super == 0
13
+
14
+ if @env.bindler_plugins_file
15
+ bindler_debug "#{@env.bindler_plugins_file} data: #{@env.bindler_plugins.inspect}"
16
+
17
+ if @env.bindler_plugins.any?
18
+ @env.ui.info "\nProject dependencies:"
19
+ @env.bindler_plugins.each do |plugin|
20
+ if plugin.is_a?(String)
21
+ display plugin
22
+ else
23
+ display *plugin.first
24
+ end
25
+ end
26
+ end
27
+ else
28
+ @env.ui.info "\nNo project specific plugins manifest file found!"
29
+ end
30
+
31
+ # Success, exit status 0
32
+ 0
33
+ end
34
+
35
+ def display(plugin, version = nil)
36
+ label = " -> #{plugin}"
37
+ label << " #{version}" if version
38
+ @env.ui.info label
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,25 @@
1
+ require Vagrant.source_root.join('plugins/commands/plugin/command/root').to_s
2
+
3
+ module VagrantPlugins
4
+ module Bindler
5
+ module PluginCommand
6
+ class Root < CommandPlugin::Command::Root
7
+ def initialize(argv, env)
8
+ super
9
+
10
+ # Override the built in `plugin list` command to output project specific
11
+ # plugins information
12
+ @subcommands.register(:list) do
13
+ require_relative "list"
14
+ Bindler::PluginCommand::List
15
+ end
16
+
17
+ @subcommands.register(:bundle) do
18
+ require_relative "bundle"
19
+ Bindler::PluginCommand::Bundle
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ module VagrantPlugins
2
+ module Bindler
3
+ class PluginNotFoundError < Vagrant::Errors::VagrantError
4
+ error_key(:plugin_not_found_error)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Bindler
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,60 @@
1
+ require Vagrant.source_root.join('plugins/commands/plugin/command/root').to_s
2
+
3
+ module VagrantPlugins
4
+ module Bindler
5
+ module BindlerCommand
6
+ class Root < Vagrant.plugin(2, :command)
7
+ def initialize(argv, env)
8
+ super
9
+
10
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
11
+ @subcommands = Vagrant::Registry.new
12
+
13
+ @subcommands.register(:setup) do
14
+ require_relative "setup"
15
+ Bindler::BindlerCommand::Setup
16
+ end
17
+ end
18
+
19
+ def execute
20
+ if @main_args.include?("-h") || @main_args.include?("--help")
21
+ # Print the help for all the sub-commands.
22
+ return help
23
+ end
24
+
25
+ # If we reached this far then we must have a subcommand. If not,
26
+ # then we also just print the help and exit.
27
+ command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
28
+ return help if !command_class || !@sub_command
29
+ @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
30
+
31
+ # Initialize and execute the command class
32
+ command_class.new(@sub_args, @env).execute
33
+ end
34
+
35
+ # Prints the help out for this command
36
+ def help
37
+ opts = OptionParser.new do |o|
38
+ o.banner = "Usage: vagrant bindler <command> [<args>]"
39
+ o.separator ""
40
+ o.separator "Available subcommands:"
41
+
42
+ # Add the available subcommands as separators in order to print them
43
+ # out as well.
44
+ keys = []
45
+ @subcommands.each { |key, value| keys << key.to_s }
46
+
47
+ keys.sort.each do |key|
48
+ o.separator " #{key}"
49
+ end
50
+
51
+ o.separator ""
52
+ o.separator "For help on any individual command run `vagrant bundler COMMAND -h`"
53
+ end
54
+
55
+ @env.ui.info(opts.help, :prefix => false)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,56 @@
1
+ require_relative '../logging'
2
+
3
+ module VagrantPlugins
4
+ module Bindler
5
+ module BindlerCommand
6
+ class Setup < Vagrant.plugin(2, :command)
7
+ def execute
8
+ if @env.home_path.join('global-plugins.json').file?
9
+ @env.ui.info "Bindler has already been set up!"
10
+ return 0
11
+ end
12
+
13
+ # Load current plugins.json file
14
+ plugins_json = @env.home_path.join('plugins.json')
15
+ plugins_json_data = JSON.parse(plugins_json.read)
16
+ @logger.debug "Current #{plugins_json} data: #{plugins_json_data.inspect}"
17
+
18
+ # Gets a list of other plugins that are installed
19
+ @logger.debug "Getting list of installed plugins"
20
+ other_plugins = plugins_json_data['installed'].dup
21
+ other_plugins.delete('bindler')
22
+
23
+ # Save other plugins to a separate file
24
+ @logger.debug "Writing #{other_plugins.inspect} to #{@env.home_path.join('global-plugins.json')}"
25
+ @env.home_path.join('global-plugins.json').open("w+") do |f|
26
+ f.write(JSON.dump({'installed' => other_plugins}))
27
+ end
28
+
29
+ # Leave only bindler on the global plugins file
30
+ plugins_json_data['installed'] = ['bindler']
31
+ @logger.debug "Writing #{plugins_json_data.inspect} to #{plugins_json}"
32
+ plugins_json.open('w+') do |f|
33
+ f.write(JSON.dump plugins_json_data)
34
+ end
35
+
36
+ # Add require to ~/.vagrant.d/Vagrantfile
37
+ vagrantfile = @env.home_path.join('Vagrantfile')
38
+ vagrantfile_contents = vagrantfile.file? ? vagrantfile.read : ''
39
+ # FIXME: We need to handle emacs / vim file types comments
40
+ vagrantfile_contents = <<-STR
41
+ begin
42
+ require 'bindler'
43
+ rescue LoadError; end
44
+ #{vagrantfile_contents}
45
+ STR
46
+ @logger.debug "Writing to system wide Vagrantfile:\n#{vagrantfile_contents}"
47
+ @env.home_path.join('Vagrantfile').open("w+") do |f|
48
+ f.write vagrantfile_contents
49
+ end
50
+
51
+ 0
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,7 @@
1
+ en:
2
+ vagrant:
3
+ errors:
4
+ plugin_not_found_error: |-
5
+ Could not find the following plugins for the current environment:
6
+ %{plugins}
7
+ Run `vagrant plugin bundle` to install missing plugins.
data/tasks/deploy.rake ADDED
@@ -0,0 +1,12 @@
1
+ task :clean do
2
+ sh 'rm -f pkg/*.gem'
3
+ end
4
+
5
+ task :install_vm do
6
+ Bundler.with_clean_env do
7
+ sh "cd development && vagrant ssh -c 'vagrant plugin uninstall bindler && vagrant plugin install /vagrant/pkg/bindler-*.gem'"
8
+ end
9
+ end
10
+
11
+ desc 'Rebuild plugin and install on Vagrant dev VM'
12
+ task :deploy => [:clean, :build, :install_vm]
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bindler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fabio Rehm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Dead easy Vagrant plugins management
42
+ email:
43
+ - fgrehm@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bindler.gemspec
55
+ - development/Vagrantfile
56
+ - lib/bindler.rb
57
+ - lib/vundler/bend_vagrant.rb
58
+ - lib/vundler/local_plugins_manifest_ext.rb
59
+ - lib/vundler/logging.rb
60
+ - lib/vundler/plugin.rb
61
+ - lib/vundler/plugin_command/bundle.rb
62
+ - lib/vundler/plugin_command/list.rb
63
+ - lib/vundler/plugin_command/root.rb
64
+ - lib/vundler/plugin_not_found_error.rb
65
+ - lib/vundler/version.rb
66
+ - lib/vundler/vundler_command/root.rb
67
+ - lib/vundler/vundler_command/setup.rb
68
+ - locales/en.yml
69
+ - tasks/deploy.rake
70
+ homepage: https://github.com/fgrehm/vundler
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.0.0
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Dead easy Vagrant plugins management
94
+ test_files: []