vagrant-tagprovision 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/README.md +43 -31
- data/Vagrantfile +10 -0
- data/lib/vagrant-tagprovision/action.rb +57 -39
- data/lib/vagrant-tagprovision/config.rb +51 -0
- data/lib/vagrant-tagprovision/plugin.rb +11 -1
- data/lib/vagrant-tagprovision/util.rb +14 -0
- data/lib/vagrant-tagprovision/version.rb +1 -1
- data/lib/vagrant-tagprovision.rb +5 -1
- data/locales/en.yml +6 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2426fbf2e6aad5ce46e1b3bc6f6e59a05fb5ec0
|
4
|
+
data.tar.gz: e7819b73c70ef1b51367df00b474161848ca1010
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ff905a64726fa736c749bf20807f17eb7e16aa1d79b1a86fef8fd260ee249f462df753c155577f75d7e8732afd38da1f018c63e75deb0f7d00ad8194cfc4f0e
|
7
|
+
data.tar.gz: a04add565f33486a176adaeab3e3df7ed457ec81deee48176954630c205418699b2b6372529286d38d08504ff3354222874157308432c3b5242a37db47b2276a
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,57 +1,69 @@
|
|
1
|
-
# Vagrant
|
1
|
+
# Vagrant TagProvision
|
2
2
|
|
3
|
-
This gem is a [Vagrant](http://www.vagrantup.com/) plugin that
|
3
|
+
This gem is a [Vagrant](http://www.vagrantup.com/) plugin that tags and logs provisioning information
|
4
4
|
|
5
|
-
## Setup Pushbullet
|
6
|
-
|
7
|
-
* First get a Pushbullet Account, and add devices to it.
|
8
|
-
- [Pushbullet.com](https://www.pushbullet.com/)
|
9
|
-
* Download the *iOS* app, *Chrome* plugin, *Android* app, and more. Add those to your Pushbullet account.
|
10
|
-
* Get your HTTP API Token: http://pushbullet.com/account
|
11
5
|
|
12
6
|
## Install Plugin
|
13
7
|
|
14
8
|
```bash
|
15
|
-
$ vagrant plugin install vagrant-
|
9
|
+
$ vagrant plugin install vagrant-tagprovision
|
16
10
|
```
|
17
11
|
|
18
12
|
## Plugin Usage
|
19
13
|
|
20
|
-
|
21
|
-
The plugin will create this file for you, but you will have to edit it manually (for now).
|
14
|
+
You will need to create a section in your Vagrantfile to enable this plugin and use the various features.
|
22
15
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
16
|
+
```
|
17
|
+
Vagrant.configure("2") do |config|
|
18
|
+
...
|
19
|
+
config.tagprovision.enabled = true
|
20
|
+
config.tagprovision.log_provision = true
|
21
|
+
config.tagprovision.tag_provision = true
|
22
|
+
config.tagprovision.push_tag = true
|
23
|
+
...
|
28
24
|
end
|
29
25
|
```
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
## Notifications
|
27
|
+
config.tagprovision.enabled - This enables and disables the plugin
|
28
|
+
config.tagprovision.log_provision - This creates an entry in /var/provision_log on the guest machine with the following format:
|
35
29
|
|
36
|
-
|
30
|
+
2016-01-11 11:31:42 +0000 Provisioned a41c6eb98bd069f85bc205fae24298e644a9b877 username
|
37
31
|
|
38
|
-
|
39
|
-
|
40
|
-
- `vagrant up`
|
41
|
-
- `vagrant reload --provision`
|
42
|
-
- `vagrant provision`
|
32
|
+
config.tagprovision.tag_provision - This will create a git tag with provisioning information
|
33
|
+
config.tagprovision.push_tag - This automatically pushes the tag to the origin your current branch is tracking
|
43
34
|
|
44
35
|
## Contributing
|
45
36
|
|
46
37
|
* use feature branches please. Prefer feature/your_feature_name
|
47
38
|
* submit pull requests to the `develop` branch
|
48
39
|
|
40
|
+
### Testing
|
49
41
|
|
50
|
-
|
42
|
+
To install dependencies use:
|
43
|
+
```
|
44
|
+
bundle install
|
45
|
+
```
|
46
|
+
|
47
|
+
Then use
|
48
|
+
```
|
49
|
+
bundle exec vagrant provision
|
50
|
+
```
|
51
|
+
To test on the test VM.
|
51
52
|
|
52
|
-
|
53
|
+
### Building and deploying gem packages
|
53
54
|
|
54
|
-
|
55
|
+
Use
|
56
|
+
|
57
|
+
```
|
58
|
+
rake build
|
59
|
+
```
|
60
|
+
|
61
|
+
Then
|
62
|
+
|
63
|
+
```
|
64
|
+
gem push pkg/vagrant-tagprovision-0.vagrant-tagprovision-0.1.1.gem
|
65
|
+
```
|
66
|
+
|
67
|
+
## Author
|
55
68
|
|
56
|
-
|
57
|
-
- for his vagrant-pushover plugin. This plugin is modeled after his.
|
69
|
+
Jim Robinson
|
data/Vagrantfile
CHANGED
@@ -10,4 +10,14 @@ Vagrant.configure("2") do |config|
|
|
10
10
|
db.vm.box_url = "http://files.vagrantup.com/precise64.box"
|
11
11
|
db.vm.box = "precise64"
|
12
12
|
end
|
13
|
+
|
14
|
+
config.vm.define "db" do |db|
|
15
|
+
db.vm.box_url = "http://files.vagrantup.com/precise64.box"
|
16
|
+
db.vm.box = "precise64"
|
17
|
+
end
|
18
|
+
|
19
|
+
config.tagprovision.enabled = true
|
20
|
+
config.tagprovision.log_provision = true
|
21
|
+
config.tagprovision.tag_provision = true
|
22
|
+
config.tagprovision.push_tag = true
|
13
23
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require "net/https"
|
2
|
-
|
2
|
+
require 'vagrant-tagprovision/util'
|
3
3
|
module VagrantPlugins
|
4
4
|
module Tagprovision
|
5
5
|
class Action
|
@@ -14,8 +14,9 @@ module VagrantPlugins
|
|
14
14
|
@current_user = `whoami`
|
15
15
|
@time = Time.new
|
16
16
|
@tag = "provisioned_#{@machine}_#{@time.year}#{@time.month}#{@time.day}#{@time.hour}#{@time.min}#{@time.sec}"
|
17
|
-
machine_env = @machinfo.env;
|
18
|
-
@tmp_path = machine_env.tmp_path;
|
17
|
+
@machine_env = @machinfo.env;
|
18
|
+
@tmp_path = @machine_env.tmp_path;
|
19
|
+
@config = Util.get_config(@machine_env)
|
19
20
|
|
20
21
|
end
|
21
22
|
|
@@ -37,48 +38,65 @@ module VagrantPlugins
|
|
37
38
|
#env[:ui].info("Vagrant Hook Reload: #{@machine}")
|
38
39
|
|
39
40
|
when :provision
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
windir = ""
|
47
|
-
@machinfo.communicate.execute("echo %SYSTEMROOT%", {:shell => :cmd}) do |type, contents|
|
48
|
-
windir << contents.gsub("\r\n", '') if type == :stdout
|
41
|
+
if(@config.tagprovision.enabled)
|
42
|
+
if(@config.tagprovision.log_provision)
|
43
|
+
log_provision(env)
|
44
|
+
end
|
45
|
+
if(@config.tagprovision.log_provision)
|
46
|
+
tag_provision(env)
|
49
47
|
end
|
50
|
-
reallogfile = "#{windir}\\System32\\drivers\\var\\provision_log"
|
51
|
-
move_cmd = 'mv -force'
|
52
|
-
else
|
53
|
-
reallogfile = '/var/log/provision_log'
|
54
|
-
move_cmd = 'mv -f'
|
55
48
|
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def tag_provision(env)
|
53
|
+
env[:ui].info("Tagging provisioning information: #{@machine}")
|
54
|
+
`git tag #{@tag}`
|
55
|
+
if(@config.tagprovision.push_tag)
|
56
|
+
`git push --tags`
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def log_provision(env)
|
61
|
+
env[:ui].info("Logging provisioning information to guest machine: #{@machine}")
|
56
62
|
|
57
|
-
|
63
|
+
if (@machinfo.communicate.test("uname -s | grep SunOS"))
|
64
|
+
reallogfile = '/var/log/provision_log'
|
65
|
+
move_cmd = 'mv'
|
66
|
+
elsif (@machinfo.communicate.test("test -d $Env:SystemRoot"))
|
67
|
+
windir = ""
|
68
|
+
@machinfo.communicate.execute("echo %SYSTEMROOT%", {:shell => :cmd}) do |type, contents|
|
69
|
+
windir << contents.gsub("\r\n", '') if type == :stdout
|
70
|
+
end
|
71
|
+
reallogfile = "#{windir}\\System32\\drivers\\var\\provision_log"
|
72
|
+
move_cmd = 'mv -force'
|
73
|
+
else
|
74
|
+
reallogfile = '/var/log/provision_log'
|
75
|
+
move_cmd = 'mv -f'
|
76
|
+
end
|
58
77
|
|
59
|
-
|
60
|
-
@machinfo.communicate.sudo("touch #{reallogfile}")
|
61
|
-
@machinfo.communicate.sudo("chmod 666 #{reallogfile}")
|
62
|
-
@machinfo.communicate.sudo("touch /tmp/provision_logs")
|
63
|
-
@machinfo.communicate.sudo("chmod 666 /tmp/provision_logs")
|
78
|
+
file = @tmp_path.join("hosts.#{@machinfo.name}_#{@commit_hash}")
|
64
79
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
80
|
+
# Make sure the log files exist and are writable.
|
81
|
+
@machinfo.communicate.sudo("touch #{reallogfile}")
|
82
|
+
@machinfo.communicate.sudo("chmod 666 #{reallogfile}")
|
83
|
+
@machinfo.communicate.sudo("touch /tmp/provision_logs")
|
84
|
+
@machinfo.communicate.sudo("chmod 666 /tmp/provision_logs")
|
69
85
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
86
|
+
# download the current log file
|
87
|
+
@machinfo.communicate.download(reallogfile, file)
|
88
|
+
|
89
|
+
if update_file(file, @machinfo, false)
|
90
|
+
# upload modified file and remove temporary file
|
91
|
+
@machinfo.communicate.upload(file, '/tmp/provision_logs')
|
92
|
+
if windir
|
93
|
+
@machinfo.communicate.sudo("#{move_cmd} /tmp/provision_logs/hosts.#{@machinfo.name} #{reallogfile}")
|
94
|
+
elsif @machinfo.communicate.test('test -f /.dockerinit')
|
95
|
+
@machinfo.communicate.sudo("cat /tmp/provision_logs > #{reallogfile}")
|
96
|
+
else
|
97
|
+
@machinfo.communicate.sudo("#{move_cmd} /tmp/provision_logs #{reallogfile}")
|
98
|
+
end
|
99
|
+
end
|
82
100
|
end
|
83
101
|
|
84
102
|
def update_file(file, resolving_machine = nil, include_id = true)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Tagprovision
|
3
|
+
class Config < Vagrant.plugin('2', :config)
|
4
|
+
attr_accessor :enabled
|
5
|
+
attr_accessor :log_provision
|
6
|
+
attr_accessor :tag_provision
|
7
|
+
attr_accessor :push_tag
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@enabled = UNSET_VALUE
|
11
|
+
@log_provision = UNSET_VALUE
|
12
|
+
@tag_provision = UNSET_VALUE
|
13
|
+
@push_tag = UNSET_VALUE
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def finalize!
|
18
|
+
@enabled = false if @enabled == UNSET_VALUE
|
19
|
+
@log_provision = false if @log_provision == UNSET_VALUE
|
20
|
+
@tag_provision = false if @tag_provision == UNSET_VALUE
|
21
|
+
@push_tag = false if @push_tag == UNSET_VALUE
|
22
|
+
end
|
23
|
+
|
24
|
+
def validate(machine)
|
25
|
+
errors = []
|
26
|
+
|
27
|
+
errors << validate_bool('hostmanager.enabled', @enabled)
|
28
|
+
errors << validate_bool('hostmanager.log_provision', @log_provision)
|
29
|
+
errors << validate_bool('hostmanager.tag_provision', @tag_provision)
|
30
|
+
errors << validate_bool('hostmanager.push_tag', @push_tag)
|
31
|
+
errors.compact!
|
32
|
+
|
33
|
+
{ "Tagprovision configuration" => errors }
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def validate_bool(key, value)
|
39
|
+
if ![TrueClass, FalseClass].include?(value.class) &&
|
40
|
+
value != UNSET_VALUE
|
41
|
+
I18n.t('vagrant_tagprovision.config.not_a_bool', {
|
42
|
+
:config_key => key,
|
43
|
+
:value => value.class.to_s
|
44
|
+
})
|
45
|
+
else
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -13,7 +13,17 @@ module VagrantPlugins
|
|
13
13
|
This plugin tags the git repo when a server is provisioned.
|
14
14
|
DESC
|
15
15
|
|
16
|
-
|
16
|
+
config(:tagprovision) do
|
17
|
+
require_relative 'config'
|
18
|
+
Config
|
19
|
+
end
|
20
|
+
|
21
|
+
# Work-around for vagrant >= 1.5
|
22
|
+
# It breaks without a provisioner config, so we provide a dummy one
|
23
|
+
config(:tagprovision, :provisioner) do
|
24
|
+
::Vagrant::Config::V2::DummyConfig.new
|
25
|
+
end
|
26
|
+
|
17
27
|
action_hook("Tagprovision_hook", :machine_action_up) do |hook|
|
18
28
|
require_relative "action"
|
19
29
|
hook.prepend(Action)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Tagprovision
|
3
|
+
module Util
|
4
|
+
def self.get_config(env)
|
5
|
+
# config_global has been removed from v1.5
|
6
|
+
if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
|
7
|
+
env.vagrantfile.config
|
8
|
+
else
|
9
|
+
env.config_global
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/vagrant-tagprovision.rb
CHANGED
@@ -4,6 +4,10 @@ require "vagrant-tagprovision/plugin"
|
|
4
4
|
|
5
5
|
module VagrantPlugins
|
6
6
|
module Tagprovision
|
7
|
-
|
7
|
+
def self.source_root
|
8
|
+
@source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
9
|
+
end
|
10
|
+
I18n.load_path << File.expand_path('locales/en.yml', source_root)
|
11
|
+
I18n.reload!
|
8
12
|
end
|
9
13
|
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
en:
|
2
|
+
vagrant_tagprovision:
|
3
|
+
config:
|
4
|
+
not_a_bool: "A value for %{config_key} can only be true or false, not type '%{value}'"
|
5
|
+
not_an_array_or_string: "A value for %{config_key} must be an Array or String, not type '%{is_class}'"
|
6
|
+
not_a_proc: "A value for %{config_key} must be a Proc, not type '%{is_class}'"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-tagprovision
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jimrobinson
|
@@ -53,8 +53,11 @@ files:
|
|
53
53
|
- Vagrantfile
|
54
54
|
- lib/vagrant-tagprovision.rb
|
55
55
|
- lib/vagrant-tagprovision/action.rb
|
56
|
+
- lib/vagrant-tagprovision/config.rb
|
56
57
|
- lib/vagrant-tagprovision/plugin.rb
|
58
|
+
- lib/vagrant-tagprovision/util.rb
|
57
59
|
- lib/vagrant-tagprovision/version.rb
|
60
|
+
- locales/en.yml
|
58
61
|
- vagrant-tagprovision.gemspec
|
59
62
|
homepage: https://github.com/jscrobinson/vagrant-tagprovision
|
60
63
|
licenses:
|