Class: Capistrano::NetStorage::S3::Broker::AwsCLI
- Defined in:
- lib/capistrano/net_storage/s3/broker/aws_cli.rb
Instance Method Summary collapse
Instance Method Details
#check ⇒ Object
9 10 11 |
# File 'lib/capistrano/net_storage/s3/broker/aws_cli.rb', line 9 def check execute_aws_s3('ls', config.bucket_url) end |
#cleanup ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# 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 ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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', '--no-progress', c.archive_url, ns.archive_path end end end end end |
#find_uploaded ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# 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 ⇒ Object
24 25 26 27 28 29 30 |
# 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', '--no-progress', ns.local_archive_path, c.archive_url) end end |