bosh-stemcell 1.2175.0 → 1.2200.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.
@@ -6,12 +6,24 @@ module Bosh::Stemcell
6
6
  Go.new
7
7
  when 'ruby'
8
8
  Ruby.new
9
+ when 'null'
10
+ NullAgent.new
9
11
  else
10
12
  raise ArgumentError.new("invalid agent: #{name}")
11
13
  end
12
14
 
13
15
  end
14
16
 
17
+ class NullAgent
18
+ def name
19
+ 'null'
20
+ end
21
+
22
+ def ==(other)
23
+ name == other.name
24
+ end
25
+ end
26
+
15
27
  class Go
16
28
  def name
17
29
  'go'
@@ -0,0 +1,11 @@
1
+ module Bosh::Stemcell
2
+ class ArchiveHandler
3
+ def initialize
4
+ @shell = Bosh::Core::Shell.new
5
+ end
6
+
7
+ def compress(directory, archive_filename)
8
+ @shell.run("sudo tar -cz -f #{archive_filename} -C #{directory} .")
9
+ end
10
+ end
11
+ end
@@ -1,79 +1,48 @@
1
- require 'fileutils'
2
-
3
1
  require 'bosh/core/shell'
4
2
  require 'bosh/stemcell/builder_options'
5
- require 'bosh/stemcell/disk_image'
6
- require 'bosh/stemcell/definition'
7
- require 'bosh/stemcell/stage_collection'
8
- require 'bosh/stemcell/stage_runner'
9
-
10
3
  require 'forwardable'
11
4
 
12
5
  module Bosh::Stemcell
13
- class BuilderCommand
6
+ class BuildEnvironment
14
7
  extend Forwardable
15
8
 
16
- def initialize(env, definition, version, release_tarball_path)
9
+ STEMCELL_BUILDER_SOURCE_DIR = File.join(File.expand_path('../../../../..', __FILE__), 'stemcell_builder')
10
+ STEMCELL_SPECS_DIR = File.expand_path('../../..', File.dirname(__FILE__))
11
+
12
+ def initialize(env, definition, version, release_tarball_path, os_image_tarball_path)
17
13
  @environment = env
18
14
  @definition = definition
15
+ @os_image_tarball_path = os_image_tarball_path
19
16
  @stemcell_builder_options = BuilderOptions.new(
20
- env,
21
- definition,
22
- version,
23
- release_tarball_path,
17
+ env: env,
18
+ definition: definition,
19
+ version: version,
20
+ release_tarball: release_tarball_path,
21
+ os_image_tarball: os_image_tarball_path,
24
22
  )
25
23
  @shell = Bosh::Core::Shell.new
26
24
  end
27
25
 
28
- def build
26
+ def prepare_build
29
27
  sanitize
30
-
31
- prepare_build_root
32
-
33
28
  prepare_build_path
34
-
35
29
  copy_stemcell_builder_to_build_path
36
-
37
30
  prepare_work_root
38
-
39
31
  persist_settings_for_bash
40
-
41
- stage_collection = StageCollection.new(definition)
42
- stage_runner = StageRunner.new(
43
- build_path: build_path,
44
- command_env: command_env,
45
- settings_file: settings_path,
46
- work_path: work_root
47
- )
48
- stage_runner.configure_and_apply(stage_collection.all_stages)
49
- system(rspec_command) || raise('Stemcell specs failed')
50
-
51
- stemcell_file
52
32
  end
53
33
 
54
- def chroot_dir
55
- File.join(work_path, 'chroot')
34
+ def os_image_rspec_command
35
+ [
36
+ "cd #{STEMCELL_SPECS_DIR};",
37
+ "OS_IMAGE=#{os_image_tarball_path}",
38
+ 'bundle exec rspec -fd',
39
+ "spec/os_image/#{operating_system.name}_spec.rb",
40
+ ].join(' ')
56
41
  end
57
42
 
58
- private
59
-
60
- def_delegators(
61
- :@definition,
62
- :infrastructure,
63
- :operating_system,
64
- :agent,
65
- )
66
-
67
- attr_reader(
68
- :shell,
69
- :environment,
70
- :definition,
71
- :stemcell_builder_options
72
- )
73
-
74
- def rspec_command
43
+ def stemcell_rspec_command
75
44
  [
76
- "cd #{File.expand_path('../../..', File.dirname(__FILE__))};",
45
+ "cd #{STEMCELL_SPECS_DIR};",
77
46
  "STEMCELL_IMAGE=#{image_file_path}",
78
47
  "bundle exec rspec -fd#{exclude_exclusions}",
79
48
  "spec/stemcells/#{operating_system.name}_spec.rb",
@@ -82,80 +51,69 @@ module Bosh::Stemcell
82
51
  ].join(' ')
