3
3
4
4
5
5
def _s3_archive_impl (ctx ):
6
- url = ctx .attr .url
6
+ url = "s3://{}/{}" . format ( ctx .attr .bucket , ctx . attr . file_path )
7
7
filename = ctx .path (url ).basename
8
8
9
9
# Download
10
10
aws_cli_path = ctx .which ("aws" )
11
- aws_cli_cmd = [aws_cli_path , "s3" , "cp" , url , "." ]
11
+ profile_flags = []
12
+ if ctx .attr .aws_profile :
13
+ profile_flags = ["--profile" , ctx .attr .aws_profile ]
14
+ aws_cli_cmd = [aws_cli_path ] + profile_flags + ["s3" , "cp" , url , "." ]
12
15
s3_result = ctx .execute (aws_cli_cmd )
13
16
if s3_result .return_code != 0 :
14
17
fail ("Failed to download {} from S3: {}" .format (url , s3_result .stderr ))
@@ -24,25 +27,29 @@ def _s3_archive_impl(ctx):
24
27
url , ctx .attr .sha256 , sha256 ))
25
28
26
29
# Extract the downloaded archive.
27
- print ("Extracting {}" .format (filename ))
28
30
ctx .extract (filename , stripPrefix = ctx .attr .strip_prefix )
29
31
30
32
# Provide external BUILD file if requested.
31
33
bash_path = ctx .os .environ .get ("BAZEL_SH" , "bash" )
32
34
if ctx .attr .build_file :
33
- ctx .execute ([bash_path , "-c" , "rm -f BUILD BUILD.bazel" ])
34
- ctx .symlink (ctx .attr .build_file , "BUILD.bazel" )
35
+ ctx .execute ([bash_path , "-c" , "rm -f BUILD BUILD.bazel" ])
36
+ ctx .symlink (ctx .attr .build_file , "BUILD.bazel" )
35
37
36
38
37
39
s3_archive = repository_rule (
38
40
implementation = _s3_archive_impl , attrs = {
39
- "url" :
40
- attr .string (mandatory = True , doc = "S3 URL for the object" ),
41
+ "bucket" :
42
+ attr .string (mandatory = True , doc = "S3 bucket name" ),
43
+ "file_path" :
44
+ attr .string (mandatory = True ,
45
+ doc = "Relative path to the archive file within the bucket" ),
46
+ "aws_profile" :
47
+ attr .string (doc = "AWS profile to use for authentication" ),
41
48
"sha256" :
42
49
attr .string (mandatory = True , doc = "SHA256 checksum of the archive" ),
43
50
"build_file" :
44
51
attr .label (allow_single_file = True ,
45
- doc = "BUILD file for the unpacked archive. " ),
52
+ doc = "BUILD file for the unpacked archive" ),
46
53
"strip_prefix" :
47
- attr .string (doc = "Prefix to strip when archive is unpacked. " ),
54
+ attr .string (doc = "Prefix to strip when archive is unpacked" ),
48
55
})
0 commit comments