bento-ya 0.1.4 → 1.0.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.
@@ -1,12 +1,16 @@
1
- require 'benchmark'
2
- require 'fileutils'
3
- require 'json'
4
- require 'tempfile'
5
- require 'yaml'
1
+ require "benchmark"
2
+ require "fileutils"
3
+ require "json"
4
+ require "tempfile"
5
+ require "yaml"
6
+ require "vagrant_cloud"
6
7
 
7
8
  MEGABYTE = 1024.0 * 1024.0
8
9
 
9
10
  module Common
11
+ def vc_account
12
+ VagrantCloud::Account.new(ENV["VAGRANT_CLOUD_ORG"], ENV["VAGRANT_CLOUD_TOKEN"])
13
+ end
10
14
 
11
15
  def banner(msg)
12
16
  puts "==> #{msg}"
@@ -33,13 +37,13 @@ module Common
33
37
  json = JSON.parse(file)
34
38
 
35
39
  # metadata needed for upload: boxname, version, provider, box filename
36
- metadata['name'] = json['name']
37
- metadata['version'] = json['version']
38
- metadata['box_basename'] = json['box_basename']
39
- metadata['tools'] = json['tools']
40
- metadata['providers'] = Hash.new
41
- json['providers'].each do |provider|
42
- metadata['providers'][provider['name']] = provider.reject { |k, _| k == 'name' }
40
+ metadata["name"] = json["name"]
41
+ metadata["version"] = json["version"]
42
+ metadata["box_basename"] = json["box_basename"]
43
+ metadata["tools"] = json["tools"]
44
+ metadata["providers"] = Hash.new
45
+ json["providers"].each do |provider|
46
+ metadata["providers"][provider["name"]] = provider.reject { |k, _| k == "name" }
43
47
  end
44
48
  metadata
45
49
  end
@@ -52,16 +56,50 @@ module Common
52
56
  `ls builds/*.json`.split("\n")
53
57
  end
54
58
 
55
- def bento_version
56
- @bento_version ||= ENV['BENTO_VERSION']
59
+ def builds_yml
60
+ YAML.load(File.read("builds.yml"))
57
61
  end
58
62
 
59
- def builds
60
- YAML.load(File.read("builds.yml"))
63
+ def build_list
64
+ bit32 = []
65
+ bit64 = []
66
+ builds_yml["public"].each do |platform, versions|
67
+ versions.each do |version, archs|
68
+ archs.each do |arch|
69
+ folder = case platform
70
+ when "opensuse-leap"
71
+ "opensuse"
72
+ when "oracle"
73
+ "oraclelinux"
74
+ else
75
+ platform
76
+ end
77
+ case arch
78
+ when "i386"
79
+ bit32 << "#{folder}/#{platform}-#{version}-#{arch}"
80
+ else
81
+ bit64 << "#{folder}/#{platform}-#{version}-#{arch}"
82
+ end
83
+ end
84
+ end
85
+ end
86
+ bit64 + bit32
61
87
  end
62
88
 
63
89
  def private_box?(boxname)
64
- proprietary_os_list = %w(macosx sles solaris windows)
90
+ proprietary_os_list = %w{macos windows sles solaris rhel}
65
91
  proprietary_os_list.any? { |p| boxname.include?(p) }
66
92
  end
93
+
94
+ def os_x?
95
+ !!(RUBY_PLATFORM =~ /darwin/)
96
+ end
97
+
98
+ def unix?
99
+ !windows?
100
+ end
101
+
102
+ def windows?
103
+ !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
104
+ end
67
105
  end
@@ -1,21 +1,21 @@
1
- require 'bento/common'
2
- require 'bento/vagrantcloud'
1
+ require "bento/common"
3
2
 
4
3
  class DeleteRunner
5
4
  include Common
6
- include VgCloud
7
5
 
8
- attr_reader :boxname, :version
6
+ attr_reader :box, :version
9
7
 
10
8
  def initialize(opts)
11
- @boxname = opts.box
9
+ @box = opts.box
12
10
  @version = opts.version
13
11
  end
14
12
 
15
13
  def start
16
14
  banner("Starting Delete...")
17
15
  time = Benchmark.measure do
18
- box_delete_version(boxname, version)
16
+ box = vc_account.get_box(box)
17
+ version = box.get_version(version)
18
+ version.delete
19
19
  end
20
20
  banner("Delete finished in #{duration(time.real)}.")
21
21
  end
@@ -1,7 +1,6 @@
1
- require 'bento/common'
1
+ require "bento/common"
2
2
 
3
3
  class NormalizeRunner
4
-
5
4
  include Common
6
5
  include PackerExec
7
6
 