83
52
  end
84
53
 
85
- def exclude_exclusions
86
- case infrastructure.name
87
- when 'vsphere'
88
- ' --tag ~exclude_on_vsphere'
89
- when 'vcloud'
90
- ' --tag ~exclude_on_vcloud'
91
- else
92
- ''
93
- end
54
+ def build_path
55
+ File.join(build_root, 'build')
94
56
  end
95
57
 
96
- def image_file_path
97
- File.join(work_path, settings['stemcell_image_name'])
58
+ def stemcell_file
59
+ File.join(work_path, settings['stemcell_tgz'])
98
60
  end
99
61
 
100
- def image_mount_point
101
- File.join(work_path, 'mnt')
62
+ def chroot_dir
63
+ File.join(work_path, 'chroot')
102
64
  end
103
65
 
104
- def sanitize
105
- FileUtils.rm_rf('*.tgz')
106
-
107
- system("sudo umount #{File.join(work_path, 'mnt/tmp/grub', settings['stemcell_image_name'])} 2> /dev/null")
108
- system("sudo umount #{image_mount_point} 2> /dev/null")
109
- system("sudo rm -rf #{base_directory}")
66
+ def settings_path
67
+ File.join(build_path, 'etc', 'settings.bash')
110
68
  end
111
69
 
112
- def settings
113
- stemcell_builder_options.default
70
+ def work_path
71
+ File.join(work_root, 'work')
114
72
  end
115
73
 
116
- def base_directory
117
- File.join('/mnt', 'stemcells', infrastructure.name, infrastructure.hypervisor, operating_system.name)
74
+ def command_env
75
+ "env #{hash_as_bash_env(proxy_settings_from_environment)}"
118
76
  end
119
77
 
120
- def build_root
121
- File.join(base_directory, 'build')
122
- end
78
+ private
123
79
 
124
- def work_root
125
- File.join(base_directory, 'work')
126
- end
80
+ def_delegators(
81
+ :@definition,
82
+ :infrastructure,
83
+ :operating_system,
84
+ :agent,
85
+ )
127
86
 
128
- def prepare_build_root
129
- FileUtils.mkdir_p(build_root, verbose: true)
130
- end
87
+ attr_reader(
88
+ :shell,
89
+ :environment,
90
+ :definition,
91
+ :stemcell_builder_options,
92
+ :os_image_tarball_path,
93
+ )
131
94
 
132
- def prepare_work_root
133
- FileUtils.mkdir_p(work_root, verbose: true)
134
- end
95
+ def sanitize
96
+ FileUtils.rm(Dir.glob('*.tgz'))
135
97
 
136
- def build_path
137
- File.join(build_root, 'build')
138
- end
98
+ shell.run("sudo umount #{File.join(work_path, 'mnt/tmp/grub', settings['stemcell_image_name'])} 2> /dev/null",
99
+ { ignore_failures: true })
139
100
 
140
- def work_path
141
- File.join(work_root, 'work')
101
+ shell.run("sudo umount #{image_mount_point} 2> /dev/null", { ignore_failures: true })
102
+
103
+ shell.run("sudo rm -rf #{base_directory}", { ignore_failures: true })
142
104
  end
143
105
 
144
106
  def prepare_build_path
145
- FileUtils.rm_rf(build_path, verbose: true) if Dir.exists?(build_path)
107
+ FileUtils.rm_rf(build_path, verbose: true) if File.exist?(build_path)
146
108
  FileUtils.mkdir_p(build_path, verbose: true)
147
109
  end
148
110
 
149
- def stemcell_builder_source_dir
150
- File.join(File.expand_path('../../../../..', __FILE__), 'stemcell_builder')
151
- end
152
-
153
111
  def copy_stemcell_builder_to_build_path
154
- FileUtils.cp_r(Dir.glob("#{stemcell_builder_source_dir}/*"), build_path, preserve: true, verbose: true)
112
+ FileUtils.cp_r(Dir.glob("#{STEMCELL_BUILDER_SOURCE_DIR}/*"), build_path, preserve: true, verbose: true)
155
113
  end
