Sha256: 7867d1be189b6bbe9194d519729536c6cb54c22e921bfbcbfdcddf4cc73c3365

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

class Dockly::BuildCache::Local < Dockly::BuildCache::Base
  def run_build
    puts "Build command: #{build_command}"
    status, body = run_command(build_command)
    raise "Build Cache `#{build_command}` failed to run." 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

  def output_directory
    File.expand_path(File.join(Dir.pwd, output_dir))
  end

  def save_file
    File.expand_path("build/build_cache/#{s3_object_prefix}#{hash_output}")
  end

  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

  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

  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

  def run_command(command)
    resp = ""
    Bundler.with_clean_env do
      IO.popen(command) do |io|
        resp << io.read
      end
    end
    [$?, resp.strip]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dockly-1.3.2 lib/dockly/build_cache/local.rb
dockly-1.3.1 lib/dockly/build_cache/local.rb