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.
22
23
24
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 22
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.
13
14
15
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 13
def commit_sha_short
@commit_sha_short
end
|
#url ⇒ Object
Returns the value of attribute url.
13
14
15
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 13
def url
@url
end
|
Instance Method Details
#checkout ⇒ Object
90
91
92
93
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 90
def checkout
log "Downloading Buildpack: #{ url }."
commit_sha_short ? checkout_specific_version : checkout_newest_version
end
|
#checkout_newest_version ⇒ Object
103
104
105
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 103
def checkout_newest_version
run_command(['git', 'clone', '--quiet', '--recursive', '--depth', '1', url, path], quiet: true)
end
|
#checkout_specific_version ⇒ Object
96
97
98
99
100
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 96
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(%w[git submodule update --init --recursive], quiet: true) }
end
|
#commit_sha_length ⇒ Object
115
116
117
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 115
def commit_sha_length
commit_sha_short ? commit_sha_short.to_s.length : 7
end
|
#compile ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 27
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
37
38
39
40
41
42
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 37
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
108
109
110
111
112
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 108
def correct_version?
exist? &&
commit_sha_short &&
commit_sha_short == current_commit_sha_short_on_disk
end
|
#current_commit_sha_short_on_disk ⇒ Object
143
144
145
146
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 143
def current_commit_sha_short_on_disk
return '' unless exist?
satorix_distrib_sha_version || git_sha_short
end
|
#delete! ⇒ Object
80
81
82
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 80
def delete!
FileUtils.rm_rf path
end
|
#detected? ⇒ Boolean
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 45
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
72
73
74
75
76
77
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 72
def ensure_correctness
unless correct_version?
delete!
checkout
end
end
|
#exist? ⇒ Boolean
85
86
87
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 85
def exist?
Dir.exist? path
end
|
#git_sha_short ⇒ Object
135
136
137
138
139
140
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 135
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
17
18
19
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 17
def go
log_error_and_abort 'Buildpack.go should not be called directly - use BuildpackManager.go.'
end
|
#name ⇒ Object
62
63
64
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 62
def name
File.basename(URI.parse(url).path, ".git")
end
|
#path ⇒ Object
67
68
69
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 67
def path
File.join Satorix.paths[:buildpacks], name
end
|
#satorix_distrib_sha? ⇒ Boolean
125
126
127
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 125
def satorix_distrib_sha?
File.exist? satorix_distrib_sha_path
end
|
#satorix_distrib_sha_path ⇒ Object
130
131
132
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 130
def satorix_distrib_sha_path
File.join(path, '.distrib-sha')
end
|
#satorix_distrib_sha_version ⇒ Object
120
121
122
|
# File 'lib/satorix/CI/shared/buildpack_manager/buildpack.rb', line 120
def satorix_distrib_sha_version
IO.binread(satorix_distrib_sha_path).strip if satorix_distrib_sha?
end
|