Class: Satorix::CI::Shared::BuildpackManager::Buildpack
- Inherits:
-
Object
- Object
- Satorix::CI::Shared::BuildpackManager::Buildpack
show all
- Includes:
- Shared::Console
- Defined in:
- lib/satorix/CI/shared/buildpack_manager/buildpack.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#colorize, #colors, #humanize_time, #log, #log_bench, #log_command, #log_duration, #log_error, #log_error_and_abort, #log_header, #run_command, #source_env_from
Constructor Details
#initialize(initialization_url) ⇒ Buildpack
Returns a new instance of Buildpack.
26
27
28
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 26
def initialize(initialization_url)
self.url, self.commit_sha_short = initialization_url.to_s.strip.split('#')
end
|
Instance Attribute Details
#commit_sha_short ⇒ Object
Returns the value of attribute commit_sha_short.
17
18
19
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 17
def commit_sha_short
@commit_sha_short
end
|
#url ⇒ Object
Returns the value of attribute url.
17
18
19
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 17
def url
@url
end
|
Instance Method Details
#checkout ⇒ Object
94
95
96
97
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 94
def checkout
log "Downloading Buildpack: #{ url }."
commit_sha_short ? checkout_specific_version : checkout_newest_version
end
|
#checkout_newest_version ⇒ Object
107
108
109
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 107
def checkout_newest_version
run_command ['git', 'clone', '--quiet', '--recursive', '--depth', '1', url, path], quiet: true
end
|
#checkout_specific_version ⇒ Object
100
101
102
103
104
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 100
def checkout_specific_version
run_command ['git', 'clone', '--quiet', '--no-checkout', url, path], quiet: true
Dir.chdir(path) { run_command ['git', 'checkout', '--quiet', commit_sha_short], quiet: true }
Dir.chdir(path) { run_command ['git', 'submodule', 'update', '--init', '--recursive'], quiet: true }
end
|
#commit_sha_length ⇒ Object
119
120
121
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 119
def commit_sha_length
commit_sha_short ? commit_sha_short.to_s.length : 7
end
|
#compile ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 31
def compile
log_bench "Building application using the #{ name } buildpack..." do
run_command [compile_binary_path,
Satorix.build_dir,
Satorix.paths[:cache],
Satorix.paths[:env]]
end
end
|
#compile_binary_path ⇒ Object
41
42
43
44
45
46
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 41
def compile_binary_path
bin_path = File.join(path, 'bin')
test_compile_path = File.join(bin_path, 'test-compile')
compile_path = File.join(bin_path, 'compile')
File.exist?(test_compile_path) ? test_compile_path : compile_path
end
|
#correct_version? ⇒ Boolean
112
113
114
115
116
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 112
def correct_version?
exist? &&
commit_sha_short &&
commit_sha_short == current_commit_sha_short_on_disk
end
|
#current_commit_sha_short_on_disk ⇒ Object
147
148
149
150
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 147
def current_commit_sha_short_on_disk
return '' unless exist?
satorix_distrib_sha_version || git_sha_short
end
|
#delete! ⇒ Object
84
85
86
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 84
def delete!
FileUtils.rm_rf path
end
|
#detected? ⇒ Boolean
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 49
def detected?
if BuildpackManager.custom_buildpacks?
log "Custom Buildpack: #{ name }."
else
command = [File.join(path, 'bin', 'detect'), Satorix.build_dir]
buildpack_name = run_command(command, quiet: true).chomp
log "Detected Framework: #{ buildpack_name }."
end
true
rescue SystemExit
false
end
|
#ensure_correctness ⇒ Object
76
77
78
79
80
81
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 76
def ensure_correctness
unless correct_version?
delete!
checkout
end
end
|
#exist? ⇒ Boolean
89
90
91
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 89
def exist?
Dir.exist? path
end
|
#git_sha_short ⇒ Object
139
140
141
142
143
144
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 139
def git_sha_short
Dir.chdir(path) do
run_command(['git', 'rev-parse', "--short=#{ commit_sha_length }", 'HEAD'], quiet: true).strip
end
end
|
#go ⇒ Object
21
22
23
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 21
def go
log_error_and_abort 'Buildpack.go should not be called directly - use BuildpackManager.go.'
end
|
#name ⇒ Object
66
67
68
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 66
def name
File.basename(URI.parse(url).path, ".git")
end
|
#path ⇒ Object
71
72
73
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 71
def path
File.join Satorix.paths[:buildpacks], name
end
|
#satorix_distrib_sha? ⇒ Boolean
129
130
131
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 129
def satorix_distrib_sha?
File.exist? satorix_distrib_sha_path
end
|
#satorix_distrib_sha_path ⇒ Object
134
135
136
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 134
def satorix_distrib_sha_path
File.join(path, '.distrib-sha')
end
|
#satorix_distrib_sha_version ⇒ Object
124
125
126
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 124
def satorix_distrib_sha_version
IO.binread(satorix_distrib_sha_path).strip if satorix_distrib_sha?
end
|