daptiv-chef-ci 0.0.15 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/daptiv-chef-ci.gemspec +21 -20
  3. data/lib/daptiv-chef-ci/clone_environment_task.rb +69 -0
  4. data/lib/daptiv-chef-ci/logger.rb +9 -10
  5. data/lib/daptiv-chef-ci/raketask_helper.rb +5 -6
  6. data/lib/daptiv-chef-ci/shell.rb +50 -28
  7. data/lib/daptiv-chef-ci/upload_cookbook_task.rb +62 -0
  8. data/lib/daptiv-chef-ci/vagrant_destroy_task.rb +11 -12
  9. data/lib/daptiv-chef-ci/vagrant_driver.rb +47 -56
  10. data/lib/daptiv-chef-ci/vagrant_provision_task.rb +12 -15
  11. data/lib/daptiv-chef-ci/vagrant_task.rb +34 -57
  12. data/lib/daptiv-chef-ci/vagrant_up_task.rb +14 -16
  13. data/lib/daptiv-chef-ci/version_cookbook_task.rb +69 -0
  14. data/lib/daptiv-chef-ci/virtualbox_driver.rb +11 -12
  15. data/spec/daptiv-chef-ci/logger_spec.rb +11 -15
  16. data/spec/daptiv-chef-ci/shell_spec.rb +23 -27
  17. data/spec/daptiv-chef-ci/vagrant_destroy_task_spec.rb +5 -7
  18. data/spec/daptiv-chef-ci/vagrant_driver_spec.rb +34 -72
  19. data/spec/daptiv-chef-ci/vagrant_provision_task_spec.rb +9 -13
  20. data/spec/daptiv-chef-ci/vagrant_task_spec.rb +29 -21
  21. data/spec/daptiv-chef-ci/vagrant_up_task_spec.rb +9 -12
  22. data/spec/daptiv-chef-ci/virtualbox_driver_spec.rb +21 -16
  23. data/spec/shared_contexts/rake.rb +7 -7
  24. metadata +21 -14
  25. data/lib/daptiv-chef-ci/basebox_builder_factory.rb +0 -19
  26. data/lib/daptiv-chef-ci/virtualbox_basebox_builder.rb +0 -33
  27. data/lib/daptiv-chef-ci/vmware_basebox_builder.rb +0 -103
  28. data/spec/daptiv-chef-ci/basebox_builder_factory_spec.rb +0 -25
  29. data/spec/daptiv-chef-ci/virtualbox_basebox_builder_spec.rb +0 -20
  30. data/spec/daptiv-chef-ci/vmware_basebox_builder_spec.rb +0 -20
@@ -1,29 +1,26 @@
1
1
  require 'daptiv-chef-ci/vagrant_up_task'
2
2
  require_relative '../shared_contexts/rake'
3
3
 
4
- describe VagrantUp::RakeTask, :unit => true do
4
+ describe VagrantUp::RakeTask, unit: true do
5
5
  include_context 'rake'
6
6
 
7
7
  describe 'vagrant_up' do
8
8
  it 'should up the box' do
9
+ vagrant_driver.should_receive(:up)
10
+ .with(cmd_timeout_in_seconds: 7200, environment: {})
9
11
 
10
- vagrant_driver.should_receive(:up).with({ :cmd_timeout_in_seconds => 7200, :environment => {} })
11
-
12
12
  task = rake['vagrant_up']
13
- task.invoke()
14
-
13
+ task.invoke
15
14
  end
16
-
15
+
17
16
  it 'should up the box with the specified environment vars' do
17
+ environment = { ENV_VAR1: 'val1', ENV_VAR2: 'val2' }
18
+ vagrant_driver.should_receive(:up)
19
+ .with(cmd_timeout_in_seconds: 7200, environment: environment)
18
20
 
19
- environment = { :ENV_VAR1 => 'val1', :ENV_VAR2 => 'val2' }
20
- vagrant_driver.should_receive(:up).with({ :cmd_timeout_in_seconds => 7200, :environment => environment })
21
-
22
21
  task = rake['vagrant_up']
23
22
  subject.environment = environment
24
- task.invoke()
25
-
23
+ task.invoke
26
24
  end
27
25
  end
28
-
29
26
  end
@@ -1,8 +1,7 @@
1
1
  require 'daptiv-chef-ci/virtualbox_driver'
