vagrant-environments 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.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +13 -0
- data/LICENSE.md +20 -0
- data/README.md +186 -0
- data/Rakefile +20 -0
- data/cucumber.yml +1 -0
- data/features/step_definitions/steps.rb +15 -0
- data/features/support/env.rb +17 -0
- data/features/vagrant-exec.feature +43 -0
- data/features/vagrant-exec/binstubs.feature +137 -0
- data/features/vagrant-exec/directory.feature +46 -0
- data/features/vagrant-exec/environment_variables.feature +68 -0
- data/features/vagrant-exec/prepend.feature +69 -0
- data/features/vagrant-exec/validations.feature +34 -0
- data/lib/vagrant-environments.rb +6 -0
- data/lib/vagrant-environments/plugin.rb +22 -0
- data/lib/vagrant-environments/version.rb +7 -0
- data/vagrant-environments.gemspec +20 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b1cfdb945660ce9eae0ce0ce88bfe3f6d565291b
|
4
|
+
data.tar.gz: 0680f875bb88da4e318457b67b210a82a223cfd2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5d04eae8f840bbe4276953b0364101545c5241d185fb65d2bff031f51b9a006786b63d0d0bac6382bfe34ff3b6681a13e2efb720b70440c9e91e4562fa4430db
|
7
|
+
data.tar.gz: 92500203c2972e1fa9b34835761a14adc33b21534c0f0856738fd106e6ef563e85a5725c9cde4970a7b7ff09286579bee55ffb375477a8d2938586568f2db420
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-dev
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
# We depend on Vagrant for development, but we don't add it as a
|
5
|
+
# gem dependency because we expect to be installed within the
|
6
|
+
# Vagrant environment itself using `vagrant plugin`.
|
7
|
+
gem 'vagrant', git: 'git://github.com/mitchellh/vagrant.git'
|
8
|
+
gem 'pry'
|
9
|
+
end
|
10
|
+
|
11
|
+
group :plugins do
|
12
|
+
gemspec
|
13
|
+
end
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013-2104 Igor 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,186 @@
|
|
1
|
+
vagrant-exec [](http://badge.fury.io/rb/vagrant-exec)
|
2
|
+
===============
|
3
|
+
|
4
|
+
Vagrant plugin to execute commands within the context of VM synced directory.
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
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).
|
10
|
+
|
11
|
+
Installation
|
12
|
+
------------
|
13
|
+
|
14
|
+
```bash
|
15
|
+
➜ vagrant plugin install vagrant-exec
|
16
|
+
```
|
17
|
+
|
18
|
+
Example
|
19
|
+
-------
|
20
|
+
|
21
|
+
```bash
|
22
|
+
➜ vagrant exec pwd
|
23
|
+
/vagrant
|
24
|
+
```
|
25
|
+
|
26
|
+
Configuration
|
27
|
+
-------------
|
28
|
+
|
29
|
+
vagrant-exec has only one configuration option for Vagrantfile, which allows you to alter the behavior of all or specific commands.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Vagrant.configure('2') do |config|
|
33
|
+
config.vm.box = 'precise32'
|
34
|
+
config.exec.commands '*', directory: '/tmp'
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
Commands can either be:
|
39
|
+
|
40
|
+
* `"*"` (wildcard) - apply options to all the commands
|
41
|
+
* `"command"` (string) - apply options for specific commands
|
42
|
+
* `%w(command1 command2)` (array) - apply options to all commands in array
|
43
|
+
|
44
|
+
Configuration options are merged, so if you specify single command in several places, all the option will be applied. The only exception is `:directory`, which is applied only once and in reverse order (i.e. the last set is used).
|
45
|
+
|
46
|
+
### Directory
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
Vagrant.configure('2') do |config|
|
50
|
+
config.vm.box = 'precise32'
|
51
|
+
|
52
|
+
# Make /tmp working directory for all the commands:
|
53
|
+
# ➜ vagrant exec pwd
|
54
|
+
# # is the same as
|
55
|
+
# ➜ vagrant ssh -c "cd /tmp && pwd"
|
56
|
+
config.exec.commands '*', directory: '/tmp'
|
57
|
+
|
58
|
+
# Make /etc working directory for env command:
|
59
|
+
# ➜ vagrant exec env
|
60
|
+
# # is the same as
|
61
|
+
# ➜ vagrant ssh -c "cd /etc && env"
|
62
|
+
config.exec.commands 'env', directory: '/etc'
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
### Prepend
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
Vagrant.configure('2') do |config|
|
70
|
+
config.vm.box = 'precise32'
|
71
|
+
|
72
|
+
# Automatically prepend apt-get command with sudo:
|
73
|
+
# ➜ vagrant exec apt-get install htop
|
74
|
+
# # is the same as
|
75
|
+
# ➜ vagrant ssh -c "cd /vagrant && sudo apt-get install htop"
|
76
|
+
config.exec.commands 'apt-get', prepend: 'sudo'
|
77
|
+
|
78
|
+
# Automatically prepend rails and rspec commands with bundle exec:
|
79
|
+
# ➜ vagrant exec rails c
|
80
|
+
# # is the same as
|
81
|
+
# ➜ vagrant ssh -c "cd /vagrant && bundle exec rails c"
|
82
|
+
#
|
83
|
+
# ➜ vagrant exec rspec spec/
|
84
|
+
# # is the same as
|
85
|
+
# ➜ vagrant ssh -c "cd /vagrant && bundle exec rspec spec/"
|
86
|
+
config.exec.commands %w(rails rspec), prepend: 'bundle exec'
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
### Environment variables
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
Vagrant.configure('2') do |config|
|
94
|
+
config.vm.box = 'precise32'
|
95
|
+
|
96
|
+
# Automatically export environment variables for ruby command:
|
97
|
+
# ➜ vagrant exec ruby -e 'puts 1'
|
98
|
+
# # is the same as
|
99
|
+
# ➜ vagrant ssh -c "cd /vagrant && export RUBY_GC_MALLOC_LIMIT=100000000 && ruby -e 'puts 1'"
|
100
|
+
config.exec.commands 'ruby', env: { 'RUBY_GC_MALLOC_LIMIT' => 100000000 }
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
Binstubs
|
105
|
+
----------------
|
106
|
+
|
107
|
+
It is possible can generate binstubs for all your configured commands. You might want to do this to avoid typing `vagrant exec` every time before command, or if you want integrate your flow in editor (e.g. running tests from editor).
|
108
|
+
|
109
|
+
Assuming you have the following configuration:
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
Vagrant.configure('2') do |config|
|
113
|
+
config.vm.box = 'precise32'
|
114
|
+
config.exec.commands 'bundle'
|
115
|
+
config.exec.commands %w(rails rake), prepend: 'bundle exec'
|
116
|
+
config.exec.commands %w(rspec cucumber), prepend: 'spring'
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
You can generate binstubs for each command:
|
121
|
+
|
122
|
+
```bash
|
123
|
+
➜ vagrant exec --binstubs
|
124
|
+
Generated binstub for bundle in bin/bundle.
|
125
|
+
Generated binstub for cucumber in bin/cucumber.
|
126
|
+
Generated binstub for rails in bin/rails.
|
127
|
+
Generated binstub for rake in bin/rake.
|
128
|
+
Generated binstub for rspec in bin/rspec.
|
129
|
+
```
|
130
|
+
|
131
|
+
Now you can use `bin/cucumber` instead of `vagrant exec cucumber` to execute commands in VM. All your configuration (directory, environment variables, prepend) will still be used.
|
132
|
+
|
133
|
+
Since binstubs use plain SSH to connect to VM, it creates connection much faster because Vagrant is not invoked:
|
134
|
+
|
135
|
+
```bash
|
136
|
+
➜ time bin/echo 1
|
137
|
+
0.28 real
|
138
|
+
➜ time vagrant exec echo 1
|
139
|
+
2.84 real
|
140
|
+
```
|
141
|
+
|
142
|
+
To make plain SSH work, it saves current SSH configuration of Vagrant to temporary file when you run `vagrant exec --binstubs`. This means that if your VM network configuration has changed (IP address, port), you will have to regenerate binstubs again. So far I had no problems with this, but it's not very convenient for sure.
|
143
|
+
|
144
|
+
Moving forward, you can use projects like [direnv](https://github.com/zimbatm/direnv) to add `bin/` to `PATH` and completely forget that you have VM running.
|
145
|
+
|
146
|
+
Testing
|
147
|
+
----------------
|
148
|
+
|
149
|
+
Before running features, you'll need to bootstrap box.
|
150
|
+
|
151
|
+
```bash
|
152
|
+
➜ bundle exec rake features:bootstrap
|
153
|
+
```
|
154
|
+
|
155
|
+
To run features, execute the following rake task.
|
156
|
+
|
157
|
+
```bash
|
158
|
+
➜ bundle exec rake features:run
|
159
|
+
```
|
160
|
+
|
161
|
+
After you're done, remove Vagrant box.
|
162
|
+
|
163
|
+
```bash
|
164
|
+
➜ bundle exec rake features:cleanup
|
165
|
+
```
|
166
|
+
|
167
|
+
To show stdout, add `@announce-stdout` tag to scenario/feature.
|
168
|
+
|
169
|
+
Known issues
|
170
|
+
-----------------------------
|
171
|
+
|
172
|
+
`vagrant-exec` cannot properly handle `-v` in command args (it's caught somewhere before plugin), so executing `vagrant exec ruby -v` will return Vagrant version rather than Ruby. As a workaround, wrap it in quotes: `vagrant exec "ruby -v"`.
|
173
|
+
|
174
|
+
Note on Patches/Pull Requests
|
175
|
+
-----------------------------
|
176
|
+
|
177
|
+
* Fork the project.
|
178
|
+
* Make your feature addition or bug fix.
|
179
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
180
|
+
* 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)
|
181
|
+
* Send me a pull request. Bonus points for topic branches.
|
182
|
+
|
183
|
+
Copyright
|
184
|
+
---------
|
185
|
+
|
186
|
+
Copyright (c) 2013-2014 Alex Rodionov. See LICENSE.md for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require 'cucumber/rake/task'
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
|
5
|
+
namespace :features do
|
6
|
+
desc 'Downloads and adds vagrant box for testing.'
|
7
|
+
task(:bootstrap) do
|
8
|
+
system('bundle exec vagrant box add vagrant_exec http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box')
|
9
|
+
end
|
10
|
+
|
11
|
+
Cucumber::Rake::Task.new(:run) do |t|
|
12
|
+
t.cucumber_opts = %w(--format pretty)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Removes testing vagrant box.'
|
16
|
+
task(:cleanup) do
|
17
|
+
system('bundle exec vagrant destroy -f')
|
18
|
+
system('bundle exec vagrant box remove vagrant_exec virtualbox')
|
19
|
+
end
|
20
|
+
end
|
data/cucumber.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
default: --require features --format html --out results.html --format pretty
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Then(/^SHH subprocess should execute command "(.+)"$/) do |command|
|
2
|
+
ssh = %w(vagrant@127.0.0.1 -p 2200 -o Compression=yes)
|
3
|
+
ssh += %w(-o DSAAuthentication=yes -o LogLevel=FATAL)
|
4
|
+
ssh += %w(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null)
|
5
|
+
ssh += %W(-o IdentitiesOnly=yes -i #{Dir.home}/.vagrant.d/insecure_private_key)
|
6
|
+
ssh += ['-q', '-t', "bash -l -c '#{command.delete("''")}'"]
|
7
|
+
assert_partial_output("Executing SSH in subprocess: #{ssh}", all_output)
|
8
|
+
end
|
9
|
+
|
10
|
+
Then(/^the file "(.+)" should contain result of vagrant ssh-config$/) do |file|
|
11
|
+
# since "bundle exec" adds some output, we actually
|
12
|
+
# assert that file contents are included in stdout
|
13
|
+
step 'I run `bundle exec vagrant ssh-config`'
|
14
|
+
with_file_content(file) { |content| expect(all_stdout).to include(content) }
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
unless `bundle exec vagrant box list`.include?('vagrant_exec')
|
2
|
+
raise 'Box is not added! Run "rake features:bootstrap".'
|
3
|
+
end
|
4
|
+
|
5
|
+
require 'aruba/cucumber'
|
6
|
+
require 'pry-byebug'
|
7
|
+
ENV['VAGRANT_LOG'] = 'info'
|
8
|
+
|
9
|
+
Before do
|
10
|
+
# VM start takes a long time
|
11
|
+
@aruba_timeout_seconds = 60
|
12
|
+
end
|
13
|
+
|
14
|
+
After do
|
15
|
+
# halt VM
|
16
|
+
system 'cd tmp/aruba; bundle exec vagrant halt &> /dev/null'
|
17
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
@no-clobber
|
2
|
+
Feature: vagrant-exec
|
3
|
+
In order to execute commands in Vagrant box
|
4
|
+
Within context of synced folder
|
5
|
+
As a developer using vagrant-exec plugin
|
6
|
+
I want to use "vagrant exec" command
|
7
|
+
|
8
|
+
Background:
|
9
|
+
Given I write to "Vagrantfile" with:
|
10
|
+
"""
|
11
|
+
Vagrant.configure('2') do |config|
|
12
|
+
config.vm.box = 'vagrant_exec'
|
13
|
+
end
|
14
|
+
"""
|
15
|
+
And I run `bundle exec vagrant up`
|
16
|
+
|
17
|
+
Scenario Outline: shows help correctly
|
18
|
+
When I run `bundle exec vagrant exec <args>`
|
19
|
+
Then the output should contain:
|
20
|
+
"""
|
21
|
+
Usage: vagrant exec [options] <command>
|
22
|
+
|
23
|
+
-h, --help Print this help
|
24
|
+
--binstubs Generate binstubs for configured commands
|
25
|
+
"""
|
26
|
+
Examples:
|
27
|
+
| args |
|
28
|
+
| |
|
29
|
+
| -h |
|
30
|
+
| --help |
|
31
|
+
| -h pwd |
|
32
|
+
| --help pwd -h |
|
33
|
+
|
34
|
+
Scenario Outline: passes command arguments correctly
|
35
|
+
When I run `bundle exec vagrant exec <command>`
|
36
|
+
Then SHH subprocess should execute command "cd /vagrant && <command>"
|
37
|
+
Examples:
|
38
|
+
| command |
|
39
|
+
| pwd . |
|
40
|
+
| pwd ~ |
|
41
|
+
| pwd -h |
|
42
|
+
| pwd --blah |
|
43
|
+
| 'pwd -h blah -v blah' |
|
@@ -0,0 +1,137 @@
|
|
1
|
+
@no-clobber
|
2
|
+
Feature: vagrant-exec binstubs
|
3
|
+
In order to easily integrate vagrant-exec into editors/IDEs
|
4
|
+
And significantly increase speed of executing commands in VM
|
5
|
+
As a user
|
6
|
+
I want to be able to generate binstubs for configured commands
|
7
|
+
Which use plan SSH
|
8
|
+
|
9
|
+
Scenario: generates binstubs for each configured command
|
10
|
+
Given I write to "Vagrantfile" with:
|
11
|
+
"""
|
12
|
+
Vagrant.configure('2') do |config|
|
13
|
+
config.vm.box = 'vagrant_exec'
|
14
|
+
config.exec.commands 'echo', directory: '/tmp'
|
15
|
+
config.exec.commands %w(pwd echo), prepend: 'test -d . &&', env: { 'TEST' => 1 }
|
16
|
+
end
|
17
|
+
"""
|
18
|
+
And I run `bundle exec vagrant up`
|
19
|
+
When I run `bundle exec vagrant exec --binstubs`
|
20
|
+
Then the exit status should be 0
|
21
|
+
And the output should contain "Generated binstub for echo in bin/echo."
|
22
|
+
And the output should contain "Generated binstub for pwd in bin/pwd."
|
23
|
+
And a file named "bin/echo" should exist
|
24
|
+
And a file named "bin/pwd" should exist
|
25
|
+
And the mode of filesystem object "bin/echo" should match "755"
|
26
|
+
And the mode of filesystem object "bin/pwd" should match "755"
|
27
|
+
And the file "bin/echo" should contain exactly:
|
28
|
+
"""
|
29
|
+
#!/bin/bash
|
30
|
+
ssh -F .vagrant/ssh_config -q -t default "bash -l -c 'cd /tmp && export TEST=1 && test -d . && echo $@'"
|
31
|
+
|
32
|
+
"""
|
33
|
+
And the file "bin/pwd" should contain exactly:
|
34
|
+
"""
|
35
|
+
#!/bin/bash
|
36
|
+
ssh -F .vagrant/ssh_config -q -t default "bash -l -c 'cd /vagrant && export TEST=1 && test -d . && pwd $@'"
|
37
|
+
|
38
|
+
"""
|
39
|
+
When I run `bin/echo test`
|
40
|
+
Then the exit status should be 0
|
41
|
+
And the output should contain "test"
|
42
|
+
When I run `bin/pwd`
|
43
|
+
Then the exit status should be 0
|
44
|
+
And the output should contain "/vagrant"
|
45
|
+
|
46
|
+
Scenario: dumps vagrant ssh-config to file
|
47
|
+
Given I write to "Vagrantfile" with:
|
48
|
+
"""
|
49
|
+
Vagrant.configure('2') do |config|
|
50
|
+
config.vm.box = 'vagrant_exec'
|
51
|
+
config.exec.commands 'echo'
|
52
|
+
end
|
53
|
+
"""
|
54
|
+
And I run `bundle exec vagrant up`
|
55
|
+
When I run `bundle exec vagrant exec --binstubs`
|
56
|
+
Then a file named ".vagrant/ssh_config" should exist
|
57
|
+
And the file ".vagrant/ssh_config" should contain result of vagrant ssh-config
|
58
|
+
|
59
|
+
Scenario: respects configured shell
|
60
|
+
Given I write to "Vagrantfile" with:
|
61
|
+
"""
|
62
|
+
Vagrant.configure('2') do |config|
|
63
|
+
config.vm.box = 'vagrant_exec'
|
64
|
+
config.ssh.shell = 'zsh -l'
|
65
|
+
config.exec.commands 'echo'
|
66
|
+
end
|
67
|
+
"""
|
68
|
+
And I run `bundle exec vagrant up`
|
69
|
+
When I run `bundle exec vagrant exec --binstubs`
|
70
|
+
Then the file "bin/echo" should contain exactly:
|
71
|
+
"""
|
72
|
+
#!/bin/bash
|
73
|
+
ssh -F .vagrant/ssh_config -q -t default "zsh -l -c 'cd /vagrant && echo $@'"
|
74
|
+
|
75
|
+
"""
|
76
|
+
|
77
|
+
Scenario: escapes double-quotes in command
|
78
|
+
Given I write to "Vagrantfile" with:
|
79
|
+
"""
|
80
|
+
Vagrant.configure('2') do |config|
|
81
|
+
config.vm.box = 'vagrant_exec'
|
82
|
+
config.exec.commands 'echo', env: { 'TEST' => 'one two' }
|
83
|
+
end
|
84
|
+
"""
|
85
|
+
And I run `bundle exec vagrant up`
|
86
|
+
When I run `bundle exec vagrant exec --binstubs`
|
87
|
+
Then the file "bin/echo" should contain exactly:
|
88
|
+
"""
|
89
|
+
#!/bin/bash
|
90
|
+
ssh -F .vagrant/ssh_config -q -t default "bash -l -c 'cd /vagrant && export TEST=\"one two\" && echo $@'"
|
91
|
+
|
92
|
+
"""
|
93
|
+
|
94
|
+
Scenario: skips if no commands are configured
|
95
|
+
Given I write to "Vagrantfile" with:
|
96
|
+
"""
|
97
|
+
Vagrant.configure('2') do |config|
|
98
|
+
config.vm.box = 'vagrant_exec'
|
99
|
+
end
|
100
|
+
"""
|
101
|
+
And I run `bundle exec vagrant up`
|
102
|
+
When I run `bundle exec vagrant exec --binstubs`
|
103
|
+
Then the exit status should be 0
|
104
|
+
And the output should contain "No commands to generate binstubs for."
|
105
|
+
|
106
|
+
Scenario: skips if only splat commands are configured
|
107
|
+
Given I write to "Vagrantfile" with:
|
108
|
+
"""
|
109
|
+
Vagrant.configure('2') do |config|
|
110
|
+
config.vm.box = 'vagrant_exec'
|
111
|
+
config.exec.commands '*', env: { 'TEST' => 'one two' }
|
112
|
+
end
|
113
|
+
"""
|
114
|
+
And I run `bundle exec vagrant up`
|
115
|
+
When I run `bundle exec vagrant exec --binstubs`
|
116
|
+
Then the exit status should be 0
|
117
|
+
And the output should contain "No commands to generate binstubs for."
|
118
|
+
|
119
|
+
Scenario: raises if vagrant is not upped
|
120
|
+
Given I write to "Vagrantfile" with:
|
121
|
+
"""
|
122
|
+
Vagrant.configure('2') do |config|
|
123
|
+
config.vm.box = 'vagrant_exec'
|
124
|
+
end
|
125
|
+
"""
|
126
|
+
When I run `bundle exec vagrant exec --binstubs`
|
127
|
+
Then the exit status should not be 0
|
128
|
+
And the stderr should contain:
|
129
|
+
"""
|
130
|
+
The provider for this Vagrant-managed machine is reporting that it
|
131
|
+
is not yet ready for SSH. Depending on your provider this can carry
|
132
|
+
different meanings. Make sure your machine is created and running and
|
133
|
+
try again. Additionally, check the output of `vagrant status` to verify
|
134
|
+
that the machine is in the state that you expect. If you continue to
|
135
|
+
get this error message, please view the documentation for the provider
|
136
|
+
you're using.
|
137
|
+
"""
|
@@ -0,0 +1,46 @@
|
|
1
|
+
@no-clobber
|
2
|
+
Feature: vagrant-exec directory
|
3
|
+
In order to change the working directory
|
4
|
+
For commands I execute using vagrant-exec
|
5
|
+
As a user
|
6
|
+
I should be able to specify it in Vagrantfile
|
7
|
+
|
8
|
+
Scenario: uses /vagrant as default directory
|
9
|
+
Given I write to "Vagrantfile" with:
|
10
|
+
"""
|
11
|
+
Vagrant.configure('2') do |config|
|
12
|
+
config.vm.box = 'vagrant_exec'
|
13
|
+
end
|
14
|
+
"""
|
15
|
+
And 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 SHH subprocess should execute command "cd /vagrant && pwd"
|
19
|
+
|
20
|
+
Scenario: uses custom directory for all commands
|
21
|
+
Given I write to "Vagrantfile" with:
|
22
|
+
"""
|
23
|
+
Vagrant.configure('2') do |config|
|
24
|
+
config.vm.box = 'vagrant_exec'
|
25
|
+
config.exec.commands '*', directory: '/tmp'
|
26
|
+
end
|
27
|
+
"""
|
28
|
+
And I run `bundle exec vagrant up`
|
29
|
+
When I run `bundle exec vagrant exec pwd`
|
30
|
+
Then the exit status should be 0
|
31
|
+
And SHH subprocess should execute command "cd /tmp && pwd"
|
32
|
+
|
33
|
+
Scenario: uses custom directory for specific commands
|
34
|
+
Given I write to "Vagrantfile" with:
|
35
|
+
"""
|
36
|
+
Vagrant.configure('2') do |config|
|
37
|
+
config.vm.box = 'vagrant_exec'
|
38
|
+
config.exec.commands %w(pwd echo), directory: '/tmp'
|
39
|
+
end
|
40
|
+
"""
|
41
|
+
And I run `bundle exec vagrant up`
|
42
|
+
When I run `bundle exec vagrant exec echo 1`
|
43
|
+
Then SHH subprocess should execute command "cd /tmp && echo 1"
|
44
|
+
When I run `bundle exec vagrant exec env`
|
45
|
+
Then SHH subprocess should execute command "cd /vagrant && env"
|
46
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
@no-clobber
|
2
|
+
Feature: vagrant-exec environment variables
|
3
|
+
In order to automatically set environment variables
|
4
|
+
For commands I execute using vagrant-exec
|
5
|
+
As a user
|
6
|
+
I should be able to specify them in Vagrantfile
|
7
|
+
|
8
|
+
Scenario: exports environment variables for all commands
|
9
|
+
Given I write to "Vagrantfile" with:
|
10
|
+
"""
|
11
|
+
Vagrant.configure('2') do |config|
|
12
|
+
config.vm.box = 'vagrant_exec'
|
13
|
+
config.exec.commands '*', env: { 'TEST1' => true, 'TEST2' => false }
|
14
|
+
end
|
15
|
+
"""
|
16
|
+
And I run `bundle exec vagrant up`
|
17
|
+
When I run `bundle exec vagrant exec pwd`
|
18
|
+
Then the exit status should be 0
|
19
|
+
And SHH subprocess should execute command "cd /vagrant && export TEST1=true && export TEST2=false && pwd"
|
20
|
+
|
21
|
+
Scenario: exports environment variables for specific commands
|
22
|
+
Given I write to "Vagrantfile" with:
|
23
|
+
"""
|
24
|
+
Vagrant.configure('2') do |config|
|
25
|
+
config.vm.box = 'vagrant_exec'
|
26
|
+
config.exec.commands 'cmd', env: { 'TEST1' => 'yo' }
|
27
|
+
config.exec.commands %w(pwd echo), env: { 'TEST2' => true, 'TEST3' => false }
|
28
|
+
end
|
29
|
+
"""
|
30
|
+
And I run `bundle exec vagrant up`
|
31
|
+
When I run `bundle exec vagrant exec cmd`
|
32
|
+
Then SHH subprocess should execute command "cd /vagrant && export TEST1=yo && cmd"
|
33
|
+
When I run `bundle exec vagrant exec pwd`
|
34
|
+
Then SHH subprocess should execute command "cd /vagrant && export TEST2=true && export TEST3=false && pwd"
|
35
|
+
When I run `bundle exec vagrant exec echo 1`
|
36
|
+
Then SHH subprocess should execute command "cd /vagrant && export TEST2=true && export TEST3=false && echo 1"
|
37
|
+
When I run `bundle exec vagrant exec env`
|
38
|
+
Then SHH subprocess should execute command "cd /vagrant && env"
|
39
|
+
|
40
|
+
Scenario: combines environment variables
|
41
|
+
Given I write to "Vagrantfile" with:
|
42
|
+
"""
|
43
|
+
Vagrant.configure('2') do |config|
|
44
|
+
config.vm.box = 'vagrant_exec'
|
45
|
+
config.exec.commands '*', env: { 'TEST1' => true }
|
46
|
+
config.exec.commands 'pwd', env: { 'TEST2' => false }
|
47
|
+
config.exec.commands %w(pwd echo), env: { 'TEST3' => false }
|
48
|
+
end
|
49
|
+
"""
|
50
|
+
And I run `bundle exec vagrant up`
|
51
|
+
When I run `bundle exec vagrant exec pwd`
|
52
|
+
Then SHH subprocess should execute command "cd /vagrant && export TEST1=true && export TEST2=false && export TEST3=false && pwd"
|
53
|
+
When I run `bundle exec vagrant exec echo 1`
|
54
|
+
Then SHH subprocess should execute command "cd /vagrant && export TEST1=true && export TEST3=false && echo 1"
|
55
|
+
When I run `bundle exec vagrant exec env`
|
56
|
+
Then SHH subprocess should execute command "cd /vagrant && export TEST1=true && env"
|
57
|
+
|
58
|
+
Scenario: wraps values with spaces to quotes
|
59
|
+
Given I write to "Vagrantfile" with:
|
60
|
+
"""
|
61
|
+
Vagrant.configure('2') do |config|
|
62
|
+
config.vm.box = 'vagrant_exec'
|
63
|
+
config.exec.commands 'pwd', env: { 'TEST' => 'one two' }
|
64
|
+
end
|
65
|
+
"""
|
66
|
+
And I run `bundle exec vagrant up`
|
67
|
+
When I run `bundle exec vagrant exec pwd`
|
68
|
+
Then SHH subprocess should execute command "cd /vagrant && export TEST="one two" && pwd"
|
@@ -0,0 +1,69 @@
|
|
1
|
+
@no-clobber
|
2
|
+
Feature: vagrant-exec prepend
|
3
|
+
In order to automatically prepend with custom command
|
4
|
+
Commands I execute using vagrant-exec
|
5
|
+
As a user
|
6
|
+
I should be able to specify it in Vagrantfile
|
7
|
+
|
8
|
+
Scenario: prepends all commands
|
9
|
+
Given I write to "Vagrantfile" with:
|
10
|
+
"""
|
11
|
+
Vagrant.configure('2') do |config|
|
12
|
+
config.vm.box = 'vagrant_exec'
|
13
|
+
config.exec.commands '*', prepend: 'echo vagrant-exec &&'
|
14
|
+
end
|
15
|
+
"""
|
16
|
+
And I run `bundle exec vagrant up`
|
17
|
+
When I run `bundle exec vagrant exec pwd`
|
18
|
+
Then the exit status should be 0
|
19
|
+
And SHH subprocess should execute command "cd /vagrant && echo vagrant-exec && pwd"
|
20
|
+
|
21
|
+
Scenario: prepends specific commands
|
22
|
+
Given I write to "Vagrantfile" with:
|
23
|
+
"""
|
24
|
+
Vagrant.configure('2') do |config|
|
25
|
+
config.vm.box = 'vagrant_exec'
|
26
|
+
config.exec.commands 'cmd', prepend: 'echo vagrant-exec1 &&'
|
27
|
+
config.exec.commands %w(pwd echo), prepend: 'echo vagrant-exec2 &&'
|
28
|
+
end
|
29
|
+
"""
|
30
|
+
And I run `bundle exec vagrant up`
|
31
|
+
When I run `bundle exec vagrant exec cmd`
|
32
|
+
Then SHH subprocess should execute command "cd /vagrant && echo vagrant-exec1 && cmd"
|
33
|
+
When I run `bundle exec vagrant exec pwd`
|
34
|
+
Then SHH subprocess should execute command "cd /vagrant && echo vagrant-exec2 && pwd"
|
35
|
+
When I run `bundle exec vagrant exec echo 1`
|
36
|
+
Then SHH subprocess should execute command "cd /vagrant && echo vagrant-exec2 && echo 1"
|
37
|
+
When I run `bundle exec vagrant exec env`
|
38
|
+
Then SHH subprocess should execute command "cd /vagrant && env"
|
39
|
+
|
40
|
+
Scenario: combines prepended
|
41
|
+
Given I write to "Vagrantfile" with:
|
42
|
+
"""
|
43
|
+
Vagrant.configure('2') do |config|
|
44
|
+
config.vm.box = 'vagrant_exec'
|
45
|
+
config.exec.commands '*', prepend: 'echo vagrant-exec1 &&'
|
46
|
+
config.exec.commands 'pwd', prepend: 'echo vagrant-exec2 &&'
|
47
|
+
config.exec.commands %w(pwd echo), prepend: 'echo vagrant-exec3 &&'
|
48
|
+
end
|
49
|
+
"""
|
50
|
+
And I run `bundle exec vagrant up`
|
51
|
+
When I run `bundle exec vagrant exec pwd`
|
52
|
+
Then SHH subprocess should execute command "cd /vagrant && echo vagrant-exec1 && echo vagrant-exec2 && echo vagrant-exec3 && pwd"
|
53
|
+
When I run `bundle exec vagrant exec echo 1`
|
54
|
+
Then SHH subprocess should execute command "cd /vagrant && echo vagrant-exec1 && echo vagrant-exec3 && echo 1"
|
55
|
+
When I run `bundle exec vagrant exec env`
|
56
|
+
Then SHH subprocess should execute command "cd /vagrant && echo vagrant-exec1 && env"
|
57
|
+
|
58
|
+
Scenario: adds prepend only in the end
|
59
|
+
Given I write to "Vagrantfile" with:
|
60
|
+
"""
|
61
|
+
Vagrant.configure('2') do |config|
|
62
|
+
config.vm.box = 'vagrant_exec'
|
63
|
+
config.exec.commands 'pwd', prepend: 'bundle exec'
|
64
|
+
config.exec.commands 'pwd', env: { 'TEST' => true }
|
65
|
+
end
|
66
|
+
"""
|
67
|
+
And I run `bundle exec vagrant up`
|
68
|
+
When I run `bundle exec vagrant exec pwd`
|
69
|
+
Then SHH subprocess should execute command "cd /vagrant && export TEST=true && bundle exec pwd"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
@no-clobber
|
2
|
+
Feature: vagrant-exec validations
|
3
|
+
In order to avoid configuration mistakes for vagrant-exec commands
|
4
|
+
As a user
|
5
|
+
I should see proper validation errors
|
6
|
+
|
7
|
+
Background:
|
8
|
+
Given I write to "Vagrantfile" with:
|
9
|
+
"""
|
10
|
+
Vagrant.configure('2') do |config|
|
11
|
+
config.vm.box = 'vagrant_exec'
|
12
|
+
config.exec.commands true, directory: nil, prepend: true, env: 0
|
13
|
+
end
|
14
|
+
"""
|
15
|
+
|
16
|
+
Scenario: raises error if command is not string or array of strings
|
17
|
+
When I run `bundle exec vagrant up`
|
18
|
+
Then the exit status should not be 0
|
19
|
+
And the output should contain "Commands should be String or Array<String>, received: true"
|
20
|
+
|
21
|
+
Scenario: raises error if directory is improperly set
|
22
|
+
When I run `bundle exec vagrant up`
|
23
|
+
Then the exit status should not be 0
|
24
|
+
And the output should contain ":directory should be String, received: nil"
|
25
|
+
|
26
|
+
Scenario: raises error if prepend is improperly set
|
27
|
+
When I run `bundle exec vagrant up`
|
28
|
+
Then the exit status should not be 0
|
29
|
+
And the output should contain ":prepend should be String, received: true"
|
30
|
+
|
31
|
+
Scenario: raises error if environment variables are improperly set
|
32
|
+
When I run `bundle exec vagrant up`
|
33
|
+
Then the exit status should not be 0
|
34
|
+
And the output should contain ":env should be Hash, received: 0"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Environments
|
3
|
+
class Plugin < Vagrant.plugin(2)
|
4
|
+
|
5
|
+
name 'vagrant-environments'
|
6
|
+
description 'Vagrant plugin to config muiltiple environments (dev, test, stage, prod)'
|
7
|
+
|
8
|
+
config :environments do
|
9
|
+
require_relative 'config'
|
10
|
+
Config
|
11
|
+
end
|
12
|
+
|
13
|
+
config :environment do
|
14
|
+
require_relative 'environment'
|
15
|
+
Environment
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
end # Plugin
|
21
|
+
end # Environments
|
22
|
+
end # VagrantPlugins
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'vagrant-environments/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'vagrant-environments'
|
6
|
+
s.version = VagrantPlugins::Environments::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.author = 'Igor Rodionov'
|
9
|
+
s.email = 'goruha@gmail.com'
|
10
|
+
s.homepage = 'http://github.com/goruha/vagrant-environments'
|
11
|
+
s.summary = 'Allow to config Vagrant work with multiple environments'
|
12
|
+
s.description = 'Vagrant plugin to config muiltiple environments (dev, test, stage, prod)'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
18
|
+
s.require_paths = %w(lib)
|
19
|
+
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-environments
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Igor Rodionov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Vagrant plugin to config muiltiple environments (dev, test, stage, prod)
|
14
|
+
email: goruha@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".gitignore"
|
20
|
+
- ".ruby-version"
|
21
|
+
- CHANGELOG.md
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.md
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- cucumber.yml
|
27
|
+
- features/step_definitions/steps.rb
|
28
|
+
- features/support/env.rb
|
29
|
+
- features/vagrant-exec.feature
|
30
|
+
- features/vagrant-exec/binstubs.feature
|
31
|
+
- features/vagrant-exec/directory.feature
|
32
|
+
- features/vagrant-exec/environment_variables.feature
|
33
|
+
- features/vagrant-exec/prepend.feature
|
34
|
+
- features/vagrant-exec/validations.feature
|
35
|
+
- lib/vagrant-environments.rb
|
36
|
+
- lib/vagrant-environments/plugin.rb
|
37
|
+
- lib/vagrant-environments/version.rb
|
38
|
+
- vagrant-environments.gemspec
|
39
|
+
homepage: http://github.com/goruha/vagrant-environments
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.4.2
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Allow to config Vagrant work with multiple environments
|
63
|
+
test_files: []
|