2016-03-10 08:16:03 +01:00
|
|
|
#!/bin/sh
|
2016-03-10 07:32:05 +01:00
|
|
|
|
2016-03-18 20:19:48 +01:00
|
|
|
# Resource Impl: http://concourse.ci/implementing-resources.html#out:-update-a-resource.
|
2016-03-10 07:32:05 +01:00
|
|
|
set -e
|
|
|
|
|
2016-03-10 09:01:02 +01:00
|
|
|
exec 3>&1 # make stdout available as fd 3 for the result
|
|
|
|
exec 1>&2 # redirect all output to stderr for logging
|
|
|
|
|
|
|
|
source=$1
|
|
|
|
|
|
|
|
if [ -z "$source" ]; then
|
2016-03-21 23:38:36 +01:00
|
|
|
echo "usage: $0 </full/path/to/dir>"
|
2016-03-10 09:01:02 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
#######################################
|
|
|
|
|
2016-03-10 09:57:41 +01:00
|
|
|
# parse incoming config data
|
|
|
|
payload=`cat`
|
|
|
|
bucket=$(echo "$payload" | jq -r '.source.bucket')
|
2016-10-04 16:33:07 +02:00
|
|
|
path=$(echo "$payload" | jq -r '.source.path // ""')
|
2016-03-18 21:13:29 +01:00
|
|
|
options=$(echo "$payload" | jq -r '.source.options // [] | join(" ")')
|
2016-03-10 09:57:41 +01:00
|
|
|
|
2016-03-18 20:19:48 +01:00
|
|
|
# export for `aws` cli
|
2016-08-18 11:31:03 +02:00
|
|
|
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
|
2016-03-10 16:57:12 +01:00
|
|
|
|
2016-03-18 20:19:48 +01:00
|
|
|
echo "Uploading to S3..."
|
2016-10-04 16:33:07 +02:00
|
|
|
eval aws s3 sync $source "s3://$bucket/$path" $options
|
2016-03-10 09:57:41 +01:00
|
|
|
echo "...done."
|
2016-03-10 09:01:02 +01:00
|
|
|
|
2016-03-10 18:35:56 +01:00
|
|
|
source "$(dirname $0)/emit.sh" >&3
|