Class: Cloudspin::Stack::Artefact::Builder
- Inherits:
-
Object
- Object
- Cloudspin::Stack::Artefact::Builder
show all
- Includes:
- FileUtils, Util::Tar
- Defined in:
- lib/cloudspin/stack/artefact/builder.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Util::Tar
#gzip, #tar, #ungzip, #untar
Constructor Details
#initialize(stack_definition:, dist_folder:) ⇒ Builder
Returns a new instance of Builder.
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 22
def initialize(stack_definition:,
dist_folder:)
@stack_definition = stack_definition
@dist_folder = dist_folder
@stack_definition_name = stack_definition.name
@stack_definition_version = stack_definition.version
@folders_to_package = {
stack_definition.terraform_source_path => 'src'
}
@files_to_package = []
end
|
Instance Attribute Details
#dist_folder ⇒ Object
Returns the value of attribute dist_folder.
18
19
20
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 18
def dist_folder
@dist_folder
end
|
#files_to_package ⇒ Object
Returns the value of attribute files_to_package.
20
21
22
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 20
def files_to_package
@files_to_package
end
|
#folders_to_package ⇒ Object
Returns the value of attribute folders_to_package.
19
20
21
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 19
def folders_to_package
@folders_to_package
end
|
#stack_definition ⇒ Object
Returns the value of attribute stack_definition.
15
16
17
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 15
def stack_definition
@stack_definition
end
|
#stack_definition_name ⇒ Object
Returns the value of attribute stack_definition_name.
16
17
18
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 16
def stack_definition_name
@stack_definition_name
end
|
#stack_definition_version ⇒ Object
Returns the value of attribute stack_definition_version.
17
18
19
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 17
def stack_definition_version
@stack_definition_version
end
|
Instance Method Details
#add_file_to_package(source_file) ⇒ Object
53
54
55
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 53
def add_file_to_package(source_file)
@files_to_package << source_file
end
|
#add_folder_to_package(source_folder, artefact_subfolder: nil) ⇒ Object
48
49
50
51
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 48
def add_folder_to_package(source_folder, artefact_subfolder: nil)
artefact_subfolder ||= File.basename(source_folder)
@folders_to_package[source_folder] = artefact_subfolder
end
|
#artefact_contents_folder ⇒ Object
68
69
70
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 68
def artefact_contents_folder
dist_folder + '/' + artefact_name
end
|
#artefact_files ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 76
def artefact_files
file_list = []
Find.find(artefact_contents_folder) do |file|
file_list << "#{artefact_contents_folder}/#{file}"
end
file_list
end
|
#artefact_name ⇒ Object
64
65
66
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 64
def artefact_name
stack_definition_name + '-' + stack_definition_version
end
|
#artefact_path ⇒ Object
72
73
74
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 72
def artefact_path
dist_folder + '/' + artefact_name + '.tgz'
end
|
#build ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 34
def build
puts "Copying files to include in the artefact to #{artefact_contents_folder}/src."
rm_rf(artefact_contents_folder)
folders_to_package.each { |source, destination|
puts "Copying #{source} to #{artefact_contents_folder + '/' + destination}"
mkpath File.dirname(artefact_contents_folder + '/' + destination)
cp_r(source, artefact_contents_folder + '/' + destination)
}
files_to_package.each { |file|
puts "Copying #{file} to #{artefact_contents_folder + '/' + file}"
cp(file, artefact_contents_folder + '/' + file)
}
end
|
#package ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/cloudspin/stack/artefact/builder.rb', line 57
def package
puts "Create #{artefact_path} from #{artefact_contents_folder}"
rm_f(artefact_path)
tar = tar(artefact_contents_folder)
tgz = gzip(tar)
File.write(artefact_path, tgz.read)
end
|