diff --git a/README.md b/README.md index df4da2a..e05df19 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ steps: - label: "Generate files and push to S3" command: bin/command-that-generates-files plugins: - - envato/aws-s3-sync#v0.4.0: + - envato/aws-s3-sync#v0.5.0: source: local-directory/ destination: s3://example-bucket/directory/ ``` @@ -26,7 +26,7 @@ steps: - label: "Pull files from S3 and execute task" command: bin/command-that-uses-files plugins: - - envato/aws-s3-sync#v0.4.0: + - envato/aws-s3-sync#v0.5.0: source: s3://example-bucket/directory/ destination: local-directory/ ``` @@ -59,6 +59,12 @@ Defaults to `null` Specify the cache control metadata value for all syncable objects +### `endpoint-url` + +Defaults to `null` + +Optionally specify an s3 endpoint URL to override the default. This option can be used to integrate with services that provide a s3 compatible api like CloudFlare R2. + ## Development To run the tests: diff --git a/lib/shared.bash b/lib/shared.bash index ca05355..e5d21b1 100644 --- a/lib/shared.bash +++ b/lib/shared.bash @@ -18,6 +18,10 @@ function aws_s3_sync() { params+=("--cache-control=${BUILDKITE_PLUGIN_AWS_S3_SYNC_CACHE_CONTROL/\ /}") fi + if [[ -n "${BUILDKITE_PLUGIN_AWS_S3_SYNC_ENDPOINT_URL:-}" ]]; then + params+=("--endpoint-url=${BUILDKITE_PLUGIN_AWS_S3_SYNC_ENDPOINT_URL/\ /}") + fi + params+=("$source") params+=("$destination") diff --git a/plugin.yml b/plugin.yml index 8d6dd38..f75fc2f 100644 --- a/plugin.yml +++ b/plugin.yml @@ -15,6 +15,8 @@ configuration: type: boolean cache-control: type: string + endpoint-url: + type: string required: - source - destination diff --git a/tests/post-command.bats b/tests/post-command.bats index 7c8a149..15c86bc 100755 --- a/tests/post-command.bats +++ b/tests/post-command.bats @@ -63,6 +63,21 @@ load '/usr/local/lib/bats/load.bash' unstub aws } +@test "Uses endpoint URL" { + export BUILDKITE_COMMAND_EXIT_STATUS=0 + export BUILDKITE_PLUGIN_AWS_S3_SYNC_SOURCE=source/ + export BUILDKITE_PLUGIN_AWS_S3_SYNC_DESTINATION=s3://destination + export BUILDKITE_PLUGIN_AWS_S3_SYNC_ENDPOINT_URL=https://myaccountid.r2.cloudflarestorage.com + + stub aws "s3 sync --endpoint-url=https://myaccountid.r2.cloudflarestorage.com source/ s3://destination : echo s3 sync --endpoint-url=https://myaccountid.r2.cloudflarestorage.com" + + run $PWD/hooks/post-command + + assert_success + assert_output --partial "s3 sync --endpoint-url=https://myaccountid.r2.cloudflarestorage.com" + unstub aws +} + @test "Doesn't attempt to sync files if the step command fails" { export BUILDKITE_COMMAND_EXIT_STATUS=1 export BUILDKITE_PLUGIN_AWS_S3_SYNC_SOURCE=source/ diff --git a/tests/pre-command.bats b/tests/pre-command.bats index bdeef16..49daa13 100644 --- a/tests/pre-command.bats +++ b/tests/pre-command.bats @@ -46,6 +46,20 @@ load '/usr/local/lib/bats/load.bash' unstub aws } +@test "Uses endpoint URL" { + export BUILDKITE_PLUGIN_AWS_S3_SYNC_SOURCE=s3://source + export BUILDKITE_PLUGIN_AWS_S3_SYNC_DESTINATION=destination/ + export BUILDKITE_PLUGIN_AWS_S3_SYNC_ENDPOINT_URL=https://myaccountid.r2.cloudflarestorage.com + + stub aws "s3 sync --endpoint-url=https://myaccountid.r2.cloudflarestorage.com s3://source destination/ : echo s3 sync --endpoint-url=https://myaccountid.r2.cloudflarestorage.com" + + run $PWD/hooks/pre-command + + assert_success + assert_output --partial "s3 sync --endpoint-url=https://myaccountid.r2.cloudflarestorage.com" + unstub aws +} + @test "Ignores cache control option" { export BUILDKITE_PLUGIN_AWS_S3_SYNC_SOURCE=s3://source export BUILDKITE_PLUGIN_AWS_S3_SYNC_DESTINATION=destination/