2
2
  require 'daptiv-chef-ci/logger'
3
3
 
4
- describe DaptivChefCI::VirtualBoxDriver, :unit => true do
5
-
4
+ describe DaptivChefCI::VirtualBoxDriver, unit: true do
6
5
  describe 'cleanup_vms' do
7
6
  it 'should poweroff and unregister all machines with a matching name' do
8
7
  boxes = [
@@ -10,22 +9,28 @@ describe DaptivChefCI::VirtualBoxDriver, :unit => true do
10
9
  '"aspnet_1379346156" {7bb1bbce-c6cc-47a2-9c51-57ede42e02b5}',
11
10
  '"python_1372120178" {c1937a1c-c6c4-4777-88d0-dfa9066fb156}'
12
11
  ]
13
- @shell = mock()
12
+ @shell = mock
14
13
  @vbox = DaptivChefCI::VirtualBoxDriver.new(@shell)
15
-
16
- @shell.should_receive(:exec_cmd).with('vboxmanage list runningvms').and_return(boxes)
17
-
18
- @shell.should_receive(:exec_cmd).with('vboxmanage controlvm "aspnet_1372120179" poweroff').once()
19
- @shell.should_receive(:exec_cmd).with('vboxmanage unregistervm "aspnet_1372120179"').once()
20
-
21
- @shell.should_receive(:exec_cmd).with('vboxmanage controlvm "aspnet_1379346156" poweroff').once()
22
- @shell.should_receive(:exec_cmd).with('vboxmanage unregistervm "aspnet_1379346156"').once()
23
-
24
- @shell.should_receive(:exec_cmd).with('vboxmanage controlvm "python_1372120178" poweroff').never()
25
- @shell.should_receive(:exec_cmd).with('vboxmanage unregistervm "python_1372120178"').never()
26
-
14
+
15
+ @shell.should_receive(:exec_cmd)
16
+ .with('vboxmanage list runningvms').and_return(boxes)
17
+
18
+ @shell.should_receive(:exec_cmd)
19
+ .with('vboxmanage controlvm "aspnet_1372120179" poweroff').once
20
+ @shell.should_receive(:exec_cmd)
21
+ .with('vboxmanage unregistervm "aspnet_1372120179"').once
22
+
23
+ @shell.should_receive(:exec_cmd)
24
+ .with('vboxmanage controlvm "aspnet_1379346156" poweroff').once
25
+ @shell.should_receive(:exec_cmd)
26
+ .with('vboxmanage unregistervm "aspnet_1379346156"').once
27
+
28
+ @shell.should_receive(:exec_cmd)
29
+ .with('vboxmanage controlvm "python_1372120178" poweroff').never
30
+ @shell.should_receive(:exec_cmd)
31
+ .with('vboxmanage unregistervm "python_1372120178"').never
32
+
27
33
  @vbox.cleanup_vms('aspnet')
28
34
  end
29
35
  end
30
-
31
36
  end
@@ -1,17 +1,17 @@
1
- require "rake"
1
+ require 'rake'
2
2
  require 'daptiv-chef-ci/raketask_helper'
3
3
 
4
- shared_context "rake" do
5
- let(:rake) { create_rake_application() }
6
- let(:vagrant_driver) { stub() }
7
-
4
+ shared_context 'rake' do
5
+ let(:rake) { create_rake_application }
6
+ let(:vagrant_driver) { stub }
7
+
8
8
  # let the errors bubble up normally, don't exit the app
9
9
  before { DaptivChefCI::RakeTaskHelpers.exit_on_failure = false }
10
-
10
+
11
11
  def create_rake_application
12
12
  Rake.application = Rake::Application.new
13
13
  subject.vagrant_driver = vagrant_driver
14
14
  Rake::Task.define_task(subject)
15
15
  Rake.application
16
16
  end
17
- end
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daptiv-chef-ci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn Neal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-13 00:00:00.000000000 Z
11
+ date: 2015-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: log4r
@@ -30,14 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 1.6.0
33
+ version: '1.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 1.6.0
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: versionomy
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.4.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.4
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -103,22 +117,20 @@ extra_rdoc_files: []
103
117
  files:
104
118
  - daptiv-chef-ci.gemspec
105
119
  - Gemfile
