Class: Dockly::BuildCache::Local
- Inherits:
-
Base
- Object
- Base
- Dockly::BuildCache::Local
show all
- Defined in:
- lib/dockly/build_cache/local.rb
Instance Method Summary
collapse
Methods inherited from Base
#base_directory, #command_directory, #connection, #execute!, #file_output, #insert_cache, #insert_latest, #parameter_command, #pull_from_s3, #push_to_s3, #s3_object, #up_to_date?
Instance Method Details
#hash_output ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/dockly/build_cache/local.rb', line 29
def hash_output
ensure_present! :hash_command
@hash_output ||= begin
status, body = run_command(hash_command)
raise "Hash Command `#{hash_command} failed to run" unless status.success?
body
end
end
|
#output_directory ⇒ Object
11
12
13
|
# File 'lib/dockly/build_cache/local.rb', line 11
def output_directory
File.expand_path(File.join(Dir.pwd, output_dir))
end
|
#parameter_output(command) ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/dockly/build_cache/local.rb', line 38
def parameter_output(command)
raise "Parameter Command tried to run but not found" unless parameter_commands.keys.include?(command)
@parameter_commands[command] ||= begin
status, body = run_command(command)
raise "Parameter Command `#{command} failed to run" unless status.success?
body
end
end
|
#push_cache(version) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/dockly/build_cache/local.rb', line 19
def push_cache(version)
ensure_present! :output_dir
if cache = pull_from_s3(version)
dest = File.dirname(File.expand_path(output_dir))
Dockly::Util::Tar.untar(cache, dest)
else
info "could not find #{s3_object(output_dir)}"
end
end
|
#run_build ⇒ Object
2
3
4
5
6
7
8
9
|
# File 'lib/dockly/build_cache/local.rb', line 2
def run_build
puts "Build command: #{build_command}"
status, body = run_command(build_command)
raise "Build Cache `#{build_command}` failed to run.\nError: #{body}" unless status.success?
FileUtils.mkdir_p(File.dirname(save_file))
tar_file = Dockly::Util::Tar.tar(output_directory, save_file)
push_to_s3(tar_file)
end
|
#run_command(command) ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/dockly/build_cache/local.rb', line 47
def run_command(command)
resp = ""
run_with_bundler do
IO.popen(command) do |io|
resp << io.read
end
end
[$?, resp.strip]
end
|
#run_with_bundler ⇒ Object
58
59
60
61
62
|
# File 'lib/dockly/build_cache/local.rb', line 58
def run_with_bundler
Bundler.with_clean_env do
yield
end
end
|
#save_file ⇒ Object
15
16
17
|
# File 'lib/dockly/build_cache/local.rb', line 15
def save_file
File.expand_path("build/build_cache/#{s3_object_prefix}#{hash_output}")
end
|