class Capistrano::NetStorage::S3::Broker::AwsCLI

Public Instance Methods

check() click to toggle source
# File lib/capistrano/net_storage/s3/broker/aws_cli.rb, line 9
def check
  execute_aws_s3('ls', config.bucket_url)
end
cleanup() click to toggle source
# File lib/capistrano/net_storage/s3/broker/aws_cli.rb, line 46
def cleanup
  c         = config
  list_args = %W(--bucket #{c.bucket} --output json)
  if c.archives_directory
    list_args += %W(--prefix #{c.archives_directory})
  end
  output = capture_aws_s3api('list-objects', list_args)
  return if output.empty?

  objects = JSON.parse(output)['Contents']
  sorted  = objects.sort_by { |obj| Time.parse(obj['LastModified']) }
  c.s3_keep_releases.times do
    break if sorted.empty?
    sorted.pop
  end
  sorted.each do |obj|
    delete_args = %W(--bucket #{c.bucket} --key #{obj['Key']})
    execute_aws_s3api('delete-object', *delete_args)
  end
end
download() click to toggle source
# File lib/capistrano/net_storage/s3/broker/aws_cli.rb, line 32
def download
  c  = config
  ns = net_storage
  on ns.servers, in: :groups, limit: ns.max_parallels do
    Retryable.retryable(tries: c.max_retry, sleep: 0.1) do
      within releases_path do
        with(c.aws_environments) do
          execute :aws, 's3', 'cp', c.archive_url, ns.archive_path
        end
      end
    end
  end
end
find_uploaded() click to toggle source
# File lib/capistrano/net_storage/s3/broker/aws_cli.rb, line 13
def find_uploaded
  if capture_aws_s3('ls', config.archive_url)
    set :net_storage_uploaded_archive, true
  end
rescue SSHKit::StandardError
  c = config
  run_locally do
    info "Archive is not found as #{c.archive_url}"
  end
end
upload() click to toggle source
# File lib/capistrano/net_storage/s3/broker/aws_cli.rb, line 24
def upload
  c  = config
  ns = net_storage
  Retryable.retryable(tries: c.max_retry, sleep: 0.1) do
    execute_aws_s3('cp', ns.local_archive_path, c.archive_url)
  end
end

Private Instance Methods

capture_aws_s3(cmd, *args) click to toggle source
# File lib/capistrano/net_storage/s3/broker/aws_cli.rb, line 78
def capture_aws_s3(cmd, *args)
  c = config
  run_locally do
    with(c.aws_environments) do
      capture :aws, 's3', cmd, *args
    end
  end
end
capture_aws_s3api(cmd, *args) click to toggle source
# File lib/capistrano/net_storage/s3/broker/aws_cli.rb, line 96
def capture_aws_s3api(cmd, *args)
  c = config
  run_locally do
    with(c.aws_environments) do
      capture :aws, 's3api', cmd, *args
    end
  end
end
execute_aws_s3(cmd, *args) click to toggle source
# File lib/capistrano/net_storage/s3/broker/aws_cli.rb, line 69
def execute_aws_s3(cmd, *args)
  c = config
  run_locally do
    with(c.aws_environments) do
      execute :aws, 's3', cmd, *args
    end
  end
end
execute_aws_s3api(cmd, *args) click to toggle source
# File lib/capistrano/net_storage/s3/broker/aws_cli.rb, line 87
def execute_aws_s3api(cmd, *args)
  c = config
  run_locally do
    with(c.aws_environments) do
      execute :aws, 's3api', cmd, *args
    end
  end
end