156
114
 
157
- def settings_path
158
- File.join(build_path, 'etc', 'settings.bash')
115
+ def prepare_work_root
116
+ FileUtils.mkdir_p(work_root, verbose: true)
159
117
  end
160
118
 
161
119
  def persist_settings_for_bash
@@ -167,12 +125,39 @@ module Bosh::Stemcell
167
125
  end
168
126
  end
169
127
 
170
- def command_env
171
- "env #{hash_as_bash_env(proxy_settings_from_environment)}"
128
+ def exclude_exclusions
129
+ case infrastructure.name
130
+ when 'vsphere'
131
+ ' --tag ~exclude_on_vsphere'
132
+ when 'vcloud'
133
+ ' --tag ~exclude_on_vcloud'
134
+ else
135
+ ''
136
+ end
172
137
  end
173
138
 
174
- def stemcell_file
175
- File.join(work_path, settings['stemcell_tgz'])
139
+ def image_file_path
140
+ File.join(work_path, settings['stemcell_image_name'])
141
+ end
142
+
143
+ def image_mount_point
144
+ File.join(work_path, 'mnt')
145
+ end
146
+
147
+ def settings
148
+ stemcell_builder_options.default
149
+ end
150
+
151
+ def base_directory
152
+ File.join('/mnt', 'stemcells', infrastructure.name, infrastructure.hypervisor, operating_system.name)
153
+ end
154
+
155
+ def build_root
156
+ File.join(base_directory, 'build')
157
+ end
158
+
159
+ def work_root
160
+ File.join(base_directory, 'work')
176
161
  end
177
162
 
178
163
  def proxy_settings_from_environment
@@ -8,13 +8,14 @@ module Bosh::Stemcell
8
8
  class BuilderOptions
9
9
  extend Forwardable
10
10
 
11
- def initialize(env, definition, version, tarball, disk_size = nil)
12
- @environment = env
13
- @definition = definition
14
-
15
- @stemcell_version = version
16
- @image_create_disk_size = disk_size || infrastructure.default_disk_size
17
- @bosh_micro_release_tgz_path = tarball
11
+ def initialize(dependencies = {})
12
+ @environment = dependencies.fetch(:env)
13
+ @definition = dependencies.fetch(:definition)
14
+
15
+ @stemcell_version = dependencies.fetch(:version)
16
+ @image_create_disk_size = dependencies.fetch(:disk_size, infrastructure.default_disk_size)
17
+ @bosh_micro_release_tgz_path = dependencies.fetch(:release_tarball)
18
+ @os_image_tgz_path = dependencies.fetch(:os_image_tarball)
18
19
  end
19
20
 
20
21
  def default
@@ -34,7 +35,8 @@ module Bosh::Stemcell
34
35
  'bosh_release_src_dir' => File.join(source_root, 'release/src/bosh'),
35
36
  'bosh_agent_src_dir' => File.join(source_root, 'bosh_agent'),
36
37
  'go_agent_src_dir' => File.join(source_root, 'go_agent'),
37
- 'image_create_disk_size' => image_create_disk_size
38
+ 'image_create_disk_size' => image_create_disk_size,
39
+ 'os_image_tgz' => os_image_tgz_path,
38
40
  }.merge(bosh_micro_options).merge(environment_variables).merge(ovf_options)
39
41
  end
40
42
 
@@ -52,7 +54,8 @@ module Bosh::Stemcell
52
54
  :stemcell_version,
53
55
  :definition,
54
56
  :image_create_disk_size,
55
- :bosh_micro_release_tgz_path
57
+ :bosh_micro_release_tgz_path,
58
+ :os_image_tgz_path,
56
59
  )
57
60
 
58
61
  def ovf_options
@@ -10,6 +10,8 @@ module Bosh::Stemcell
10
10
  Vsphere.new
11
11
  when 'vcloud'
12
12
  Vcloud.new
13
+ when 'null'
14
+ NullInfrastructure.new
13
15
  else
14
16
  raise ArgumentError.new("invalid infrastructure: #{name}")
15
17
  end
@@ -37,6 +39,12 @@ module Bosh::Stemcell
37
39
  end
38
40
  end
39
41
 
42
+ class NullInfrastructure < Base
43
+ def initialize
44
+ super(name: 'null', hypervisor: 'null', default_disk_size: -1)
45
+ end
46
+ end
47
+
40
48
  class OpenStack < Base
