vagrant_box_version 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vagrant_box_version/action.rb +18 -0
- data/lib/vagrant_box_version/command.rb +3 -56
- data/lib/vagrant_box_version/plugin.rb +12 -0
- data/lib/vagrant_box_version/version-checking.rb +66 -0
- data/lib/vagrant_box_version/version.rb +1 -1
- data/vagrant_box_version.gemspec +2 -1
- metadata +9 -8
- data/.gitignore +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c4b0d5d746a99637d2596722b2a59aebb985667
|
4
|
+
data.tar.gz: c4c5f3eadf68083ccf183600e2c4aa98b9df0409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b214f97ca82d4d70bc62dee594217a9fa952351d346fcf75992fbf4ee1d2af53486c26df7d1a1f340132d2e77086ece3e95be34c8aef2e5779137f23f13951b9
|
7
|
+
data.tar.gz: a8da378649a5679befef71168400ce690c24e0a560bbf47db8ab90f5de0f5e3774e7b938395456285703ca2bf5b8da3a7c293ee9bc24256ca61f4f1627199eae
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative "version-checking"
|
2
|
+
|
3
|
+
module VagrantBoxVersion
|
4
|
+
module Action
|
5
|
+
class Check
|
6
|
+
include VersionChecking
|
7
|
+
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
check(env[:machine], env[:ui])
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,68 +1,15 @@
|
|
1
1
|
require "vagrant"
|
2
|
+
require_relative "version-checking"
|
2
3
|
|
3
4
|
module VagrantBoxVersion
|
4
|
-
require "open-uri"
|
5
|
-
|
6
|
-
class VersionString
|
7
|
-
attr_reader :build, :hash
|
8
|
-
include Comparable
|
9
|
-
|
10
|
-
def initialize(string)
|
11
|
-
@build = string.strip[/[^-]*/].to_i
|
12
|
-
@hash = if string.include? "-" then string.strip.split("-")[1] else "" end
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_s
|
16
|
-
"#@build-#@hash"
|
17
|
-
end
|
18
|
-
|
19
|
-
def <=>(other)
|
20
|
-
build <=> other.build
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
5
|
class Command < Vagrant.plugin(2, :command)
|
6
|
+
include VersionChecking
|
25
7
|
|
26
8
|
def execute
|
27
9
|
ui = @env.ui
|
28
10
|
|
29
11
|
with_target_vms() do |machine|
|
30
|
-
|
31
|
-
unless box.nil?
|
32
|
-
version = local_version(box.directory)
|
33
|
-
remote = remote_version(machine.config.version.url, box.name)
|
34
|
-
|
35
|
-
ui.info("Local version is #{version || "unknown"}")
|
36
|
-
|
37
|
-
if (version || VersionString.new("0")) < (remote || VersionString.new("0"))
|
38
|
-
ui.warn("Version #{remote} is available!")
|
39
|
-
ui.info("To update, run:")
|
40
|
-
ui.info(" vagrant destroy && vagrant box remove #{box.name} #{box.provider.to_s}")
|
41
|
-
elsif version.nil?
|
42
|
-
ui.warn("Local version couldn't be determined. You should probably upgrade your box.")
|
43
|
-
elsif remote.nil?
|
44
|
-
ui.warn("Remote version couldn't be determined. Try again later.")
|
45
|
-
else
|
46
|
-
ui.success("You are up to date!")
|
47
|
-
end
|
48
|
-
else
|
49
|
-
ui.success("There is no local box yet. Nothing to do.")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def local_version(boxdir)
|
57
|
-
versionfile = File.join(boxdir, "include", "version")
|
58
|
-
if File.exists? versionfile then VersionString.new(File.read(versionfile)) else nil end
|
59
|
-
end
|
60
|
-
|
61
|
-
def remote_version(server, name)
|
62
|
-
begin
|
63
|
-
VersionString.new(open("#{server}/#{name}.box.version").read)
|
64
|
-
rescue
|
65
|
-
nil
|
12
|
+
check(machine, ui)
|
66
13
|
end
|
67
14
|
end
|
68
15
|
end
|
@@ -23,5 +23,17 @@ module VagrantBoxVersion
|
|
23
23
|
require_relative "config"
|
24
24
|
Config
|
25
25
|
end
|
26
|
+
|
27
|
+
# thanks to
|
28
|
+
# https://github.com/tknerr/vagrant-plugin-bundler/blob/master/lib/vagrant-plugin-bundler/plugin.rb
|
29
|
+
|
30
|
+
check_version_hook = lambda do |hook|
|
31
|
+
require_relative "action"
|
32
|
+
hook.before Vagrant::Action::Builtin::Provision, VagrantBoxVersion::Action::Check
|
33
|
+
end
|
34
|
+
|
35
|
+
action_hook 'check-box-version-on-machine-up', :machine_action_up, &check_version_hook
|
36
|
+
action_hook 'check-box-version-on-machine-reload', :machine_action_reload, &check_version_hook
|
37
|
+
action_hook 'check-box-version-on-machine-provision', :machine_action_provision, &check_version_hook
|
26
38
|
end
|
27
39
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
##
|
2
|
+
# Mix-in to do actual version checking
|
3
|
+
#
|
4
|
+
|
5
|
+
module VagrantBoxVersion
|
6
|
+
require "open-uri"
|
7
|
+
|
8
|
+
|
9
|
+
class VersionString
|
10
|
+
attr_reader :build, :hash
|
11
|
+
include Comparable
|
12
|
+
|
13
|
+
def initialize(string)
|
14
|
+
@build = string.strip[/[^-]*/].to_i
|
15
|
+
@hash = if string.include? "-" then string.strip.split("-")[1] else "" end
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
"#@build-#@hash"
|
20
|
+
end
|
21
|
+
|
22
|
+
def <=>(other)
|
23
|
+
build <=> other.build
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
module VersionChecking
|
29
|
+
def check(machine, ui)
|
30
|
+
box = machine.box
|
31
|
+
unless box.nil?
|
32
|
+
version = local_version(box.directory)
|
33
|
+
remote = remote_version(machine.config.version.url, box.name)
|
34
|
+
|
35
|
+
ui.info("Local version is #{version || "unknown"}")
|
36
|
+
|
37
|
+
if (version || VersionString.new("0")) < (remote || VersionString.new("0"))
|
38
|
+
ui.warn("Version #{remote} is available!")
|
39
|
+
ui.info("To update, run:")
|
40
|
+
ui.info(" vagrant destroy && vagrant box remove #{box.name} #{box.provider.to_s}")
|
41
|
+
elsif version.nil?
|
42
|
+
ui.warn("Local version couldn't be determined. You should probably upgrade your box.")
|
43
|
+
elsif remote.nil?
|
44
|
+
ui.warn("Remote version couldn't be determined. Try again later.")
|
45
|
+
else
|
46
|
+
ui.success("You are up to date!")
|
47
|
+
end
|
48
|
+
else
|
49
|
+
ui.success("There is no local box yet. Nothing to do.")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def local_version(boxdir)
|
54
|
+
versionfile = File.join(boxdir, "include", "version")
|
55
|
+
if File.exists? versionfile then VersionString.new(File.read(versionfile)) else nil end
|
56
|
+
end
|
57
|
+
|
58
|
+
def remote_version(server, name)
|
59
|
+
begin
|
60
|
+
VersionString.new(open("#{server}/#{name}.box.version").read)
|
61
|
+
rescue
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/vagrant_box_version.gemspec
CHANGED
@@ -13,7 +13,8 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files = `
|
16
|
+
spec.files = `find lib -type f`.split($/) +
|
17
|
+
["Gemfile", "LICENSE.txt", "README.md", "Rakefile", "vagrant_box_version.gemspec"]
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
20
|
spec.require_paths = ["lib"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant_box_version
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edd Steel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -45,16 +45,17 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .
|
49
|
-
- Gemfile
|
50
|
-
- LICENSE.txt
|
51
|
-
- README.md
|
52
|
-
- Rakefile
|
53
|
-
- lib/vagrant_box_version.rb
|
48
|
+
- lib/vagrant_box_version/action.rb
|
54
49
|
- lib/vagrant_box_version/command.rb
|
55
50
|
- lib/vagrant_box_version/config.rb
|
56
51
|
- lib/vagrant_box_version/plugin.rb
|
52
|
+
- lib/vagrant_box_version/version-checking.rb
|
57
53
|
- lib/vagrant_box_version/version.rb
|
54
|
+
- lib/vagrant_box_version.rb
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
58
59
|
- vagrant_box_version.gemspec
|
59
60
|
homepage: ''
|
60
61
|
licenses:
|