s3-resource-simple/assets/in
Phill Baker 414b3a3d10 Add option to skip downloading.
Example usage:
```
resources:
- name: <resource name>
  type: <resource type name>
  source:
    access_key_id: {{aws-access-key}}
    secret_access_key: {{aws-secret-key}}
    bucket: {{aws-bucket}}
jobs:
- name: <job name>
  plan:
  - put: <resource name>
     params:
       skip_download: true
```
2017-02-24 17:58:34 -05:00

43 lines
1.2 KiB
Bash
Executable file

#!/bin/sh
# Resource Impl: http://concourse.ci/implementing-resources.html#in:-fetch-a-given-resource
set -e
exec 3>&1 # make stdout available as fd 3 for the result
exec 1>&2 # redirect all output to stderr for logging
dest=$1
if [ -z "$dest" ]; then
echo "usage: $0 <path/to/volume>"
exit 1
fi
#######################################
# parse incoming config data
payload=`cat`
bucket=$(echo "$payload" | jq -r '.source.bucket')
path=$(echo "$payload" | jq -r '.source.path // ""')
options=$(echo "$payload" | jq -r '.source.options // [] | join(" ")')
skip_download=$(echo "$payload" | jq -r '.params.skip_download // ""')
# export for `aws` cli
AWS_ACCESS_KEY_ID=$(echo "$payload" | jq -r '.source.access_key_id')
AWS_SECRET_ACCESS_KEY=$(echo "$payload" | jq -r '.source.secret_access_key')
# Due to precedence rules, must be unset to support AWS IAM Roles.
if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
fi
if [ "$skip_download" = "true" ]; then
echo "Skipping downloading from S3..."
else
echo "Downloading from S3..."
eval aws s3 sync "s3://$bucket/$path" $dest $options
echo "...done."
fi
source "$(dirname $0)/emit.sh" >&3