Skip to content

Commit d3bae97

Browse files
authored
feat: Support args in s3_sync (#115)
Resolves #100 --- ### Changes are visible to end-users: yes - Searched for relevant documentation and updated as needed: yes - Breaking change (forces users to change their own code or config): no - Suggested release notes appear below: no ### Test plan - Manual testing with `--dry_run` and `s3_args = ["--dryrun", "--other-flags"]`
1 parent 902938e commit d3bae97

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

aws/private/s3_sync.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ _ATTRS = {
2727
"role": attr.string(
2828
doc = "Assume this role before copying files, using `aws sts assume-role`",
2929
),
30+
"s3_args": attr.string_list(
31+
doc = "Additional arguments to pass to the aws s3 cp command",
32+
default = [],
33+
),
3034
"aws": attr.label(
3135
doc = "AWS CLI",
3236
),
@@ -74,6 +78,7 @@ def _s3_sync_impl(ctx):
7478
"$coreutils": coreutils.coreutils_info.bin.short_path,
7579
"$jq": jq.jqinfo.bin.short_path,
7680
"artifacts=()": "artifacts=({})".format(" ".join([s.short_path for s in ctx.files.srcs])),
81+
"s3_args=()": "s3_args=({})".format(" ".join(ctx.attr.s3_args)),
7782
"# Collect Args": "\n".join(vars),
7883
},
7984
)

aws/private/s3_sync.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ s3_cp() {
8888

8989
if [[ "${dry_run}" == "false" ]]; then
9090
warn "Copying ${src} to ${dst}"
91-
"$aws" s3 cp "${src}" "${dst}"
91+
"$aws" s3 cp "${s3_args[@]}" "${src}" "${dst}"
9292
else
9393
warn "[DRY RUN] Would copy ${src} to ${dst}"
94+
if [[ "${#s3_args[@]}" -gt 0 ]]; then
95+
warn "[DRY RUN] with args: ${s3_args[*]}"
96+
fi
9497
fi
9598

9699
if [[ -n "${output_json_file}" ]]; then
@@ -124,6 +127,7 @@ output_json_results() {
124127
dry_run=false
125128
output_json_file=""
126129
artifacts=()
130+
s3_args=()
127131
sha256_results=()
128132

129133
while (("$#")); do

examples/release_to_s3/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ s3_sync(
3333
bucket = "my-bucket-name/sub-folder",
3434
)
3535

36+
# s3_args can be used to pass options to aws s3 cp
37+
s3_sync(
38+
name = "release_with_args",
39+
srcs = ["my_file.txt"],
40+
bucket = "my-bucket-name/sub-folder",
41+
s3_args = ["--sse"],
42+
)
43+
3644
##############
3745
# Use case: Copy one file to an exact S3 URI that varies depending on stamping
3846
# See https://github.com/aspect-build/rules_aws/issues/83

0 commit comments

Comments
 (0)