vagrant-exec 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ # We depend on Vagrant for development, but we don't add it as a
7
+ # gem dependency because we expect to be installed within the
8
+ # Vagrant environment itself using `vagrant plugin`.
9
+ gem 'vagrant', git: 'git://github.com/mitchellh/vagrant.git'
10
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013-2013 Alex Rodionov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ vagrant-exec
2
+ ===============
3
+
4
+ Vagrant plugin to execute commands within the context of VM synced directory.
5
+
6
+ [![Gem Version](https://badge.fury.io/rb/vagrant-exec.png)](http://badge.fury.io/rb/vagrant-exec)
7
+
8
+ Description
9
+ -----------
10
+
11
+ You will probably use the plugin if you don't want to SSH into the box to execute commands simply because your machine environment is already configured (e.g. I use ZSH and TextMate bundles to run specs/features).
12
+
13
+ Example
14
+ -------
15
+
16
+ ```shell
17
+ ➜ vagrant exec pwd
18
+ /vagrant
19
+ ```
20
+
21
+ Installation
22
+ -------
23
+
24
+ ```shell
25
+ ➜ vagrant plugin install vagrant-exec
26
+ ```
27
+
28
+ Configuration
29
+ -------------
30
+
31
+ The root directory can be configured using Vagrantfile.
32
+
33
+ ```ruby
34
+ Vagrant.configure('2') do |config|
35
+ config.vm.box = 'precise32'
36
+ config.exec.folder = '/custom'
37
+ end
38
+ ```
39
+
40
+ You can also enable bundler to prepend each command with `bundle exec` (note, that it won't be done for commands like `bundle install`).
41
+
42
+ ```ruby
43
+ Vagrant.configure('2') do |config|
44
+ config.vm.box = 'precise32'
45
+ config.exec.bundler = true
46
+ end
47
+ ```
48
+
49
+ Acceptance tests
50
+ ----------------
51
+
52
+ Before running features, you'll need to bootstrap box.
53
+
54
+ ```shell
55
+ ➜ bundle exec rake features:bootstrap
56
+ ➜ bundle exec rake features:run
57
+ ```
58
+
59
+ Note on Patches/Pull Requests
60
+ -----------------------------
61
+
62
+ * Fork the project.
63
+ * Make your feature addition or bug fix.
64
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
65
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
66
+ * Send me a pull request. Bonus points for topic branches.
67
+
68
+ Copyright
69
+ ---------
70
+
71
+ Copyright (c) 2013-2013 Alex Rodionov. See LICENSE.md for details.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ require 'cucumber/rake/task'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ namespace :features do
6
+ task(:bootstrap) do
7
+ # download and add box for acceptance tests
8
+ system("bundle exec vagrant box add precise32 http://files.vagrantup.com/precise32.box")
9
+ end
10
+
11
+ Cucumber::Rake::Task.new(:run) do |t|
12
+ t.cucumber_opts = %w(--format pretty)
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ Given(/^I have default Vagrantfile$/) do
2
+ vagrantfile = <<-RUBY
3
+ Vagrant.require_plugin 'vagrant-exec'
4
+
5
+ Vagrant.configure('2') do |config|
6
+ config.vm.box = 'precise32'
7
+ end
8
+ RUBY
9
+ step 'a file named "Vagrantfile" with:', vagrantfile
10
+ end
11
+
12
+ Given(/^I set vagrant-exec folder to (.+)$/) do |folder|
13
+ config = <<-RUBY
14
+
15
+ Vagrant.configure('2') do |config|
16
+ config.exec.folder = #{folder}
17
+ end
18
+ RUBY
19
+ step 'I append to "Vagrantfile" with:', config
20
+ end
21
+
22
+ Given(/^I set vagrant-exec bundler to (.+)$/) do |bundler|
23
+ config = <<-RUBY
24
+
25
+ Vagrant.configure('2') do |config|
26
+ config.exec.bundler = #{bundler}
27
+ end
28
+ RUBY
29
+ step 'I append to "Vagrantfile" with:', config
30
+ end
@@ -0,0 +1,11 @@
1
+ require 'aruba/cucumber'
2
+
3
+ Before do
4
+ # VM start takes a long time
5
+ @aruba_timeout_seconds = 60
6
+ end
7
+
8
+ After do
9
+ # halt VM
10
+ system "cd tmp/aruba; bundle exec vagrant halt &> /dev/null"
11
+ end
@@ -0,0 +1,61 @@
1
+ @no-clobber
2
+ Feature: vagrant-exec
3
+ In order to execute commands in Vagrant box
4
+ Within context of root synced folder
5
+ As a developer using vagrant-exec plugin
6
+ I want to use "vagrant exec" command
7
+ And be able to customize folder
8
+ And prepend commands with "bundle exec"
9
+ Using Vagrantfile configuraiotn
10
+
11
+ Background:
12
+ Given I have default Vagrantfile
13
+
14
+ Scenario: uses /vagrant as default folder
15
+ Given I run `bundle exec vagrant up`
16
+ When I run `bundle exec vagrant exec pwd`
17
+ Then the exit status should be 0
18
+ And the output should contain "/vagrant"
19
+
20
+ Scenario: can use custom folder
21
+ Given I set vagrant-exec folder to "/tmp"
22
+ And I run `bundle exec vagrant up`
23
+ When I run `bundle exec vagrant exec pwd`
24
+ Then the exit status should be 0
25
+ And the output should contain "/tmp"
26
+
27
+ Scenario: raises error if folder is improperly set
28
+ Given I set vagrant-exec folder to true
29
+ And I run `bundle exec vagrant up`
30
+ Then the exit status should not be 0
31
+ And the output should contain "folder should be a string"
32
+
33
+ Scenario: does not use bundler by default
34
+ Given I run `bundle exec vagrant up`
35
+ When I run `bundle exec vagrant exec pwd`
36
+ Then the output should not contain "bundle exec"
37
+
38
+ # we don't have bundler in box
39
+ Scenario: can use bundler
40
+ Given I set vagrant-exec bundler to true
41
+ And I run `bundle exec vagrant up`
42
+ When I run `bundle exec vagrant exec pwd`
43
+ Then the exit status should not be 0
44
+ And the output should contain "bundle: command not found"
45
+
46
+ Scenario: does not use bundler for bundle commands
47
+ Given I set vagrant-exec bundler to true
48
+ And I run `bundle exec vagrant up`
49
+ When I run `bundle exec vagrant exec bundle install`
50
+ Then the output should not contain "bundle exec bundle install"
51
+
52
+ Scenario: raises error if bundler is improperly set
53
+ Given I set vagrant-exec bundler to "true"
54
+ When I run `bundle exec vagrant up`
55
+ Then the exit status should not be 0
56
+ And the output should contain "bundler should be boolean"
57
+
58
+ Scenario: can use custom VM
59
+ Given I run `bundle exec vagrant up`
60
+ When I run `bundle exec vagrant exec --machine vm pwd`
61
+ And the output should contain "machine with the name 'vm' was not found"
@@ -0,0 +1,41 @@
1
+ module VagrantPlugins
2
+ module Exec
3
+ class Command < Vagrant.plugin(2, :command)
4
+
5
+ def execute
6
+ options = {}
7
+
8
+ opts = OptionParser.new do | o |
9
+ o.banner = 'Usage: vagrant exec [options] <command>'
10
+ o.separator ''
11
+
12
+ o.on('-m', '--machine VM', 'VM name to use.') do | vm |
13
+ options[:machine] = vm
14
+ end
15
+ end
16
+
17
+ # Parse the options
18
+ argv = parse_options(opts)
19
+ return unless argv
20
+
21
+ # Execute the actual SSH
22
+ with_target_vms(options[:machine], single_target: true) do | vm |
23
+ vm.config.exec.finalize! # TODO: do we have to call it explicitly?
24
+
25
+ plain = argv.join(' ')
26
+ command = "cd #{vm.config.exec.folder}; "
27
+ if vm.config.exec.bundler && !(plain =~ /^bundle /)
28
+ command << 'bundle exec '
29
+ end
30
+ command << plain
31
+ @logger.debug("Executing single command on remote machine: #{command}")
32
+ env = vm.action(:ssh_run, ssh_run_command: command)
33
+
34
+ status = env[:ssh_run_exit_status] || 0
35
+ return status
36
+ end
37
+ end
38
+
39
+ end # Command
40
+ end # Exec
41
+ end # VagrantPlugins
@@ -0,0 +1,27 @@
1
+ module VagrantPlugins
2
+ module Exec
3
+ class Config < Vagrant.plugin(2, :config)
4
+
5
+ attr_accessor :folder
6
+ attr_accessor :bundler
7
+
8
+ def initialize
9
+ @folder = UNSET_VALUE
10
+ @bundler = UNSET_VALUE
11
+ end
12
+
13
+ def validate(_)
14
+ return { 'exec' => ['folder should be a string'] } unless @folder.is_a?(String)
15
+ return { 'exec' => ['bundler should be boolean'] } unless [true, false].include?(@bundler)
16
+
17
+ {}
18
+ end
19
+
20
+ def finalize!
21
+ @folder = '/vagrant' if @folder == UNSET_VALUE
22
+ @bundler = false if @bundler == UNSET_VALUE
23
+ end
24
+
25
+ end # Config
26
+ end # Exec
27
+ end # VagrantPlugins
@@ -0,0 +1,20 @@
1
+ module VagrantPlugins
2
+ module Exec
3
+ class Plugin < Vagrant.plugin(2)
4
+
5
+ name 'Vagrant Exec'
6
+ description 'Plugin allows to execute commands within the context of synced folder.'
7
+
8
+ config :exec do
9
+ require_relative 'config'
10
+ Config
11
+ end
12
+
13
+ command :exec do
14
+ require_relative 'command'
15
+ Command
16
+ end
17
+
18
+ end # Plugin
19
+ end # Exec
20
+ end # VagrantPlugins
@@ -0,0 +1,7 @@
1
+ module VagrantPlugins
2
+ module Exec
3
+
4
+ VERSION = '0.1.0'
5
+
6
+ end # Exec
7
+ end # VagrantPlugins
@@ -0,0 +1,4 @@
1
+ require 'vagrant'
2
+
3
+ require 'vagrant-exec/plugin'
4
+ require 'vagrant-exec/version'
@@ -0,0 +1,21 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require 'vagrant-exec/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'vagrant-exec'
6
+ s.version = VagrantPlugins::Exec::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.author = 'Alex Rodionov'
9
+ s.email = 'p0deje@gmail.com'
10
+ s.homepage = 'http://github.com/p0deje/vagrant-exec'
11
+ s.summary = 'Execute commands in Vagrant synced folder'
12
+ s.description = 'Vagrant plugin to execute commands within the context of VM synced folder'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = %w(lib)
18
+
19
+ s.add_development_dependency 'aruba'
20
+ s.add_development_dependency 'rake'
21
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-exec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alex Rodionov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aruba
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Vagrant plugin to execute commands within the context of VM synced folder
47
+ email: p0deje@gmail.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - Gemfile
53
+ - LICENSE.md
54
+ - README.md
55
+ - Rakefile
56
+ - features/step_definitions/steps.rb
57
+ - features/support/env.rb
58
+ - features/vagrant-exec.feature
59
+ - lib/vagrant-exec.rb
60
+ - lib/vagrant-exec/command.rb
61
+ - lib/vagrant-exec/config.rb
62
+ - lib/vagrant-exec/plugin.rb
63
+ - lib/vagrant-exec/version.rb
64
+ - vagrant-exec.gemspec
65
+ homepage: http://github.com/p0deje/vagrant-exec
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ segments:
78
+ - 0
79
+ hash: 612892604228850569
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ segments:
87
+ - 0
88
+ hash: 612892604228850569
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.23
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Execute commands in Vagrant synced folder
95
+ test_files:
96
+ - features/step_definitions/steps.rb
97
+ - features/support/env.rb
98
+ - features/vagrant-exec.feature