vagrant_box_version 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 448b6eb663ff3e362c5e8953ffc7491ee52d7e6b
4
+ data.tar.gz: 30b6be9f3f652ccebdbdb21622d7efa138c578ce
5
+ SHA512:
6
+ metadata.gz: bcda7ad27f8749a59a5c128c53b2dbe8a79fadda2ee9034ecd3586263e3d9a6ed23e92f4e83199f9661c2dc24702ede3e046cec512211a0ef5fb31533979c302
7
+ data.tar.gz: 33674f0b3bd51c28536219b64f86308ce46c42ac271e3aa72c1b05bc358f69727cea832bfd1786f0e87a704643d7dc98225ccbc3c3092aaececc663e9db770b6
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant_box_version.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Hootsuite Media Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Vagrant Box Version Plugin
2
+
3
+ This plugin allows users of vagrant boxes to check they have the latest
4
+ available version. It's designed to do so in the simplest way possible.
5
+
6
+ It provides two things:
7
+
8
+ 1. A convention for storing version information inside vagrant boxes
9
+ 2. A plugin that checks that the version available on a remote server is the
10
+ same as the current box version.
11
+
12
+ Versions are stored inside the box in `include/version` and just contain a
13
+ version identifier. The part of that version number before the first dash is
14
+ parsed as an integer for comparison. We use
15
+ `[jenkins build number]-[git short revision]`.
16
+
17
+ The purpose of this plugin is to enable organizations to continuously improve
18
+ their vagrant-backed dev environments, and treat them as disposable (á la
19
+ [Chad Fowler][fowler])
20
+
21
+ ## Usage
22
+
23
+ ### For box publishers
24
+
25
+ Boxes should include a file called `version` containing your version of the
26
+ box. Simply create the file with the desired content and include it in your
27
+ packaged box when you run:
28
+
29
+ vagrant package --include version
30
+
31
+ The plugin requires a file with the name `[box-name].box.version` to be
32
+ installed in a known HTTP/HTTPS/FTP location. We upload them alongside the box
33
+ with the same jenkins job that builds boxes.
34
+
35
+ ### For box users
36
+
37
+ Once the plugin is installed (`vagrant plugin install vagrant_box_version`),
38
+ simply add the location of your box server's version files to your config,
39
+ e.g.
40
+
41
+ config.version.url = http://my-vagrant-box.es/
42
+
43
+ You can then run `vagrant version` to check you have the latest version. If
44
+ you don't or either remote or local version can't be determined, you will be
45
+ warned about it.
46
+
47
+ ### Installation from source.
48
+
49
+ Simply run `rake build`, and then
50
+ `vagrant plugin install pkg/vagrant_box_version`.
51
+
52
+ ### Extension points
53
+
54
+ This is always going to be minimal. However in the future it might:
55
+
56
+ * Allow a regex-based version format that identifies points of comparison.
57
+ * Offer to update your box for you (destroying the current box)
58
+ * Provide more flexibility about version information source (frankly unlikely)
59
+
60
+ ## Contributing
61
+
62
+ Contributions in the form of pull requests are are very welcome, though anyone
63
+ wanting to produce a full box package manager might want to start again.
64
+
65
+ [fowler]: http://chadfowler.com/blog/2013/06/23/immutable-deployments/
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,69 @@
1
+ require "vagrant"
2
+
3
+ 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
+ class Command < Vagrant.plugin(2, :command)
25
+
26
+ def execute
27
+ ui = @env.ui
28
+
29
+ with_target_vms() do |machine|
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
+ 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
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,22 @@
1
+ module VagrantBoxVersion
2
+
3
+ class Config < Vagrant.plugin("2", :config)
4
+ attr_accessor :url
5
+
6
+ def initialize()
7
+ @url = UNSET_VALUE
8
+ end
9
+
10
+ def finalize!
11
+ @url = "" if @url == UNSET_VALUE
12
+ end
13
+
14
+ def validate(machine)
15
+ if @url.empty?
16
+ { "version" => ["config.version.url must be set"] }
17
+ else
18
+ {}
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ begin
2
+ require "vagrant"
3
+ rescue LoadError
4
+ raise "This plugin must be run from within Vagrant."
5
+ end
6
+
7
+ if Vagrant::VERSION < "1.2.0"
8
+ raise "This plugin is only compatible with Vagrant 1.2+"
9
+ end
10
+
11
+
12
+ module VagrantBoxVersion
13
+ class Plugin < Vagrant.plugin("2")
14
+
15
+ name "Vagrant Box Version Plugin"
16
+
17
+ command "version" do
18
+ require_relative "command"
19
+ Command
20
+ end
21
+
22
+ config "version" do
23
+ require_relative "config"
24
+ Config
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module VagrantBoxVersion
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ require "vagrant_box_version/version"
2
+ require "vagrant_box_version/plugin"
3
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant_box_version/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant_box_version"
8
+ spec.version = VagrantBoxVersion::VERSION
9
+ spec.authors = ["Edd Steel"]
10
+ spec.email = ["edward.steel@hootsuite.com"]
11
+ spec.description = "Plugin to provide version information for boxes"
12
+ spec.summary = "Plugin to provide version information for boxes"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant_box_version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Edd Steel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Plugin to provide version information for boxes
42
+ email:
43
+ - edward.steel@hootsuite.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/vagrant_box_version.rb
54
+ - lib/vagrant_box_version/command.rb
55
+ - lib/vagrant_box_version/config.rb
56
+ - lib/vagrant_box_version/plugin.rb
57
+ - lib/vagrant_box_version/version.rb
58
+ - vagrant_box_version.gemspec
59
+ homepage: ''
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.0.0
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Plugin to provide version information for boxes
83
+ test_files: []