Module: Satorix::CI::Shared::BuildpackManager
Overview
Defined Under Namespace
Classes: Buildpack
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
Instance Method Details
#abort_if_skip_buildpack ⇒ Object
181
182
183
184
185
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 181
def abort_if_skip_buildpack
if ENV['SKIP_BUILDPACK']
log_error_and_abort("\n\nDEPRECATED: Skipping buildpack is no longer supported, please update your .gitlab-ci.yml.\n\n")
end
end
|
#active_buildpack_list ⇒ Object
26
27
28
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 26
def active_buildpack_list
custom_buildpack_list || stack_buildpack_list
end
|
#active_buildpacks ⇒ Object
31
32
33
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 31
def active_buildpacks
active_buildpack_list.split.map { |buildpack| Buildpack.new buildpack }
end
|
#cedar_14? ⇒ Boolean
36
37
38
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 36
def cedar_14?
stack_version == 'cedar-14'
end
|
#copy_app_dir ⇒ Object
41
42
43
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 41
def copy_app_dir
FileUtils.cp_r File.join(Satorix.build_dir, '/.'), Satorix.app_dir, remove_destination: true
end
|
#custom_buildpack_list ⇒ Object
46
47
48
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 46
def custom_buildpack_list
IO.binread(files[:dot_buildpacks]).strip if custom_buildpacks?
end
|
#custom_buildpacks? ⇒ Boolean
51
52
53
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 51
def custom_buildpacks?
File.exist? files[:dot_buildpacks]
end
|
#default_buildpack_list ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 56
def default_buildpack_list
<<-THESE_ARE_THE_BUILDPACKS_OFFICIALLY_SUPPORTED_BY_FLYNN.strip
https://github.com/heroku/heroku-buildpack-multi.git#ed950773
https://github.com/cloudfoundry/staticfile-buildpack.git#e482e8f2
https://github.com/heroku/heroku-buildpack-ruby.git#4ca71a9d
https://github.com/heroku/heroku-buildpack-nodejs.git#a4fb9419
https://github.com/heroku/heroku-buildpack-clojure.git#5858bad3
https://github.com/heroku/heroku-buildpack-python.git#9dcabe24
https://github.com/heroku/heroku-buildpack-java.git#354d2a79
https://github.com/heroku/heroku-buildpack-gradle.git#b89c8c38
https://github.com/heroku/heroku-buildpack-scala.git#41c296d4
https://github.com/heroku/heroku-buildpack-php.git#62a691bf
https://github.com/heroku/heroku-buildpack-go.git#6f80fd9c
THESE_ARE_THE_BUILDPACKS_OFFICIALLY_SUPPORTED_BY_FLYNN
end
|
#default_cedar_14_buildpack_list ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 75
def default_cedar_14_buildpack_list
<<-THESE_ARE_THE_BUILDPACKS_OFFICIALLY_SUPPORTED_BY_FLYNN.strip
https://github.com/heroku/heroku-buildpack-multi.git#ed950773
https://github.com/cloudfoundry/staticfile-buildpack.git#206728f9
https://github.com/heroku/heroku-buildpack-ruby.git#6988832f
https://github.com/heroku/heroku-buildpack-nodejs.git#9b8a98d8
https://github.com/heroku/heroku-buildpack-clojure.git#8768a8ff
https://github.com/heroku/heroku-buildpack-python.git#cafd4182
https://github.com/heroku/heroku-buildpack-java.git#8c34efe9
https://github.com/heroku/heroku-buildpack-gradle.git#13fa1fe7
https://github.com/heroku/heroku-buildpack-scala.git#dd0dd806
https://github.com/heroku/heroku-buildpack-play.git#cc5e6166
https://github.com/heroku/heroku-buildpack-php.git#e0499a7f
https://github.com/heroku/heroku-buildpack-go.git#bd1acfe5
THESE_ARE_THE_BUILDPACKS_OFFICIALLY_SUPPORTED_BY_FLYNN
end
|
#files ⇒ Object
95
96
97
98
99
100
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 95
def files
build_dir = Satorix.build_dir
{ dot_buildpacks: File.join(build_dir, '.buildpacks'),
dot_env: File.join(build_dir, '.env'),
dot_release: File.join(build_dir, '.release') }
end
|
#go ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 17
def go
abort_if_skip_buildpack
prepare_buildpack_environment
run_buildpacks
load_dot_release_file
switch_context_to_new_test_slug
end
|
#load_dot_release_file ⇒ Object
103
104
105
106
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 103
def load_dot_release_file
log_error_and_abort "Unhandled file '#{ files[:dot_release] }'." if File.exists? files[:dot_release]
end
|
#load_env ⇒ Object
128
129
130
131
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 128
def load_env
log_error_and_abort 'Unhandled load_env' unless (Dir.entries(Satorix.paths[:env]) - %w(. ..)).empty?
end
|
#load_profile ⇒ Object
134
135
136
137
138
139
140
141
142
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 134
def load_profile
profile_locations.each do |profile_location|
Dir.glob(profile_location) do |shell_file|
source_env_from shell_file
end
end
end
|
#lsb_release ⇒ Object
109
110
111
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 109
def lsb_release
run_command(%w[lsb_release --release --short], quiet: true).chomp
end
|
#prepare_buildpack_environment ⇒ Object
114
115
116
117
118
119
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 114
def prepare_buildpack_environment
log_bench 'Preparing buildpack environment...' do
set_buildpack_expectations
process_dot_env_file
end
end
|
#process_dot_env_file ⇒ Object
122
123
124
125
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 122
def process_dot_env_file
log_error_and_abort "Unhandled file '#{ files[:dot_env] }'" if File.exists? files[:dot_env]
end
|
#profile_locations ⇒ Object
145
146
147
148
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 145
def profile_locations
[File.join('/etc/profile.d', '*.sh'),
File.join(Satorix.app_dir, '.profile.d', '*.sh')]
end
|
#run_buildpacks ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 151
def run_buildpacks
buildpacks = []
log_bench('Detecting application type...') do
active_buildpacks.each(&:ensure_correctness)
buildpacks = active_buildpacks.keep_if(&:detected?)
if buildpacks.empty?
log_error_and_abort 'Unable to select a buildpack!'
elsif buildpacks.length > 1 && !custom_buildpacks?
log_error("\n\nWarning: Multiple default buildpacks reported the ability to handle this app."\
" The first buildpack in the list above will be used.\n\n")
buildpacks = buildpacks.first(1)
end
end
buildpacks.each(&:compile)
end
|
#set_buildpack_expectations ⇒ Object
171
172
173
174
175
176
177
178
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 171
def set_buildpack_expectations
ENV['APP_DIR'] = Satorix.app_dir
ENV['REQUEST_ID'] = "commit-#{ Satorix.ci_commit_sha }"
ENV['STACK'] = stack_version
ENV['DATABASE_URL'] = Satorix::CI::Test::Shared::Database.url
ENV['CURL_CONNECT_TIMEOUT'] = '30'
ENV['CURL_TIMEOUT'] = '600'
end
|
#stack_buildpack_list ⇒ Object
197
198
199
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 197
def stack_buildpack_list
cedar_14? ? default_cedar_14_buildpack_list : default_buildpack_list
end
|
#stack_version ⇒ Object
188
189
190
191
192
193
194
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 188
def stack_version
if lsb_release == '14.04'
return 'cedar-14'
else
return 'heroku-18'
end
end
|
#switch_context_to_new_test_slug ⇒ Object
202
203
204
205
206
207
208
|
# File 'lib/satorix/CI/shared/buildpack_manager.rb', line 202
def switch_context_to_new_test_slug
log_bench 'Switching context to the newly built application...' do
copy_app_dir
load_env
load_profile
end
end
|