Class: RSpecTracer::RemoteCache::Aws
- Inherits:
-
Object
- Object
- RSpecTracer::RemoteCache::Aws
- Defined in:
- lib/rspec_tracer/remote_cache/aws.rb
Defined Under Namespace
Classes: AwsError
Instance Method Summary collapse
- #branch_refs?(branch_name) ⇒ Boolean
- #cache_files_list(ref) ⇒ Object
- #download_branch_refs(branch_name, file_name) ⇒ Object
- #download_dir(ref, run_id) ⇒ Object
- #download_file(ref, file_name) ⇒ Object
-
#initialize ⇒ Aws
constructor
A new instance of Aws.
- #upload_branch_refs(branch_name, file_name) ⇒ Object
- #upload_dir(ref, run_id) ⇒ Object
- #upload_file(ref, file_name) ⇒ Object
Constructor Details
#initialize ⇒ Aws
Returns a new instance of Aws.
8 9 10 11 |
# File 'lib/rspec_tracer/remote_cache/aws.rb', line 8 def initialize @s3_bucket, @s3_path = setup_s3 @aws_cli = setup_aws_cli end |
Instance Method Details
#branch_refs?(branch_name) ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rspec_tracer/remote_cache/aws.rb', line 13 def branch_refs?(branch_name) key = "#{@s3_path}/branch-refs/#{branch_name}/branch_refs.json" system( @aws_cli, 's3api', 'head-object', '--bucket', @s3_bucket, '--key', key, out: File::NULL, err: File::NULL ) end |
#cache_files_list(ref) ⇒ Object
62 63 64 65 66 |
# File 'lib/rspec_tracer/remote_cache/aws.rb', line 62 def cache_files_list(ref) prefix = "s3://#{@s3_bucket}/#{@s3_path}/#{ref}/" `#{@aws_cli} s3 ls #{prefix} --recursive`.chomp.split("\n") end |
#download_branch_refs(branch_name, file_name) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rspec_tracer/remote_cache/aws.rb', line 29 def download_branch_refs(branch_name, file_name) key = "#{@s3_path}/branch-refs/#{branch_name}/branch_refs.json" system( @aws_cli, 's3api', 'get-object', '--bucket', @s3_bucket, '--key', key, file_name, out: File::NULL, err: File::NULL ) end |
#download_dir(ref, run_id) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rspec_tracer/remote_cache/aws.rb', line 85 def download_dir(ref, run_id) remote_dir = s3_dir(ref, run_id) local_dir = File.join(RSpecTracer.cache_path, run_id) raise AwsError, "Failed to download files from #{remote_dir}" unless system( @aws_cli, 's3', 'cp', remote_dir, local_dir, '--recursive', out: File::NULL, err: File::NULL ) puts "Downloaded cache files from #{remote_dir} to #{local_dir}" rescue AwsError => e FileUtils.rm_rf(local_dir) raise e end |
#download_file(ref, file_name) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rspec_tracer/remote_cache/aws.rb', line 68 def download_file(ref, file_name) remote_path = File.join(s3_dir(ref), file_name) local_path = File.join(RSpecTracer.cache_path, file_name) raise AwsError, "Failed to download file #{remote_path}" unless system( @aws_cli, 's3', 'cp', remote_path, local_path, out: File::NULL, err: File::NULL ) puts "Downloaded file #{remote_path} to #{local_path}" end |
#upload_branch_refs(branch_name, file_name) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rspec_tracer/remote_cache/aws.rb', line 46 def upload_branch_refs(branch_name, file_name) remote_path = "s3://#{@s3_bucket}/#{@s3_path}/branch-refs/#{branch_name}/branch_refs.json" raise AwsError, "Failed to upload branch refs for #{branch_name} branch" unless system( @aws_cli, 's3', 'cp', file_name, remote_path, out: File::NULL, err: File::NULL ) puts "Uploaded branch refs for #{branch_name} branch to #{remote_path}" end |
#upload_dir(ref, run_id) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/rspec_tracer/remote_cache/aws.rb', line 124 def upload_dir(ref, run_id) remote_dir = s3_dir(ref, run_id) local_dir = File.join(RSpecTracer.cache_path, run_id) raise AwsError, "Failed to download files from #{local_dir}" unless system( @aws_cli, 's3', 'cp', local_dir, remote_dir, '--recursive', out: File::NULL, err: File::NULL ) puts "Uploaded files from #{local_dir} to #{remote_dir}" end |
#upload_file(ref, file_name) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rspec_tracer/remote_cache/aws.rb', line 107 def upload_file(ref, file_name) remote_path = File.join(s3_dir(ref), file_name) local_path = File.join(RSpecTracer.cache_path, file_name) raise AwsError, "Failed to upload file #{local_path}" unless system( @aws_cli, 's3', 'cp', local_path, remote_path, out: File::NULL, err: File::NULL ) puts "Uploaded file #{local_path} to #{remote_path}" end |