41
49
  def initialize
42
50
  super(name: 'openstack', hypervisor: 'kvm', default_disk_size: 10240)
@@ -0,0 +1,20 @@
1
+ module Bosh::Stemcell
2
+ class OsImageBuilder
3
+ def initialize(dependencies = {})
4
+ @environment = dependencies.fetch(:environment)
5
+ @collection = dependencies.fetch(:collection)
6
+ @runner = dependencies.fetch(:runner)
7
+ @archive_handler = dependencies.fetch(:archive_handler)
8
+ end
9
+
10
+ def build(os_image_path)
11
+ environment.prepare_build
12
+ runner.configure_and_apply(collection.operating_system_stages)
13
+ archive_handler.compress(environment.chroot_dir, os_image_path)
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :environment, :collection, :runner, :archive_handler
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ module Bosh::Stemcell
2
+ class OsImageUploader
3
+ def initialize(dependencies = {})
4
+ @digester = dependencies.fetch(:digester)
5
+ @adapter = dependencies.fetch(:adapter)
6
+ end
7
+
8
+ def upload(bucket_name, os_image_path)
9
+ digest = digester.file(os_image_path).hexdigest
10
+ adapter.upload(
11
+ bucket_name: bucket_name,
12
+ key: digest,
13
+ body: os_image_path,
14
+ public: true,
15
+ )
16
+ digest
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :digester, :adapter
22
+ end
23
+ end
@@ -9,53 +9,65 @@ module Bosh::Stemcell
9
9
  @definition = definition
10
10
  end
11
11
 
12
- def all_stages
13
- operating_system_stages + agent_stages + infrastructure_stages
12
+ def operating_system_stages
13
+ case operating_system
14
+ when OperatingSystem::Centos then
15
+ centos_os_stages + common_os_stages
16
+ when OperatingSystem::Ubuntu then
17
+ ubuntu_os_stages + common_os_stages
18
+ end
14
19
  end
15
20
 
16
- private
17
-
18
- def_delegators :@definition, :infrastructure, :operating_system, :agent
21
+ def extract_operating_system_stages
22
+ [
23
+ :untar_base_os_image,
24
+ ]
25
+ end
19
26
 
20
27
  def agent_stages
21
28
  case agent
22
- when Agent::Go
23
- [
24
- :bosh_ruby,
25
- :bosh_go_agent,
26
- :bosh_micro_go,
27
- :aws_cli,
28
- ]
29
- when Agent::Ruby
30
- [
31
- :bosh_ruby,
32
- :bosh_agent,
33
- :bosh_micro,
34
- ]
35
- end
36
- end
37
-
38
- def operating_system_stages
39
- case operating_system
40
- when OperatingSystem::Centos then
41
- centos_os_stages + common_os_stages
42
- when OperatingSystem::Ubuntu then
43
- ubuntu_os_stages + common_os_stages
29
+ when Agent::Go
30
+ [
31
+ :bosh_ruby,
32
+ :bosh_go_agent,
33
+ :bosh_micro_go,
34
+ :aws_cli,
35
+ ]
36
+ when Agent::Ruby
37
+ [
38
+ :bosh_ruby,
39
+ :bosh_agent,
40
+ :bosh_micro,
41
+ ]
44
42
  end
45
43
  end
46
44
 
45
+ # rubocop:disable MethodLength
47
46
  def infrastructure_stages
48
47
  case infrastructure
49
- when Infrastructure::Aws then
50
- aws_stages
51
- when Infrastructure::OpenStack then
48
+ when Infrastructure::Aws then
49
+ aws_stages
50
+ when Infrastructure::OpenStack then
51
+ if operating_system.instance_of?(OperatingSystem::Centos)
52
+ centos_openstack_stages
53
+ else
52
54
  openstack_stages
53
- when Infrastructure::Vsphere then
55
+ end
56
+ when Infrastructure::Vsphere then
57
+ if operating_system.instance_of?(OperatingSystem::Centos)
58
+ centos_vsphere_stages
59
+ else
54
60
  vsphere_stages
55
- when Infrastructure::Vcloud then
56
- vcloud_stages
61
+ end
62
+ when Infrastructure::Vcloud then
63
+ if operating_system.instance_of?(OperatingSystem::Centos)
64
+ centos_vcloud_stages
65
+ else
66
+ default_vcloud_stages
67
+ end
57
68
  end
