-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathRakefile
More file actions
114 lines (98 loc) · 3.84 KB
/
Rakefile
File metadata and controls
114 lines (98 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
require 'json'
namespace :stemcell do
desc 'Build a base OS image for use in stemcells'
task :build_os_image, [:operating_system_name, :operating_system_version, :os_image_path] do |_, args|
begin
require 'bosh/stemcell/archive_handler'
require 'bosh/stemcell/build_environment'
require 'bosh/stemcell/definition'
require 'bosh/stemcell/os_image_builder'
require 'bosh/stemcell/stage_collection'
require 'bosh/stemcell/stage_runner'
definition = Bosh::Stemcell::Definition.for('null', 'null', args.operating_system_name, args.operating_system_version)
environment = Bosh::Stemcell::BuildEnvironment.new(
ENV.to_hash,
definition,
'',
args.os_image_path,
)
collection = Bosh::Stemcell::StageCollection.new(definition)
runner = Bosh::Stemcell::StageRunner.new(
build_path: environment.build_path,
command_env: environment.command_env,
settings_file: environment.settings_path,
work_path: environment.work_path,
)
archive_handler = Bosh::Stemcell::ArchiveHandler.new
builder = Bosh::Stemcell::OsImageBuilder.new(
environment: environment,
collection: collection,
runner: runner,
archive_handler: archive_handler,
)
builder.build(args.os_image_path)
sh(environment.os_image_rspec_command)
rescue RuntimeError => e
print_help
raise e
end
end
desc 'Build a stemcell, requires `os_image_path` pointing at an image created via `stemcell:build_os_image`'
task :build, [:infrastructure_name, :hypervisor_name, :operating_system_name, :operating_system_version, :os_image_path, :build_number] do |_, args|
begin
require 'bosh/stemcell/build_environment'
require 'bosh/stemcell/definition'
require 'bosh/stemcell/stage_collection'
require 'bosh/stemcell/stage_runner'
require 'bosh/stemcell/stemcell_packager'
require 'bosh/stemcell/stemcell_builder'
args.with_defaults(build_number: '0000')
definition = Bosh::Stemcell::Definition.for(args.infrastructure_name, args.hypervisor_name, args.operating_system_name, args.operating_system_version)
environment = Bosh::Stemcell::BuildEnvironment.new(
ENV.to_hash,
definition,
args.build_number,
args.os_image_path,
)
sh(environment.os_image_rspec_command)
puts "Working from #{environment.work_path}..."
puts "########################################"
runner = Bosh::Stemcell::StageRunner.new(
build_path: environment.build_path,
command_env: environment.command_env,
settings_file: environment.settings_path,
work_path: environment.work_path,
)
stemcell_building_stages = Bosh::Stemcell::StageCollection.new(definition)
builder = Bosh::Stemcell::StemcellBuilder.new(
environment: environment,
runner: runner,
definition: definition,
collection: stemcell_building_stages
)
packager = Bosh::Stemcell::StemcellPackager.new(
definition: definition,
version: environment.version,
work_path: environment.work_path,
tarball_path: environment.stemcell_tarball_path,
disk_size: environment.stemcell_disk_size,
runner: runner,
collection: stemcell_building_stages,
)
builder.build
mkdir_p('tmp')
definition.disk_formats.each do |disk_format|
puts "Packaging #{disk_format}..."
stemcell_tarball = packager.package(disk_format)
cp(stemcell_tarball, 'tmp')
end
sh(environment.stemcell_rspec_command)
rescue RuntimeError => e
print_help
raise e
end
end
def print_help
puts "\nFor help with stemcell building, see: https://github.com/cloudfoundry/bosh-linux-stemcell-builder/blob/master/README.md\n\n"
end
end