├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── Vagrantfile ├── lib ├── vagrant │ ├── multiplug.rb │ └── multiplug │ │ └── version.rb └── vagrant_plugins │ └── multiplug │ ├── action │ └── install_plugins.rb │ ├── config.rb │ └── plugin.rb ├── recipe.yml └── vagrant-multiplug.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.vagrant 3 | /.yardoc 4 | /Gemfile.lock 5 | /_yardoc/ 6 | /coverage/ 7 | /doc/ 8 | /pkg/ 9 | /spec/reports/ 10 | /tmp/ 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.2.0 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.0.3 2 | - Fix problem that newly-installed gems can't be loaded after restart 3 | 4 | ## 0.0.2 5 | - Fix installed package checking logic 6 | 7 | ## 0.0.1 8 | - 1st Release 9 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | group :development do 4 | gem "vagrant", git: "https://github.com/mitchellh/vagrant.git" 5 | end 6 | 7 | group :plugins do 8 | gemspec 9 | end 10 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Ryo Nakamura 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vagrant-multiplug 2 | [Vagrant](https://github.com/mitchellh/vagrant) plug-in to manage plug-in dependencies. 3 | 4 | ## Usage 5 | This plug-in will automatically install dependent plug-in before running vagrant actions. 6 | 7 | ``` 8 | $ vagrant plugin install vagrant-multiplug 9 | ``` 10 | 11 | After installing, you can specify the required plug-in dependencies in your Vagrantfile like so: 12 | 13 | ```rb 14 | # Vagrantfile 15 | Vagrant.configure("2") do |config| 16 | config.plugin.add_dependency "vagrant-serverkit", "0.0.2" 17 | config.plugin.add_dependency "serverkit-defaults" 18 | config.plugin.add_dependency "serverkit-homebrew" 19 | config.plugin.add_dependency "serverkit-karabiner" 20 | config.plugin.add_dependency "serverkit-rbenv" 21 | ... 22 | end 23 | ``` 24 | 25 | ## Example 26 | Here is an example of `vagrant up`. 27 | 28 | ``` 29 | $ vagrant plugin install vagrant-multiplug 30 | Installing the 'vagrant-multiplug' plugin. This can take a few minutes... 31 | Installed the plugin 'vagrant-multiplug (0.0.2)'! 32 | $ vagrant plugin list 33 | vagrant-multiplug (0.0.2) 34 | vagrant-share (1.1.3, system) 35 | $ vagrant up 36 | Bringing machine 'default' up with 'virtualbox' provider... 37 | Installing the 'vagrant-serverkit --version '0.0.2'' plugin. This can take a few minutes... 38 | Installed the plugin 'vagrant-serverkit (0.0.2)'! 39 | Installing the 'serverkit-defaults' plugin. This can take a few minutes... 40 | Installed the plugin 'serverkit-defaults (0.0.1)'! 41 | Installing the 'serverkit-homebrew' plugin. This can take a few minutes... 42 | Installed the plugin 'serverkit-homebrew (0.0.3)'! 43 | Installing the 'serverkit-karabiner' plugin. This can take a few minutes... 44 | Installed the plugin 'serverkit-karabiner (0.0.1)'! 45 | Installing the 'serverkit-rbenv' plugin. This can take a few minutes... 46 | Installed the plugin 'serverkit-rbenv (0.0.2)'! 47 | Restarting vagrant... 48 | Bringing machine 'default' up with 'virtualbox' provider... 49 | ==> default: Importing base box 'ubuntu/trusty64'... 50 | ==> default: Matching MAC address for NAT networking... 51 | ==> default: Checking if box 'ubuntu/trusty64' is up to date... 52 | ==> default: Setting the name of the VM: vagrant-multiplug_default_1428990750261_56569 53 | ==> default: Clearing any previously set forwarded ports... 54 | ==> default: Clearing any previously set network interfaces... 55 | ==> default: Preparing network interfaces based on configuration... 56 | default: Adapter 1: nat 57 | ==> default: Forwarding ports... 58 | default: 22 => 2222 (adapter 1) 59 | ==> default: Booting VM... 60 | ==> default: Waiting for machine to boot. This may take a few minutes... 61 | default: SSH address: 127.0.0.1:2222 62 | default: SSH username: vagrant 63 | default: SSH auth method: private key 64 | default: Warning: Connection timeout. Retrying... 65 | default: Warning: Remote connection disconnect. Retrying... 66 | default: 67 | default: Vagrant insecure key detected. Vagrant will automatically replace 68 | default: this with a newly generated keypair for better security. 69 | default: 70 | default: Inserting generated public key within guest... 71 | default: Removing insecure key from the guest if its present... 72 | default: Key inserted! Disconnecting and reconnecting using new SSH key... 73 | ==> default: Machine booted and ready! 74 | ==> default: Checking for guest additions in VM... 75 | ==> default: Mounting shared folders... 76 | default: /vagrant => /Users/r7kamura/src/github.com/r7kamura/vagrant-multiplug 77 | ``` 78 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure("2") do |config| 2 | config.vm.box = "ubuntu/trusty64" 3 | 4 | config.plugin.add_dependency "vagrant-serverkit", "0.0.2" 5 | config.plugin.add_dependency "serverkit-rbenv", "0.0.3" 6 | 7 | config.vm.provision :serverkit do |serverkit_config| 8 | serverkit_config.recipe_path = "recipe.yml" 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/vagrant/multiplug.rb: -------------------------------------------------------------------------------- 1 | require "vagrant" 2 | require "vagrant/multiplug/version" 3 | require "vagrant_plugins/multiplug/plugin" 4 | -------------------------------------------------------------------------------- /lib/vagrant/multiplug/version.rb: -------------------------------------------------------------------------------- 1 | module Vagrant 2 | module Multiplug 3 | VERSION = "0.0.3" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/vagrant_plugins/multiplug/action/install_plugins.rb: -------------------------------------------------------------------------------- 1 | module VagrantPlugins 2 | module Multiplug 3 | module Action 4 | class InstallPlugins 5 | def initialize(app, *) 6 | @app = app 7 | end 8 | 9 | def call(env) 10 | results = env[:machine].config.plugin.dependencies.map do |dependency| 11 | case 12 | when dependency.installed? 13 | false 14 | when system("vagrant plugin install #{dependency.name} #{dependency.options}") 15 | true 16 | else 17 | exit(1) 18 | end 19 | end 20 | restart if results.any? 21 | @app.call(env) 22 | end 23 | 24 | private 25 | 26 | # Force Vagrant::Bundler#init! to be enabled 27 | # @return [Hash Object>] 28 | def env_for_restarted_process 29 | { 30 | "VAGRANT_INTERNAL_BUNDLERIZED" => nil, 31 | "VAGRANT_FORCE_BUNDLER" => "1", 32 | } 33 | end 34 | 35 | def restart 36 | puts "Restarting vagrant..." 37 | exec(env_for_restarted_process, "#{$0} #{ARGV * ' '}") 38 | end 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /lib/vagrant_plugins/multiplug/config.rb: -------------------------------------------------------------------------------- 1 | require "vagrant" 2 | 3 | module VagrantPlugins 4 | module Multiplug 5 | class Config < Vagrant.plugin("2", :config) 6 | def add_dependency(name, version = nil) 7 | dependencies << Dependency.new(name, version) 8 | end 9 | 10 | def dependencies 11 | @dependencies ||= [] 12 | end 13 | end 14 | 15 | class Dependency 16 | attr_reader :name, :version 17 | 18 | def initialize(name, version = nil) 19 | @name = name 20 | @version = version 21 | end 22 | 23 | # @note ::Vagrant.has_plugin?(@name, @version) cannot be used because it looks up from caches 24 | def installed? 25 | `vagrant plugin list`.each_line.any? do |line| 26 | if @version 27 | line == "#{@name} (#{@version})\n" 28 | else 29 | line.start_with?("#{@name} (") 30 | end 31 | end 32 | end 33 | 34 | # @return [String] Command-line options for `vagrant plugin install NAME` 35 | def options 36 | if @version 37 | "--plugin-version #{@version}" 38 | end 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /lib/vagrant_plugins/multiplug/plugin.rb: -------------------------------------------------------------------------------- 1 | require "vagrant" 2 | 3 | module VagrantPlugins 4 | module Multiplug 5 | class Plugin < Vagrant.plugin("2") 6 | name "multiplug" 7 | 8 | config(:plugin) do 9 | require_relative "config" 10 | Config 11 | end 12 | 13 | action_hook(:install_plugins, Plugin::ALL_ACTIONS) do |hook| 14 | require_relative "action/install_plugins" 15 | hook.before( 16 | Vagrant::Action::Builtin::ConfigValidate, 17 | VagrantPlugins::Multiplug::Action::InstallPlugins, 18 | ) 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /recipe.yml: -------------------------------------------------------------------------------- 1 | resources: 2 | - type: rbenv_ruby 3 | version: 2.2.0 4 | -------------------------------------------------------------------------------- /vagrant-multiplug.gemspec: -------------------------------------------------------------------------------- 1 | lib = File.expand_path("../lib", __FILE__) 2 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 3 | require "vagrant/multiplug/version" 4 | 5 | Gem::Specification.new do |spec| 6 | spec.name = "vagrant-multiplug" 7 | spec.version = Vagrant::Multiplug::VERSION 8 | spec.authors = ["Ryo Nakamura"] 9 | spec.email = ["r7kamura@gmail.com"] 10 | spec.summary = "Vagrant plug-in to manage plug-in dependencies." 11 | spec.homepage = "https://github.com/r7kamura/vagrant-multiplug" 12 | spec.license = "MIT" 13 | 14 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 15 | spec.require_paths = ["lib"] 16 | 17 | spec.add_development_dependency "bundler" 18 | spec.add_development_dependency "rake", "~> 10.0" 19 | end 20 | --------------------------------------------------------------------------------