58
69
  end
70
+ # rubocop:enable MethodLength
59
71
 
60
72
  def openstack_stages
61
73
  if operating_system.instance_of?(OperatingSystem::Centos)
@@ -81,6 +93,10 @@ module Bosh::Stemcell
81
93
  end
82
94
  end
83
95
 
96
+ private
97
+
98
+ def_delegators :@definition, :infrastructure, :operating_system, :agent
99
+
84
100
  def centos_os_stages
85
101
  [:base_centos, :base_yum]
86
102
  end
@@ -26,17 +26,15 @@ module Bosh::Stemcell
26
26
  end
27
27
 
28
28
  def apply(stages)
29
- work_directory = File.join(work_path, 'work')
30
-
31
29
  stages.each do |stage|
32
- FileUtils.mkdir_p(work_directory)
30
+ FileUtils.mkdir_p(work_path)
33
31
 
34
32
  puts "=== Applying '#{stage}' stage ==="
35
33
  puts "== Started #{Time.now.strftime('%a %b %e %H:%M:%S %Z %Y')} =="
36
34
 
37
35
  stage_apply_script = File.join(build_path, 'stages', stage.to_s, 'apply.sh')
38
36
 
39
- run_sudo_with_command_env("#{stage_apply_script} #{work_directory}")
37
+ run_sudo_with_command_env("#{stage_apply_script} #{work_path}")
40
38
  end
41
39
  end
42
40
 
@@ -0,0 +1,23 @@
1
+ module Bosh::Stemcell
2
+ class StemcellBuilder
3
+ def initialize(dependencies = {})
4
+ @gem_components = dependencies.fetch(:gem_components)
5
+ @environment = dependencies.fetch(:environment)
6
+ @collection = dependencies.fetch(:collection)
7
+ @runner = dependencies.fetch(:runner)
8
+ end
9
+
10
+ def build
11
+ gem_components.build_release_gems
12
+ environment.prepare_build
13
+ stemcell_stages = collection.extract_operating_system_stages +
14
+ collection.agent_stages +
15
+ collection.infrastructure_stages
16
+ runner.configure_and_apply(stemcell_stages)
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :gem_components, :environment, :collection, :runner
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Stemcell
3
- VERSION = '1.2175.0'
3
+ VERSION = '1.2200.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh-stemcell
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2175.0
4
+ version: 1.2200.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-12 00:00:00.000000000 Z
12
+ date: 2014-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bosh_aws_cpi
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.2175.0
21
+ version: 1.2200.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.2175.0
29
+ version: 1.2200.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: fakefs
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -149,17 +149,21 @@ files:
149
149
  - lib/bosh/stemcell/agent.rb
150
150
  - lib/bosh/stemcell/archive.rb
151
151
  - lib/bosh/stemcell/archive_filename.rb
152
+ - lib/bosh/stemcell/archive_handler.rb
152
153
  - lib/bosh/stemcell/aws/ami.rb
153
154
  - lib/bosh/stemcell/aws/light_stemcell.rb
154
155
  - lib/bosh/stemcell/aws/region.rb
155
- - lib/bosh/stemcell/builder_command.rb
156
+ - lib/bosh/stemcell/build_environment.rb
156
157
  - lib/bosh/stemcell/builder_options.rb
157
158
  - lib/bosh/stemcell/definition.rb
158
159
  - lib/bosh/stemcell/disk_image.rb
159
160
  - lib/bosh/stemcell/infrastructure.rb
160
161
  - lib/bosh/stemcell/operating_system.rb
162
+ - lib/bosh/stemcell/os_image_builder.rb
163
+ - lib/bosh/stemcell/os_image_uploader.rb
161
164
  - lib/bosh/stemcell/stage_collection.rb
162
165
  - lib/bosh/stemcell/stage_runner.rb
166
+ - lib/bosh/stemcell/stemcell_builder.rb
163
167
  - lib/bosh/stemcell/version.rb
164
168
  - lib/monkeypatch/serverspec/backend/exec.rb
165
169
  - README.md
@@ -184,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
188
  version: '0'
185
189
  segments:
186
190
  - 0
187
- hash: -1695777046374317705
191
+ hash: 2870165919734630849
188
192
  requirements: []
189
193
  rubyforge_project:
190
194
  rubygems_version: 1.8.23