@@ -10,8 +10,7 @@ import sys
10
10
import tempfile
11
11
import subprocess
12
12
import boto3
13
- from botocore .exceptions import ClientError , NoCredentialsError
14
- from tenacity import retry
13
+ from cosalib .s3 import s3_copy , s3_check_exists
15
14
16
15
sys .path .insert (0 , os .path .dirname (os .path .abspath (__file__ )))
17
16
@@ -22,13 +21,7 @@ CACHE_MAX_AGE_ARTIFACT = 60 * 60 * 24 * 365
22
21
# set metadata caching to 5m
23
22
CACHE_MAX_AGE_METADATA = 60 * 5
24
23
from cosalib .builds import Builds , BUILDFILES
25
- from cosalib .cmdlib import (
26
- load_json ,
27
- retry_stop_long ,
28
- retry_wait_long ,
29
- retry_boto_exception ,
30
- retry_callback
31
- )
24
+ from cosalib .cmdlib import load_json
32
25
33
26
34
27
def main ():
@@ -194,57 +187,5 @@ def s3_upload_build(s3_client, args, builddir, bucket, prefix):
194
187
dry_run = args .dry_run )
195
188
196
189
197
- @retry (stop = retry_stop_long , wait = retry_wait_long ,
198
- retry = retry_boto_exception , before_sleep = retry_callback )
199
- def s3_check_exists (s3_client , bucket , key , dry_run = False ):
200
- print (f"Checking if bucket '{ bucket } ' has key '{ key } '" )
201
- try :
202
- s3_client .head_object (Bucket = bucket , Key = key )
203
- except ClientError as e :
204
- if e .response ['Error' ]['Code' ] == '404' :
205
- return False
206
- raise e
207
- except NoCredentialsError as e :
208
- # It's reasonable to run without creds if doing a dry-run
209
- if dry_run :
210
- return False
211
- raise e
212
- return True
213
-
214
-
215
- @retry (stop = retry_stop_long , wait = retry_wait_long ,
216
- retry = retry_boto_exception , retry_error_callback = retry_callback )
217
- def s3_copy (s3_client , src , bucket , key , max_age , acl , extra_args = {}, dry_run = False ):
218
- extra_args = dict (extra_args )
219
- if 'ContentType' not in extra_args :
220
- if key .endswith ('.json' ):
221
- extra_args ['ContentType' ] = 'application/json'
222
- elif key .endswith ('.tar' ):
223
- extra_args ['ContentType' ] = 'application/x-tar'
224
- elif key .endswith ('.xz' ):
225
- extra_args ['ContentType' ] = 'application/x-xz'
226
- elif key .endswith ('.gz' ):
227
- extra_args ['ContentType' ] = 'application/gzip'
228
- elif key .endswith ('.iso' ):
229
- extra_args ['ContentType' ] = 'application/x-iso9660-image'
230
- else :
231
- # use a standard MIME type for "binary blob" instead of the default
232
- # 'binary/octet-stream' AWS slaps on
233
- extra_args ['ContentType' ] = 'application/octet-stream'
234
- upload_args = {
235
- 'CacheControl' : f'max-age={ max_age } ' ,
236
- 'ACL' : acl
237
- }
238
- upload_args .update (extra_args )
239
-
240
- print ((f"{ 'Would upload' if dry_run else 'Uploading' } { src } to "
241
- f"s3://{ bucket } /{ key } with args { upload_args } " ))
242
-
243
- if dry_run :
244
- return
245
-
246
- s3_client .upload_file (Filename = src , Bucket = bucket , Key = key , ExtraArgs = upload_args )
247
-
248
-
249
190
if __name__ == '__main__' :
250
191
sys .exit (main ())
0 commit comments