@@ -25,7 +24,7 @@ class NormalizeRunner
25
24
  if !@modified.empty?
26
25
  info("")
27
26
  info("The following templates were modified:")
28
- @modified.sort.each { |template| info(" * #{template}")}
27
+ @modified.sort.each { |template| info(" * #{template}") }
29
28
  end
30
29
  banner("Normalizing finished in #{duration(time.real)}.")
31
30
  end
@@ -41,7 +40,7 @@ class NormalizeRunner
41
40
 
42
41
  banner("[#{template}] Fixing")
43
42
  original_checksum = checksum(file)
44
- output = %x{packer fix #{file}}
43
+ output = `packer fix #{file}`
45
44
  raise "[#{template}] Error fixing, exited #{$?}" if $?.exitstatus != 0
46
45
  # preserve ampersands in shell commands,
47
46
  # see: https://github.com/mitchellh/packer/issues/784
@@ -59,7 +58,7 @@ class NormalizeRunner
59
58
 
60
59
  def packer_validate_cmd(template, var_file)
61
60
  vars = "#{template}.variables.json"
62
- cmd = %W[packer validate -var-file=#{var_file} #{template}.json]
61
+ cmd = %W{packer validate -var-file=#{var_file} #{template}.json}
63
62
  cmd.insert(2, "-var-file=#{vars}") if File.exist?(vars)
64
63
  cmd
65
64
  end
@@ -74,7 +73,7 @@ class NormalizeRunner
74
73
  banner("[#{template}] DEBUG: md_file(#{md_file.path}) is:")
75
74
  puts IO.read(md_file.path)
76
75
  end
77
- system(*cmd) or raise "[#{template}] Error validating, exited #{$?}"
76
+ system(*cmd) || raise( "[#{template}] Error validating, exited #{$?}")
78
77
  end
79
78
  end
80
79
  end
@@ -1,6 +1,5 @@
1
1
 
2
2
  module PackerExec
3
-
4
3
  def for_packer_run_with(template)
5
4
  Tempfile.open("#{template}-metadata.json") do |md_file|
6
5
  Tempfile.open("#{template}-metadata-var-file") do |var_file|
@@ -1,6 +1,8 @@
1
- require 'digest'
1
+ require "digest"
2
+ require "bento/common"
2
3
 
3
4
  class ProviderMetadata
5
+ include Common
4
6
 
5
7
  def initialize(path, box_basename)
6
8
  @base = File.join(path, box_basename)
@@ -24,7 +26,12 @@ class ProviderMetadata
24
26
  attr_reader :base
25
27
 
26
28
  def provider_from_file(file)
27
- file.sub(/^.*\.([^.]+)\.box$/, '\1')
29
+ provider = file.sub(/^.*\.([^.]+)\.box$/, '\1')
30
+ if provider == "vmware"
31
+ "vmware_desktop"
32
+ else
33
+ provider
34
+ end
28
35
  end
29
36
 
30
37
  def shasum(file)
@@ -33,14 +40,14 @@ class ProviderMetadata
33
40
 
34
41
  def size_in_mb(file)
35
42
  size = File.size(file)
36
- size_mb = size / MEGABYTE
43
+ size_mb = size / MEGABYTE
37
44
  size_mb.ceil.to_s
38
45
  end
39
46
 
40
47
  def version(provider)
41
48
  case provider
42
49
  when /vmware/
43
- ver_fusion
50
+ ver_vmware
44
51
  when /virtualbox/
45
52
  ver_vbox
46
53
  when /parallels/
@@ -48,23 +55,30 @@ class ProviderMetadata
48
55
  end
49
56
  end
50
57
 
51
- def ver_fusion
52
- path = File.join('/Applications/VMware\ Fusion.app/Contents/Library')
53
- fusion_cmd = File.join(path, "vmware-vmx -v")
54
- cmd = Mixlib::ShellOut.new(fusion_cmd)
55
- cmd.run_command
56
- cmd.stderr.split(' ')[5]
58
+ def ver_vmware
59
+ if os_x?
60
+ path = File.join('/Applications/VMware\ Fusion.app/Contents/Library')
61
+ fusion_cmd = File.join(path, "vmware-vmx -v")
62
+ cmd = Mixlib::ShellOut.new(fusion_cmd)
63
+ cmd.run_command
64
+ cmd.stderr.split(" ")[5]
65
+ else
66
+ cmd = Mixlib::ShellOut.new("vmware --version")
67
+ cmd.run_command
68
+ cmd.stdout.split(" ")[2]
69
+ end
57
70
  end
58
71
 
59
72
  def ver_parallels
73
+ raise "Platform is not macOS / OS X, exiting..." unless os_x?
60
74
  cmd = Mixlib::ShellOut.new("prlctl --version")
61
75
  cmd.run_command
62
- cmd.stdout.split(' ')[2]
76
+ cmd.stdout.split(" ")[2]
63
77
  end
64
78
 
65
79
  def ver_vbox
66
80
  cmd = Mixlib::ShellOut.new("VBoxManage --version")
67
81
  cmd.run_command
68
- cmd.stdout.split('r')[0]
82
+ cmd.stdout.split("r")[0]
69
83
  end
70
84
  end
@@ -1,21 +1,21 @@
1
- require 'bento/common'
2
- require 'bento/vagrantcloud'
1
+ require "bento/common"
3
2
 
4
3
  class ReleaseRunner
5
4
  include Common
6
- include VgCloud
7
5
 
8
- attr_reader :boxname, :version
6
+ attr_reader :box, :version
9
7
 
10
8
  def initialize(opts)
11
- @boxname = opts.box
9
+ @box = opts.box
12
10
  @version = opts.version
13
11
  end
14
12
 
15
13
  def start
16
- banner("Starting Release...")
14
+ banner("Releasing #{box}/#{version}...")
17
15
  time = Benchmark.measure do
18
- box_release_version(boxname, version)
16
+ box = vc_account.get_box(box)
17
+ version = box.get_version(version)
18
+ version.release
19
19
  end
20
20
  banner("Release finished in #{duration(time.real)}.")
21
21
  end
@@ -1,21 +1,21 @@
1
- require 'bento/common'
2
- require 'bento/vagrantcloud'
1
+ require "bento/common"
3
2
 
4
3
  class RevokeRunner
5
4
  include Common
6
- include VgCloud
7
5
 
8
- attr_reader :boxname, :version
6
+ attr_reader :box, :version
9
7
 
10
8
  def initialize(opts)
11
- @boxname = opts.box
9
+ @box = opts.box
12
10
  @version = opts.version
13
11
  end
14
12
 
15
13
  def start
16
- banner("Starting Revoke...")
14
+ banner("Revoking #{box}/#{version}...")
17
15
  time = Benchmark.measure do
18
- box_revoke_version(boxname, version)
16
+ box = vc_account.get_box(box)
17
+ version = box.get_version(version)
18
+ version.revoke
19
19
  end
20
20
  banner("Revoke finished in #{duration(time.real)}.")
21
21
  end
@@ -1,6 +1,6 @@
1
- require 'bento/common'
2
- require 'mixlib/shellout'
3
- require 'erb'
1
+ require "bento/common"
2
+ require "mixlib/shellout"
3
+ require "erb"
4
4
 
5
5
  class TestRunner
6
6
  include Common
@@ -33,7 +33,7 @@ class TestRunner
33
33
  boxes = cmd.stdout.split("\n")
34
34
 
35
35
  boxes.each do |box|
36
- b = box.split(' ')
36
+ b = box.split(" ")
37
37
  rm_cmd = Mixlib::ShellOut.new("vagrant box remove --force #{b[0]} --provider #{b[1].to_s.gsub(/(,|\()/, '')}")
38
38
  banner("Removing #{b[0]} for provider #{b[1].to_s.gsub(/(,|\()/, '')}")
39
39
  rm_cmd.run_command
@@ -42,15 +42,19 @@ class TestRunner
42
42
 
43
43
  def test_box(md_json)
44
44
  md = box_metadata(md_json)
45
- @boxname = md['name']
46
- @providers = md['providers']
47
- @share_disabled = no_shared || /freebsd/.match(boxname) ? true : false
45
+ @boxname = md["name"]
46
+ @providers = md["providers"]
47
+ @share_disabled = no_shared || /(freebsd|opensuse)/.match(boxname) ? true : false
48
48
 
49
49
  dir = "#{File.expand_path("../../", File.dirname(__FILE__))}/templates"
50
- kitchen_cfg = ERB.new(File.read(dir + '/kitchen.yml.erb'), nil, '-').result(binding)
51
- File.open(".kitchen.yml", "w") { |f| f.puts kitchen_cfg }
50
+ %w{.kitchen.yml bootstrap.sh}.each do |file|
51
+ t = file =~ /kitchen/ ? "kitchen.yml.erb" : "#{file}.erb"
52
+ erb = ERB.new(File.read(dir + "/#{t}"), nil, "-").result(binding)
53
+ File.open(file, "w") { |f| f.puts erb }
54
+ end
52
55
 
53
- kitchen_test = Mixlib::ShellOut.new("kitchen test", :timeout => 900, live_stream: STDOUT)
54
- kitchen_test.run_command
56
+ test = Mixlib::ShellOut.new("kitchen test", :timeout => 900, live_stream: STDOUT)
57
+ test.run_command
58
+ test.error!
55
59
  end
56
60
  end
@@ -1,9 +1,7 @@
1
- require 'bento/common'
2
- require 'bento/vagrantcloud'
1
+ require "bento/common"
3
2
 
4
3
  class UploadRunner
5
4
  include Common
6
- include VgCloud
7
5
 
8
6
  attr_reader :md_json
9
7
 
@@ -14,14 +12,25 @@ class UploadRunner
14
12
  def start
15
13
  banner("Starting uploads...")
16
14
  time = Benchmark.measure do
17
- if md_json.nil?
18
- metadata_files.each do |md_file|
19
- box_upload(md_file)
20
- end
21
- else
22
- box_upload(md_json)
15
+ files = md_json ? [md_json] : metadata_files
16
+ files.each do |md_file|
17
+ upload(md_file)
23
18
  end
24
19
  end
25
- banner("Atlas uploads finished in #{duration(time.real)}.")
20
+ banner("Uploads finished in #{duration(time.real)}.")
21
+ end
22
+
23
+ def upload(md_file)
24
+ md = box_metadata(md_file)
25
+ box_description = "a bento box for #{md['name']}"
26
+ box = vc_account.ensure_box(md["name"], box_description, private_box?(md["name"]))
27
+ version = box.ensure_version(md["version"], File.read(md_file))
28
+
29
+ md["providers"].each do |k, v|
30
+ provider = version.ensure_provider(k, nil)
31
+ banner("Uploading #{box.name}/#{version.version}/#{provider.name}...")
32
+ provider.upload_file("builds/#{v['file']}")
33
+ banner("#{provider.download_url}")
34
+ end
26
35
  end
27
36
  end
@@ -1,3 +1,3 @@
1
1
  module Bento
2
- VERSION = "0.1.4"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1 @@
1
+ echo "Shell Provisioner Says What"
@@ -7,11 +7,11 @@ platforms:
7
7
  - name: <%= @boxname + '-' + k %>
8
8
  driver:
9
9
  name: vagrant
10
- <% if k == 'vmware' -%>
10
+ <% if k =~ /vmware/ -%>
11
11
  <% if RUBY_PLATFORM.match(/darwin/) -%>
12
- provider: <%= k + '_fusion' %>
12
+ provider: <%= 'vmware_fusion' %>
13
13
  <% else -%>
14
- provider: <%= k + '_workstation' %>
14
+ provider: <%= 'vmware_workstation' %>
15
15
  <% end -%>
16
16
  <% else -%>
17
17
  provider: <%= k %>
metadata CHANGED
@@ -1,57 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bento-ya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Thomas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-05 00:00:00.000000000 Z
11
+ date: 2017-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '11.2'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '11.2'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: mixlib-shellout
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - "~>"
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: '2.2'
19
+ version: 2.3.2
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - "~>"
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: '2.2'
26
+ version: 2.3.2
41
27
  - !ruby/object:Gem::Dependency
42
- name: buildkit
28
+ name: vagrant_cloud
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '0.4'
33
+ version: '1.0'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '0.4'
40
+ version: '1.0'
55
41
  description: bento-ya builds bento boxes
56
42
  email:
57
43
  - sthomas@chef.io
@@ -61,6 +47,7 @@ extensions: []
61
47
  extra_rdoc_files: []
62
48
  files:
63
49
  - ".gitignore"
50
+ - ".travis.yml"
64
51
  - CHANGELOG.md
65
52
  - Gemfile
66
53
  - LICENSE
@@ -70,12 +57,10 @@ files:
70
57
  - bin/bento
71
58
  - lib/bento.rb
72
59
  - lib/bento/build.rb
73
- - lib/bento/build_remote.rb
74
60
  - lib/bento/buildmetadata.rb
75
61
  - lib/bento/cli.rb
76
62
  - lib/bento/common.rb
77
63
  - lib/bento/delete.rb
78
- - lib/bento/httpstuff.rb
79
64
  - lib/bento/normalize.rb
80
65
  - lib/bento/packerexec.rb
81
66
  - lib/bento/providermetadata.rb
@@ -83,8 +68,8 @@ files:
83
68
  - lib/bento/revoke.rb
84
69
  - lib/bento/test.rb
85
70
  - lib/bento/upload.rb
86
- - lib/bento/vagrantcloud.rb
87
71
  - lib/bento/version.rb
72
+ - templates/bootstrap.sh.erb
88
73
  - templates/kitchen.yml.erb
89
74
  homepage: https://github.com/cheeseplus/bento-ya
90
75
  licenses: