vagrant-save 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b61d2c1869c2781c59cce9b501e55fc56ee2dca6
4
+ data.tar.gz: 0b6b807477ce3b01e6e133c1153e25331b81aa2c
5
+ SHA512:
6
+ metadata.gz: 3e9cf1802217aeccfae0f99107cee0a8115699ed1241b1530670ed9c57c593ac9ab949385b38251e5a14803005bc299e9ead422fa3fe088cc40d153cec115008
7
+ data.tar.gz: 30a5948f0055017eceb7d11723da3c4b93d5c99192d65a8e47c7e1f74fb971415af0a87591949e3e5a052cf5bd8af3289c855f184ab235fe5e2762bf13b88b2a
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ Gemfile.lock
16
+ /.idea
17
+ /.vagrant
18
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
5
+ end
6
+
7
+ gem 'vagrant-export', '~> 0.2.3', git: 'https://github.com/trenker/vagrant-export.git'
8
+
9
+ group :plugins do
10
+ gem 'vagrant-save', path: '.'
11
+ end
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # vagrant-save
2
+
3
+ This is a simple plugin to export boxes into .box files using [vagrant-export](https://github.com/trenker/vagrant-export) and pushes that file to a [boxserver](https://github.com/trenker/boxserver) instance.
4
+
5
+ ## Installation
6
+
7
+ Like with any other vagrant plugin:
8
+
9
+ ```bash
10
+ vagrant plugin install vagrant-save
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Have a [boxserver](https://github.com/trenker/boxserver) instance running and set the property `config.vm.box_server_url` to its address in your vagrant file.
16
+
17
+ Then just run
18
+
19
+ ```bash
20
+ vagrant save
21
+ ```
22
+
23
+ to release a new version of your box.
24
+
25
+ Without any further arguments, vagrant-save will delete old versions, keeping only the last three. You can override this by setting the `-c|--clean` option.
26
+
27
+ ```bash
28
+ # Keeping the last six versions
29
+ vagrant save -c 6
30
+
31
+ # Keeping all versions
32
+ vagrant save -c 0
33
+ ```
34
+
35
+ By default, it increases the bugfix version number by one. So an installed 1.0.0 becomes 1.0.1. You can specify the version yourself using the parameter `-v|--version`, like this:
36
+
37
+ ```bash
38
+ vagrant save -v 1.2.0
39
+ ```
40
+
41
+ The parameter must always have all three digits and must be greater than the installed version
42
+
43
+ ## License
44
+
45
+ The MIT License (MIT)
46
+
47
+ Copyright (c) 2014 Georg Großberger
48
+
49
+ Permission is hereby granted, free of charge, to any person obtaining a copy
50
+ of this software and associated documentation files (the "Software"), to deal
51
+ in the Software without restriction, including without limitation the rights
52
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
53
+ copies of the Software, and to permit persons to whom the Software is
54
+ furnished to do so, subject to the following conditions:
55
+
56
+ The above copyright notice and this permission notice shall be included in
57
+ all copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
64
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
65
+ THE SOFTWARE.
data/Vagrantfile ADDED
@@ -0,0 +1,5 @@
1
+
2
+ Vagrant.configure("2") do |config|
3
+ config.vm.box_server_url = "http://localhost:8001"
4
+ config.vm.box = "base/typo3"
5
+ end
@@ -0,0 +1,7 @@
1
+ # #
2
+ # This is free software; you can redistribute it and/or modify it under #
3
+ # the terms of the MIT- / X11 - License #
4
+ # #
5
+
6
+ require 'vagrant-save/plugin'
7
+ require 'vagrant-save/version'
@@ -0,0 +1,81 @@
1
+ # #
2
+ # This is free software; you can redistribute it and/or modify it under #
3
+ # the terms of the MIT- / X11 - License #
4
+ # #
5
+
6
+ require_relative 'errors'
7
+
8
+ module VagrantPlugins
9
+ module Save
10
+ class Command < Vagrant.plugin('2', :command)
11
+
12
+ def self.synopsis
13
+ 'exports a box file with additional actions taken'
14
+ end
15
+
16
+ def execute
17
+ options = {}
18
+ options[:version] = nil
19
+ options[:clean] = 3
20
+
21
+ opts = OptionParser.new do |o|
22
+ o.banner = 'Usage: vagrant save [version]'
23
+ o.separator ''
24
+
25
+ o.on('-c', '--clean', 'Set the version of the uploaded box') do |c|
26
+ options[:clean] = c.to_i
27
+ end
28
+ end
29
+
30
+ argv = parse_options(opts)
31
+ return 1 unless argv
32
+
33
+ target_version = options[:version]
34
+
35
+ unless target_version == nil
36
+ unless /^[0-9]+\.[0-9]+\.[0-9]+$/ =~ target_version
37
+ raise VagrantPlugins::Save::Errors::NoValidVersion
38
+ end
39
+ end
40
+
41
+ require 'vagrant-export/exporter'
42
+ require_relative 'uploader'
43
+
44
+ ex = VagrantPlugins::Export::Exporter.new(@env, @logger)
45
+ up = Uploader.new(@env, @logger)
46
+
47
+ with_target_vms argv, reverse: true do |machine|
48
+
49
+ if target_version
50
+ version = target_version
51
+
52
+ if Gem::Version.new(machine.box.version.to_s) <= Gem::Version.new(version)
53
+ raise VagrantPlugins::Save::Errors::InvalidVersion
54
+ end
55
+
56
+ else
57
+ version_parts = machine.box.version.to_s
58
+ if /^[0-9]+\.[0-9]+\.[0-9]+$/ =~ version_parts
59
+ version_parts = version_parts.split('.')
60
+ version = version_parts[0] + '.' + version_parts[1] + '.' + (version_parts[2].to_i + 1).to_s
61
+ else
62
+ version = '1.0.0'
63
+ end
64
+ end
65
+
66
+ file = ex.handle(machine, false, false)
67
+
68
+ up.send(machine, file, version)
69
+
70
+ FileUtils.remove(file)
71
+
72
+ if options[:clean] && options[:clean] > 1
73
+ up.clean(machine, options[:clean])
74
+ end
75
+
76
+ end
77
+ 0
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,28 @@
1
+ # #
2
+ # This is free software; you can redistribute it and/or modify it under #
3
+ # the terms of the MIT- / X11 - License #
4
+ # #
5
+
6
+ module VagrantPlugins
7
+ module Save
8
+ module Errors
9
+
10
+ class CannotContactBoxServer < VagrantError
11
+ error_message('Cannot contact the given box server. Please make sure the URL is correct and it is running')
12
+ end
13
+
14
+ class UploadFailed < VagrantError
15
+ error_message('Cannot upload the box file to the boxserver')
16
+ end
17
+
18
+ class NoValidVersion < VagrantError
19
+ error_message('The given version is not valid. Please pass a version number like 1.2.3, or leave it to automatically bump the bugfix/release number')
20
+ end
21
+
22
+ class InvalidVersion < VagrantError
23
+ error_message('The given version number is lower or equal to the current version of the box')
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ # #
2
+ # This is free software; you can redistribute it and/or modify it under #
3
+ # the terms of the MIT- / X11 - License #
4
+ # #
5
+
6
+ module VagrantPlugins
7
+ module Save
8
+ class Plugin < Vagrant.plugin('2')
9
+
10
+ name('Vagrant Save')
11
+
12
+ description <<-EOF
13
+ Uses vagrant-export to create a.box file from the current machine and
14
+ saves it to a boxserver using a HTTP PUT request.
15
+ EOF
16
+
17
+ command 'save' do
18
+ require_relative 'command'
19
+ Command
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,87 @@
1
+ # #
2
+ # This is free software; you can redistribute it and/or modify it under #
3
+ # the terms of the MIT- / X11 - License #
4
+ # #
5
+
6
+ require 'httpclient'
7
+
8
+ module VagrantPlugins
9
+ module Save
10
+ class Uploader
11
+
12
+ # @param [Vagrant::Environment] env
13
+ # @param [Log4r::Logger] logger
14
+ def initialize(env, logger)
15
+ @env = env
16
+ @logger = logger
17
+ end
18
+
19
+ # @param [Vagrant::Machine] machine
20
+ # @param [string] file
21
+ # @param [string] version
22
+ # @return int
23
+ def send(machine, file, version)
24
+
25
+ @env.ui.info('Uploading now')
26
+
27
+ provider = machine.provider_name.to_s
28
+ ping_url = make_url(machine)
29
+ post_url = ping_url + '/' + version + '/' + provider
30
+
31
+ client = HTTPClient.new
32
+ res = client.options(ping_url)
33
+
34
+ raise VagrantPlugins::Save::Errors::CannotContactBoxServer unless res.http_header.status_code == 200
35
+
36
+ File.open(file) do |f|
37
+ body = {'box' => f}
38
+ res = client.post(post_url, body)
39
+ end
40
+
41
+ raise VagrantPlugins::Save::Errors::UploadFailed unless res.http_header.status_code == 200
42
+
43
+ @env.ui.info('Upload successful')
44
+
45
+ 0
46
+ end
47
+
48
+ # @param [Vagrant::Machine] machine
49
+ # @param [int] keep
50
+ # @return int
51
+ def clean(machine, keep)
52
+ @env.ui.info('Cleaning up old versions')
53
+
54
+ data_url = make_url(machine)
55
+
56
+ res = client.get(data_url)
57
+ data = JSON.parse(res.http_body)
58
+
59
+ client = HTTPClient.new
60
+ saved_versions = data['versions'].map{ |v| v.version}
61
+
62
+ if saved_versions.length > keep
63
+ saved_versions = saved_versions.sort.reverse
64
+ saved_versions.slice(keep, saved_versions.length).each { |v|
65
+ client.delete(data_url + '/' + v)
66
+ }
67
+ end
68
+
69
+ 0
70
+ end
71
+
72
+ private
73
+
74
+ # @param [Vagrant::Machine] machine
75
+ # @return string
76
+ def make_url(machine)
77
+ name = machine.box.name.gsub(/_+/, '/')
78
+ base_url = Vagrant.server_url(machine.config.vm.box_server_url).to_s
79
+
80
+ raise Vagrant::Errors::BoxServerNotSet unless base_url
81
+
82
+ base_url + '/' + name
83
+ end
84
+
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,10 @@
1
+ # #
2
+ # This is free software; you can redistribute it and/or modify it under #
3
+ # the terms of the MIT- / X11 - License #
4
+ # #
5
+
6
+ module VagrantPlugins
7
+ module Save
8
+ VERSION = '0.1.0'
9
+ end
10
+ end
@@ -0,0 +1,50 @@
1
+ $:.unshift(File.expand_path('../lib', __FILE__))
2
+
3
+ require 'vagrant-save/version'
4
+
5
+ Gem::Specification.new do |g|
6
+ g.name = 'vagrant-save'
7
+ g.version = VagrantPlugins::Save::VERSION
8
+ g.platform = Gem::Platform::RUBY
9
+ g.license = 'MIT'
10
+ g.authors = 'Georg Großberger'
11
+ g.email = 'contact@grossberger-ge.org'
12
+ g.homepage = 'https://github.com/trenker/vagrant-save.git'
13
+ g.summary = 'Export boxes to a boxserver'
14
+ g.description = 'Export boxes to a boxserver on a remote machine using HTTP/PUT'
15
+
16
+ # The following block of code determines the files that should be included
17
+ # in the gem. It does this by reading all the files in the directory where
18
+ # this gemspec is, and parsing out the ignored files from the gitignore.
19
+ # Note that the entire gitignore(5) syntax is not supported, specifically
20
+ # the "!" syntax, but it should mostly work correctly.
21
+ root_path = File.dirname(__FILE__)
22
+ all_files = Dir.chdir(root_path) { Dir.glob('**/{*,.*}') }
23
+ all_files.reject! { |file| %w(. ..).include?(File.basename(file)) }
24
+ gitignore_path = File.join(root_path, '.gitignore')
25
+ gitignore = File.readlines(gitignore_path)
26
+ gitignore.map! { |line| line.chomp.strip }
27
+ gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
28
+
29
+ unignored_files = all_files.reject do |file|
30
+ # Ignore any directories, the gemspec only cares about files
31
+ next true if File.directory?(file)
32
+
33
+ # Ignore any paths that match anything in the gitignore. We do
34
+ # two tests here:
35
+ #
36
+ # - First, test to see if the entire path matches the gitignore.
37
+ # - Second, match if the basename does, this makes it so that things
38
+ # like '.DS_Store' will match sub-directories too (same behavior
39
+ # as git).
40
+ #
41
+ gitignore.any? do |ignore|
42
+ File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
43
+ File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
44
+ end
45
+ end
46
+
47
+ g.files = unignored_files
48
+ g.require_path = 'lib'
49
+ g.add_dependency 'vagrant-export', '~> 0.2.3'
50
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-save
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Georg Großberger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: vagrant-export
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.3
27
+ description: Export boxes to a boxserver on a remote machine using HTTP/PUT
28
+ email: contact@grossberger-ge.org
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - Gemfile
35
+ - README.md
36
+ - Vagrantfile
37
+ - lib/vagrant-save.rb
38
+ - lib/vagrant-save/command.rb
39
+ - lib/vagrant-save/errors.rb
40
+ - lib/vagrant-save/plugin.rb
41
+ - lib/vagrant-save/uploader.rb
42
+ - lib/vagrant-save/version.rb
43
+ - vagrant-save.gemspec
44
+ homepage: https://github.com/trenker/vagrant-save.git
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.4.5
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Export boxes to a boxserver
68
+ test_files: []