106
- - lib/daptiv-chef-ci/basebox_builder_factory.rb
120
+ - lib/daptiv-chef-ci/clone_environment_task.rb
107
121
  - lib/daptiv-chef-ci/logger.rb
108
122
  - lib/daptiv-chef-ci/raketask_helper.rb
109
123
  - lib/daptiv-chef-ci/shell.rb
124
+ - lib/daptiv-chef-ci/upload_cookbook_task.rb
110
125
  - lib/daptiv-chef-ci/vagrant_destroy_task.rb
111
126
  - lib/daptiv-chef-ci/vagrant_driver.rb
112
127
  - lib/daptiv-chef-ci/vagrant_provision_task.rb
113
128
  - lib/daptiv-chef-ci/vagrant_task.rb
114
129
  - lib/daptiv-chef-ci/vagrant_up_task.rb
115
- - lib/daptiv-chef-ci/virtualbox_basebox_builder.rb
130
+ - lib/daptiv-chef-ci/version_cookbook_task.rb
116
131
  - lib/daptiv-chef-ci/virtualbox_driver.rb
117
- - lib/daptiv-chef-ci/vmware_basebox_builder.rb
118
- - pkg/daptiv-chef-ci-0.0.14.gem
119
132
  - Rakefile
120
133
  - README.md
121
- - spec/daptiv-chef-ci/basebox_builder_factory_spec.rb
122
134
  - spec/daptiv-chef-ci/logger_spec.rb
123
135
  - spec/daptiv-chef-ci/shell_spec.rb
124
136
  - spec/daptiv-chef-ci/vagrant_destroy_task_spec.rb
@@ -126,9 +138,7 @@ files:
126
138
  - spec/daptiv-chef-ci/vagrant_provision_task_spec.rb
127
139
  - spec/daptiv-chef-ci/vagrant_task_spec.rb
128
140
  - spec/daptiv-chef-ci/vagrant_up_task_spec.rb
129
- - spec/daptiv-chef-ci/virtualbox_basebox_builder_spec.rb
130
141
  - spec/daptiv-chef-ci/virtualbox_driver_spec.rb
131
- - spec/daptiv-chef-ci/vmware_basebox_builder_spec.rb
132
142
  - spec/shared_contexts/rake.rb
133
143
  - .gitignore
134
144
  homepage: ''
@@ -155,7 +165,6 @@ signing_key:
155
165
  specification_version: 4
156
166
  summary: A small gem to reduce Rake duplication
157
167
  test_files:
158
- - spec/daptiv-chef-ci/basebox_builder_factory_spec.rb
159
168
  - spec/daptiv-chef-ci/logger_spec.rb
160
169
  - spec/daptiv-chef-ci/shell_spec.rb
161
170
  - spec/daptiv-chef-ci/vagrant_destroy_task_spec.rb
@@ -163,7 +172,5 @@ test_files:
163
172
  - spec/daptiv-chef-ci/vagrant_provision_task_spec.rb
164
173
  - spec/daptiv-chef-ci/vagrant_task_spec.rb
165
174
  - spec/daptiv-chef-ci/vagrant_up_task_spec.rb
166
- - spec/daptiv-chef-ci/virtualbox_basebox_builder_spec.rb
167
175
  - spec/daptiv-chef-ci/virtualbox_driver_spec.rb
168
- - spec/daptiv-chef-ci/vmware_basebox_builder_spec.rb
169
176
  - spec/shared_contexts/rake.rb
