class Dockly::BuildCache::Local

Public Instance Methods

hash_output() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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() { || ... } click to toggle source
# File lib/dockly/build_cache/local.rb, line 58
def run_with_bundler
  Bundler.with_clean_env do
    yield
  end
end
save_file() click to toggle source
# File lib/dockly/build_cache/local.rb, line 15
def save_file
  File.expand_path("build/build_cache/#{s3_object_prefix}#{hash_output}")
end