Skip to content

Commit

Permalink
Merge pull request #6 from envato/sherv/add-endpoint-option
Browse files Browse the repository at this point in the history
Add endpoint url option to customise the s3 endpoint
  • Loading branch information
Shervanator authored Sep 6, 2022
2 parents b5d398f + 6c4b34e commit b29e4f5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
```
Expand All @@ -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/
```
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions lib/shared.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 2 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ configuration:
type: boolean
cache-control:
type: string
endpoint-url:
type: string
required:
- source
- destination
15 changes: 15 additions & 0 deletions tests/post-command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
14 changes: 14 additions & 0 deletions tests/pre-command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit b29e4f5

Please sign in to comment.