Drone CI Plugins
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

drone-s3-sync

Build Status Docker Hub Quay.io GitHub contributors Source: GitHub License: MIT

Drone plugin to synchronize a directory with an S3 bucket.

Usage

kind: pipeline
name: default

steps:
  - name: sync
    image: thegeeklab/drone-s3-sync
    settings:
      access_key: a50d28f4dd477bc184fbd10b376de753
      secret_key: bc5785d3ece6a9cdefa42eb99b58986f9095ff1c
      region: us-east-1
      bucket: my-bucket.s3-website-us-east-1.amazonaws.com
      source: folder/to/archive
      target: /target/location

Parameters

access-key optional string
S3 access key.
Default: none
acl optional map
Access control list.
Default: none
bucket required string
Name of the bucket.
Default: none
cache_control optional map
Cache-control settings for uploads.
Default: none
cloudfront-distribution optional string
ID of cloudfront distribution to invalidate.
Default: none
content-encoding optional map
Content-encoding settings for uploads.
Default: none
content-type optional map
Content-type settings for uploads.
Default: none
delete optional bool
Delete locally removed files from the target.
Default: none
dry_run optional bool
Dry run disables API calls.
Default: none
endpoint optional string
Endpoint for the s3 connection.
Default: none
max_concurrency optional int
Customize number of concurrent files to process.
Default: 100
metadata optional map
Additional metadata for uploads.
Default: none
path-style optional bool
Enable path style for bucket paths.
Default: none
redirects optional map
Redirects to create.
Default: none
region optional string
S3 region.
Default: us-east-1
secret-key optional string
S3 secret key.
Default: none
source optional string
Upload source path.
Default: .
target optional string
Upload target path.
Default: /

Examples

Customize acl, content_type, content_encoding or cache_control:

kind: pipeline
name: default

steps:
  - name: sync
    image: thegeeklab/drone-s3-sync
    settings:
      access_key: a50d28f4dd477bc184fbd10b376de753
      secret_key: bc5785d3ece6a9cdefa42eb99b58986f9095ff1c
      region: us-east-1
      bucket: my-bucket.s3-website-us-east-1.amazonaws.com
      source: folder/to/archive
      target: /target/location
      acl:
        "public/*": public-read
        "private/*": private
      content_type:
        ".svg": image/svg+xml
      content_encoding:
        ".js": gzip
        ".css": gzip
      cache_control: "public, max-age: 31536000"

All map parameters can be specified as map for a subset of files or as string for all files.

  • For the acl parameter the key must be a glob. Files without a matching rule will default to private.
  • For the content_type parameter, the key must be a file extension (including the leading dot). To apply a configuration to files without extension, the key can be set to an empty string "". For files without a matching rule, the content type is determined automatically.
  • For the content_encoding parameter, the key must be a file extension (including the leading dot). To apply a configuration to files without extension, the key can be set to an empty string "". For files without a matching rule, no Content Encoding header is set.
  • For the cache_control parameter, the key must be a file extension (including the leading dot). If you want to set cache control for files without an extension, set the key to the empty string "". For files without a matching rule, no Cache Control header is set.

Sync to Minio S3:

To use Minio S3 its required to set path_style: true.

kind: pipeline
name: default

steps:
  - name: sync
    image: thegeeklab/drone-s3-sync
    settings:
      endpoint: https://minio.example.com
      access_key: a50d28f4dd477bc184fbd10b376de753
      secret_key: bc5785d3ece6a9cdefa42eb99b58986f9095ff1c
      bucket: my-bucket
      source: folder/to/archive
      target: /target/location
      path_style: true

Build

Build the binary with the following command:

export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on

make build

Build the Docker image with the following command:

docker build --file docker/Dockerfile.amd64 --tag thegeeklab/drone-s3-sync .

Test

docker run --rm \
  -e PLUGIN_BUCKET=my_bucket \
  -e AWS_ACCESS_KEY_ID=abc123 \
  -e AWS_SECRET_ACCESS_KEY=xyc789 \
  -v $(pwd):$(pwd) \
  -w $(pwd) \
  thegeeklab/drone-s3-sync