vagrant-lifecycle 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +15 -7
- data/lib/vagrant-lifecycle/command.rb +28 -6
- data/lib/vagrant-lifecycle/config.rb +0 -1
- data/lib/vagrant-lifecycle/middleware.rb +1 -43
- data/lib/vagrant-lifecycle/plugin.rb +7 -9
- data/lib/vagrant-lifecycle/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5611fea343055e79d06bb2a9133d859fecdecd9a
|
4
|
+
data.tar.gz: e7b510084e3d9a4b1fbf05f9f5317fed57265012
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a72769bc4e0a041db10cee8cd21dda552b09d1e4104c923cd2f971cef0274760aaa5e4066632c1404af206b17c5f806aa6404243b3762e2a5ef33923dcc1b95
|
7
|
+
data.tar.gz: b93ff762ce27e57bb02140b5c737b00c8083712d5319ce176773161d5d8e5ddbf4c4ad58fccf95aec19444c5774d272d2af74f7f8874f03b2135fc666add63d7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
Vagrant Lifecycle is a Vagrant plugin that allows execution of custom provisioning events for the Chef provisioners.
|
4
4
|
|
5
|
+
The primarily goal of this plugin is to ease the development and testing of Chef recipes intended for use on services
|
6
|
+
like AWS OpsWorks.
|
7
|
+
|
5
8
|
## Installation
|
6
9
|
|
7
10
|
1. Install the latest version of [Vagrant](https://www.vagrantup.com/downloads.html)
|
@@ -52,9 +55,15 @@ You can execute provisioning on the specific lifecycle event via command (for ex
|
|
52
55
|
$ vagrant lifecycle -e deploy
|
53
56
|
```
|
54
57
|
|
55
|
-
|
58
|
+
### Usage with other Vagrant plugins
|
59
|
+
|
60
|
+
Currently executed lifecycle event name is available in other Vagrant plugin's middlewares through `:lifecycle_event`
|
61
|
+
key of the environment hash. Please note that this key will not be set during regular provision even if the
|
62
|
+
`lifecycle.default_event` is configured.
|
63
|
+
|
64
|
+
### More examples
|
56
65
|
|
57
|
-
|
66
|
+
#### Evaluate run list based on lifecycle event and node roles
|
58
67
|
|
59
68
|
Example Vagrantfile configuration section:
|
60
69
|
|
@@ -98,7 +107,7 @@ Vagrant.configure("2") do |config|
|
|
98
107
|
end
|
99
108
|
```
|
100
109
|
|
101
|
-
|
110
|
+
#### Require additional parameter(s) for a specific lifecycle event
|
102
111
|
|
103
112
|
Example Vagrantfile configuration section:
|
104
113
|
|
@@ -116,11 +125,11 @@ Vagrant.configure("2") do |config|
|
|
116
125
|
end
|
117
126
|
parser.parse!
|
118
127
|
end
|
119
|
-
opt_parser.program_name="vagrant -e deploy"
|
128
|
+
opt_parser.program_name="vagrant lifecycle -e deploy"
|
120
129
|
|
121
130
|
if options.empty?
|
122
131
|
puts opt_parser.help
|
123
|
-
exit
|
132
|
+
exit 1
|
124
133
|
end
|
125
134
|
|
126
135
|
unless options.key?(:application)
|
@@ -147,11 +156,10 @@ Sample usage:
|
|
147
156
|
$ vagrant lifecycle -e deploy -a really_cool_app
|
148
157
|
```
|
149
158
|
|
150
|
-
|
159
|
+
#### Use specific machine info
|
151
160
|
|
152
161
|
Example Vagrantfile configuration section:
|
153
162
|
|
154
|
-
|
155
163
|
```ruby
|
156
164
|
Vagrant.configure("2") do |config|
|
157
165
|
config.lifecycle.events = {
|
@@ -1,7 +1,3 @@
|
|
1
|
-
require "vagrant-lifecycle/version"
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
|
5
1
|
module VagrantPlugins
|
6
2
|
module Lifecycle
|
7
3
|
class Command < Vagrant.plugin(2, :command)
|
@@ -9,11 +5,37 @@ module VagrantPlugins
|
|
9
5
|
"provisions the vagrant machine using a custom lifecycle event"
|
10
6
|
end
|
11
7
|
|
8
|
+
# Like OptionParser.order!, but leave any unrecognized --switches alone
|
9
|
+
def order_recognized!(parser, args)
|
10
|
+
extra_opts = []
|
11
|
+
begin
|
12
|
+
parser.order!(args) {|a| extra_opts << a}
|
13
|
+
rescue OptionParser::InvalidOption => e
|
14
|
+
extra_opts << e.args[0]
|
15
|
+
retry
|
16
|
+
end
|
17
|
+
args[0, 0] = extra_opts
|
18
|
+
end
|
19
|
+
|
12
20
|
def execute
|
13
|
-
|
21
|
+
options = Hash.new
|
22
|
+
opt_parser = OptionParser.new do |parser|
|
23
|
+
parser.on("-e", "--event EVENT", "Lifecycle event to execute") do |p|
|
24
|
+
options[:event] = p
|
25
|
+
end
|
26
|
+
order_recognized!(parser, ARGV)
|
27
|
+
end
|
28
|
+
opt_parser.program_name="vagrant lifecycle"
|
29
|
+
|
30
|
+
unless options.key?(:event)
|
31
|
+
@env.ui.error "Lifecycle event parameter missing!"
|
32
|
+
puts opt_parser.help
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
lifecycle_event = options[:event]
|
14
36
|
|
15
37
|
with_target_vms([], reverse: true) do |machine|
|
16
|
-
machine.action(:provision)
|
38
|
+
machine.action(:provision, {:lifecycle_event => lifecycle_event})
|
17
39
|
end
|
18
40
|
|
19
41
|
exit 0
|
@@ -1,19 +1,5 @@
|
|
1
|
-
require "vagrant-lifecycle/version"
|
2
|
-
require "singleton"
|
3
|
-
require 'json'
|
4
|
-
|
5
1
|
module VagrantPlugins
|
6
2
|
module Lifecycle
|
7
|
-
class MiddleWareConfig
|
8
|
-
include Singleton
|
9
|
-
|
10
|
-
attr_accessor :enabled
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@enabled = false
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
3
|
class MiddleWare
|
18
4
|
def initialize(app, env)
|
19
5
|
@app = app
|
@@ -22,36 +8,8 @@ module VagrantPlugins
|
|
22
8
|
@logger = Log4r::Logger.new("vagrant::lifecycle::#{klass}")
|
23
9
|
end
|
24
10
|
|
25
|
-
# Like OptionParser.order!, but leave any unrecognized --switches alone
|
26
|
-
def order_recognized!(parser, args)
|
27
|
-
extra_opts = []
|
28
|
-
begin
|
29
|
-
parser.order!(args) {|a| extra_opts << a}
|
30
|
-
rescue OptionParser::InvalidOption => e
|
31
|
-
extra_opts << e.args[0]
|
32
|
-
retry
|
33
|
-
end
|
34
|
-
args[0, 0] = extra_opts
|
35
|
-
end
|
36
|
-
|
37
11
|
def call(env)
|
38
|
-
|
39
|
-
options = Hash.new
|
40
|
-
opts = OptionParser.new do |parser|
|
41
|
-
parser.on("-e", "--event EVENT", "Lifecycle event to execute") do |p|
|
42
|
-
options[:event] = p
|
43
|
-
end
|
44
|
-
order_recognized!(parser, ARGV)
|
45
|
-
end
|
46
|
-
|
47
|
-
unless options.key?(:event)
|
48
|
-
env[:ui].error "Lifecycle event parameter missing!"
|
49
|
-
env[:interrupted] = true
|
50
|
-
end
|
51
|
-
event = options[:event]
|
52
|
-
else
|
53
|
-
event = env[:machine].config.lifecycle.default_event
|
54
|
-
end
|
12
|
+
event = env[:lifecycle_event] || env[:machine].config.lifecycle.default_event || nil
|
55
13
|
|
56
14
|
if event.nil?
|
57
15
|
@app.call(env)
|
@@ -1,13 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
|
5
|
-
require 'json'
|
1
|
+
require 'vagrant-lifecycle/command'
|
2
|
+
require 'vagrant-lifecycle/config'
|
3
|
+
require 'vagrant-lifecycle/middleware'
|
4
|
+
require 'vagrant-lifecycle/version'
|
6
5
|
|
7
6
|
module VagrantPlugins
|
8
7
|
module Lifecycle
|
9
8
|
class Plugin < Vagrant.plugin(2)
|
10
|
-
name
|
9
|
+
name 'Lifecycle Plugin'
|
11
10
|
|
12
11
|
def self.provision
|
13
12
|
Vagrant::Action::Builder.new.tap do |b|
|
@@ -17,17 +16,16 @@ module VagrantPlugins
|
|
17
16
|
|
18
17
|
[:machine_action_up, :machine_action_reload, :machine_action_provision].each do |action|
|
19
18
|
action_hook(:lifecycle_provision, action) do |hook|
|
20
|
-
# hook.after(Vagrant::Action::Builtin::ConfigValidate, Plugin.provision_init)
|
21
19
|
hook.before(Vagrant::Action::Builtin::Provision, Plugin.provision)
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
25
|
-
command
|
23
|
+
command 'lifecycle' do
|
26
24
|
Command
|
27
25
|
end
|
28
26
|
|
29
27
|
config(:lifecycle) do
|
30
|
-
require_relative
|
28
|
+
require_relative 'config'
|
31
29
|
Config
|
32
30
|
end
|
33
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-lifecycle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikola Stojiljkovic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|