@@ -1,19 +0,0 @@
1
- require 'log4r'
2
- require_relative 'shell'
3
- require_relative 'vmware_basebox_builder'
4
- require_relative 'virtualbox_basebox_builder'
5
-
6
- module DaptivChefCI
7
-
8
- # Abstract factory to produce base box builder instances based off the specified provider
9
- class BaseBoxBuilderFactory
10
-
11
- # Creates a new base box builder instance
12
- def create(shell, provider, base_dir)
13
- provider == :vmware_fusion ?
14
- DaptivChefCI::VMwareBaseBoxBuilder.new(base_dir) :
15
- DaptivChefCI::VirtualBoxBaseBoxBuilder.new(base_dir, shell)
16
- end
17
-
18
- end
19
- end
@@ -1,33 +0,0 @@
1
- require 'log4r'
2
- require 'fileutils'
3
- require_relative 'shell'
4
-
5
- module DaptivChefCI
6
-
7
- # This class builds VBox Vagrant boxes
8
- class VirtualBoxBaseBoxBuilder
9
-
10
- # Creates a new box builder instance
11
- #
12
- # @param [String] The full path to the directory where the Vagrantfile exists
13
- # of the box we want to package, i.e. /Users/admin/src/dotnetframework
14
- # @param [Shell] A shell instance
15
- def initialize(base_dir, shell)
16
- @shell = shell
17
- @base_dir = base_dir
18
- @logger = Log4r::Logger.new("daptiv_chef_ci::vmware_base_box_builder")
19
- end
20
-
21
- # Packages a VBox Vagrant box. This can take 15 minutes or so.
22
- #
23
- # @param [String] base box file name, i.e. 'windows-server-2008.box'
24
- def build(box_file)
25
- Dir.chdir(@base_dir) {
26
- @logger.info("Packaging box #{box_file}")
27
- FileUtils.rm(box_file) if File.exists?(box_file)
28
- @shell.exec_cmd("vagrant package --output #{box_file}", 3600)
29
- }
30
- end
31
-
32
- end
33
- end
@@ -1,103 +0,0 @@
1
- require 'log4r'
2
- require 'fileutils'
3
- require_relative 'shell'
4
-
5
- module DaptivChefCI
6
-
7
- # This class builds VMware Fusion 6 Vagrant boxes on OS X
8
- #
9
- # NOTE - This class makes a lot of assumptions that hopefully won't break until
10
- # after Vagrant natively supports packaging VMware Fusion boxes.
11
- class VMwareBaseBoxBuilder
12
-
13
- # Creates a new box builder instance
14
- #
15
- # @param [String] The full path to the directory where the Vagrantfile exists
16
- # of the box we want to package, i.e. /Users/admin/src/dotnetframework
17
- def initialize(base_dir)
18
- @base_dir = base_dir
19
- @logger = Log4r::Logger.new("daptiv_chef_ci::vmware_base_box_builder")
20
- end
21
-
22
- # Packages a VMware Fusion Vagrant box. This can take 15 minutes or so.
23
- #
24
- # @param [String] base box file name, i.e. 'windows-server-2008.box'
25
- def build(box_file)
26
- # /Users/admin/src/mybox/.vagrant/machines/default/vmware_fusion/0f721388-a327-4ba3-b203-c09f69016b43/
27
- box_root_path = "#{@base_dir}/.vagrant/machines/default/vmware_fusion"
28
-
29
- sub_dir = Dir["#{box_root_path}/*/"]
30
- .map { |d| File.basename(d) }
31
- .find { |d| d =~ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/ }
32
-
33
- box_path = "#{box_root_path}/#{sub_dir}"
34
- @logger.debug("box_path: #{box_path}")
35
-
36
- build_box(box_path, box_file)
37
- end
38
-
39
-
40
- protected
41
-
42
- def build_box(box_path, box_file)
43
- tar_list_path = "#{box_path}/boxfilelist.txt"
44
- completed_box_path = "#{@base_dir}/#{box_file}"
45
-
46
- @logger.debug("tar_list_path: #{tar_list_path}")
47
- @logger.debug("completed_box_path: #{completed_box_path}")
48
-
49
- Dir.chdir(box_path) {
50
- vmdk_file = File.expand_path(Dir.glob("*.vmdk").first())
51
-
52
- args = [vdiskmanager_path]
53
- args << '-d'
54
- args << vmdk_file
55
- @logger.info("Defragging #{vmdk_file}")
56
- system(*args)
57
-
58
- args = [vdiskmanager_path]
59
- args << '-k'
60
- args << vmdk_file
61
- @logger.info("Shrinking #{vmdk_file}")
62
- system(*args)
63
-
64
- create_json_manifest(box_path)
65
- create_tar_manifest(tar_list_path)
66
-
67
- @logger.info("Packaging box #{box_file}")
68
- tar_cmd = "tar -czvf #{box_file} -T #{tar_list_path}"
69
- %x[#{tar_cmd}]
70
- FileUtils.rm(completed_box_path) if File.exists?(completed_box_path)
71
- FileUtils.mv(box_file, completed_box_path)
72
- }
73
-
74
- @logger.info("Done creating box #{completed_box_path}")
75
- end
76
-
77
- def create_tar_manifest(tar_list_path)
78
- @logger.debug("Creating manifest #{tar_list_path}")
79
-
80
- files = Dir.glob("*.{vmdk,nvram,plist,vmsd,vmx,vmxf,json}").join("\n")
81
- @logger.debug("Found the following files to pack: #{files}")
82
-
83
- FileUtils.rm(tar_list_path) if File.exists?(tar_list_path)
84
- IO.write(tar_list_path, files)
85
- end
86
-
87
- def create_json_manifest(box_path)
88
- json_manifest_path = File.join(box_path, "metadata.json")
89
- FileUtils.rm(json_manifest_path) if File.exists?(json_manifest_path)
90
- manifest = <<-EOH
91
- {
92
- "provider":"vmware_fusion"
93
- }
94
- EOH
95
- IO.write(json_manifest_path, manifest)
96
- end
97
-
98
- def vdiskmanager_path
99
- '/Applications/VMware Fusion.app/Contents/Library/vmware-vdiskmanager'
100
- end
101
-
102
- end
103
- end
@@ -1,25 +0,0 @@
1
- require 'daptiv-chef-ci/basebox_builder_factory'
2
- require 'daptiv-chef-ci/virtualbox_basebox_builder'
3
- require 'daptiv-chef-ci/vmware_basebox_builder'
4
-
5
- describe DaptivChefCI::BaseBoxBuilderFactory, :unit => true do
6
-
7
- before(:each) do
8
- @shell = stub()
9
- @factory = DaptivChefCI::BaseBoxBuilderFactory.new()
10
- end
11
-
12
- describe 'create' do
13
-
14
- it 'should create VMware builder when provider is vmware_fusion' do
15
- builder = @factory.create(@shell, :vmware_fusion, Dir.pwd)
16
- expect(builder).to be_an_instance_of(DaptivChefCI::VMwareBaseBoxBuilder)
17
- end
18
-
19
- it 'should create VMware builder when provider is virtualbox' do
20
- builder = @factory.create(@shell, :virtualbox, Dir.pwd)
21
- expect(builder).to be_an_instance_of(DaptivChefCI::VirtualBoxBaseBoxBuilder)
22
- end
23
-
24
- end
25
- end
@@ -1,20 +0,0 @@
1
- require 'daptiv-chef-ci/virtualbox_basebox_builder'
2
- require 'daptiv-chef-ci/logger'
3
-
4
- describe DaptivChefCI::VirtualBoxBaseBoxBuilder, :integration => true do
5
-
6
- #Note- This test requires you have
7
- # 1. the dotnetframework cookbook cloned to ~/src/dotnetframework
8
- # 2. From ~/src/dotnetframework previously ran: vagrant up
9
- # 3. vagrant halt
10
-
11
- describe 'build' do
12
- it 'should build a VBox Vagrant base box' do
13
- base_dir = "#{ENV['HOME']}/src/dotnetframework"
14
- builder = DaptivChefCI::VirtualBoxBaseBoxBuilder.new(base_dir, DaptivChefCI::Shell.new())
15
- builder.build('dotnettest-vbox.box')
16
- expect(File.exists?("#{base_dir}/dotnettest-vbox.box"))
17
- end
18
- end
19
-
20
- end
@@ -1,20 +0,0 @@
1
- require 'daptiv-chef-ci/vmware_basebox_builder'
2
- require 'daptiv-chef-ci/logger'
3
-
4
- describe DaptivChefCI::VMwareBaseBoxBuilder, :integration => true do
5
-
6
- #Note- This test requires you have
7
- # 1. the dotnetframework cookbook cloned to ~/src/dotnetframework
8
- # 2. From ~/src/dotnetframework previously ran: vagrant up --provider vmware_fusion
9
- # 3. vagrant halt
10
-
11
- describe 'build' do
12
- it 'should build a VMware Vagrant base box' do
13
- base_dir = "#{ENV['HOME']}/src/dotnetframework"
14
- builder = DaptivChefCI::VMwareBaseBoxBuilder.new(base_dir)
15
- builder.build('dotnettest-vmware.box')
16
- expect(File.exists?("#{base_dir}/dotnettest-vmware.box"))
17
- end
18
- end
19
-
20
- end