vagrant-triggers 0.4.1 → 0.4.2
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 +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/README.md +14 -1
- data/lib/vagrant-triggers/dsl.rb +24 -10
- data/lib/vagrant-triggers/plugin.rb +2 -0
- data/lib/vagrant-triggers/version.rb +1 -1
- data/locales/en.yml +2 -0
- data/spec/vagrant-triggers/dsl_spec.rb +21 -5
- data/vagrant-triggers.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20f85521449cec74e8c6c0947943879e3464e031
|
4
|
+
data.tar.gz: 60dd75ac51dd416be9c09262b612bc9499d65ef8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bb36d46e8cd09f65e8bb0f7e3eb74d1ac3d92857a0a3b9ce51fb3d1a2d2b9849573597b5f3cdf64b34c26c90f29c9b841e1b5e5fe9672f0764ebcd9a0c95630
|
7
|
+
data.tar.gz: 448e39b6038ef926e3d95c3d1abe7d7927b3b5e86e8062ea0a7fbc61f33673eb46c8787668f7c41fb4b674fa1ed4c62b82eca9d0ff62741bc682054d513f6008
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.4.2 (September 12, 2014)
|
2
|
+
|
3
|
+
IMPROVEMENTS:
|
4
|
+
|
5
|
+
- Use Vagrant communicator interface for running remote commands [(#17)](https://github.com/emyl/vagrant-triggers/issues/17)
|
6
|
+
- Allow options to be overridden by a single command.
|
7
|
+
|
1
8
|
## 0.4.1 (June 20, 2014)
|
2
9
|
|
3
10
|
BUG FIXES:
|
data/README.md
CHANGED
@@ -46,7 +46,7 @@ The first argument is the command in which the trigger will be tied. It could be
|
|
46
46
|
### Options
|
47
47
|
|
48
48
|
* ```:append_to_path => ["dir", "dir"]```: additional places where looking for scripts. See [this wiki page](https://github.com/emyl/vagrant-triggers/wiki/The-:append_to_path-option) for details.
|
49
|
-
* ```:force => true```: continue even one of the scripts fails (exits with non-zero code)
|
49
|
+
* ```:force => true```: continue even if one of the scripts fails (exits with non-zero code)
|
50
50
|
* ```:stdout => true```: display script output
|
51
51
|
* ```:vm => ["vm1", /vm[2-3]/]```: fire only for matching virtual machines. Value can be a string, a regexp or an array of strings and/or regexps.
|
52
52
|
|
@@ -60,6 +60,19 @@ For additional details you can take a look to the [VagrantPlugins::Triggers::DSL
|
|
60
60
|
|
61
61
|
Triggers won't run if ```VAGRANT_NO_TRIGGERS``` environment variable is set.
|
62
62
|
|
63
|
+
## A simple example
|
64
|
+
|
65
|
+
Cleanup some temporary files after machine destroy:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
|
69
|
+
Vagrant.configure("2") do |config|
|
70
|
+
config.trigger.after :destroy do
|
71
|
+
run "rm -Rf tmp/*"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
63
76
|
## A more detailed example
|
64
77
|
|
65
78
|
In the following example a VirtualBox VM (not managed by Vagrant) will be tied to the machine defined in ```Vagrantfile```, to make so that it follows its lifecycle:
|
data/lib/vagrant-triggers/dsl.rb
CHANGED
@@ -18,8 +18,8 @@ module VagrantPlugins
|
|
18
18
|
|
19
19
|
def run(raw_command, options = {})
|
20
20
|
info I18n.t("vagrant_triggers.action.trigger.executing_command", :command => raw_command)
|
21
|
-
command
|
22
|
-
env_backup
|
21
|
+
command = Shellwords.shellsplit(raw_command)
|
22
|
+
env_backup = ENV.to_hash
|
23
23
|
begin
|
24
24
|
build_environment
|
25
25
|
result = Vagrant::Util::Subprocess.execute(command[0], *command[1..-1])
|
@@ -28,18 +28,22 @@ module VagrantPlugins
|
|
28
28
|
ensure
|
29
29
|
ENV.replace(env_backup)
|
30
30
|
end
|
31
|
-
|
32
|
-
raise Errors::CommandFailed, :command => raw_command, :stderr => result.stderr
|
33
|
-
end
|
34
|
-
if @options[:stdout]
|
35
|
-
info I18n.t("vagrant_triggers.action.trigger.command_output", :output => result.stdout)
|
36
|
-
end
|
37
|
-
result.stdout
|
31
|
+
process_result(raw_command, result, @options.merge(options))
|
38
32
|
end
|
39
33
|
alias_method :execute, :run
|
40
34
|
|
41
35
|
def run_remote(raw_command, options = {})
|
42
|
-
|
36
|
+
info I18n.t("vagrant_triggers.action.trigger.executing_remote_command", :command => raw_command)
|
37
|
+
stderr = ""
|
38
|
+
stdout = ""
|
39
|
+
exit_code = @machine.communicate.sudo(raw_command, :elevated => true, :good_exit => (0..255).to_a) do |type, data|
|
40
|
+
if type == :stderr
|
41
|
+
stderr += data
|
42
|
+
elsif type == :stdout
|
43
|
+
stdout += data
|
44
|
+
end
|
45
|
+
end
|
46
|
+
process_result(raw_command, Vagrant::Util::Subprocess::Result.new(exit_code, stdout, stderr), @options.merge(options))
|
43
47
|
end
|
44
48
|
alias_method :execute_remote, :run_remote
|
45
49
|
|
@@ -75,6 +79,16 @@ module VagrantPlugins
|
|
75
79
|
# Add the VAGRANT_NO_TRIGGERS variable to avoid loops
|
76
80
|
ENV["VAGRANT_NO_TRIGGERS"] = "1"
|
77
81
|
end
|
82
|
+
|
83
|
+
def process_result(command, result, options)
|
84
|
+
if result.exit_code != 0 && !options[:force]
|
85
|
+
raise Errors::CommandFailed, :command => command, :stderr => result.stderr
|
86
|
+
end
|
87
|
+
if options[:stdout]
|
88
|
+
info I18n.t("vagrant_triggers.action.trigger.command_output", :output => result.stdout)
|
89
|
+
end
|
90
|
+
result.stdout
|
91
|
+
end
|
78
92
|
end
|
79
93
|
end
|
80
94
|
end
|
data/locales/en.yml
CHANGED
@@ -150,11 +150,27 @@ describe VagrantPlugins::Triggers::DSL do
|
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
-
context "
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
153
|
+
context "run a remote command" do
|
154
|
+
before do
|
155
|
+
Vagrant::Util::Subprocess::Result.stub(:new => result)
|
156
|
+
machine.stub_chain(:communicate, :sudo).and_return(0)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should raise an error if executed command exits with non-zero code" do
|
160
|
+
result.stub(:exit_code => 1)
|
161
|
+
expect { @dsl.run_remote(@command) }.to raise_error(VagrantPlugins::Triggers::Errors::CommandFailed)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "shouldn't raise an error if executed command exits with non-zero code but :force option was specified" do
|
165
|
+
dsl = described_class.new(ui, machine, :force => true)
|
166
|
+
result.stub(:exit_code => 1)
|
167
|
+
expect { dsl.run_remote(@command) }.not_to raise_error()
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should display output if :stdout option was specified" do
|
171
|
+
dsl = described_class.new(ui, machine, :stdout => true)
|
172
|
+
ui.should_receive(:info).with(/Some output/)
|
173
|
+
dsl.run_remote(@command)
|
158
174
|
end
|
159
175
|
end
|
160
176
|
end
|
data/vagrant-triggers.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-triggers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emiliano Ticci
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - <
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - <
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3'
|
55
55
|
description: This plugin allow the definition of arbitrary scripts that will run on
|
56
56
|
the host before and/or after Vagrant commands.
|
57
57
|
email: emiticci@gmail.com
|