2016-03-10 08:16:03 +01:00
|
|
|
#!/bin/sh
|
2016-03-10 07:32:05 +01:00
|
|
|
|
2016-03-10 09:57:41 +01:00
|
|
|
# http://concourse.ci/implementing-resources.html#out:-update-a-resource.
|
|
|
|
|
2016-03-10 09:01:02 +01:00
|
|
|
# https://github.com/concourse/git-resource/blob/6fcfbd4/assets/out#L4-L16
|
2016-03-10 07:32:05 +01:00
|
|
|
set -e
|
2016-03-10 17:40:41 +01:00
|
|
|
set -x
|
2016-03-10 07:32:05 +01:00
|
|
|
|
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
|
|
|
|
echo "usage: $0 <path/to/volume>"
|
|
|
|
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-03-10 16:57:12 +01:00
|
|
|
|
2016-03-10 09:57:41 +01:00
|
|
|
echo "Uploading to S3..."
|
2016-03-10 16:57:12 +01:00
|
|
|
|
2016-03-10 09:01:02 +01:00
|
|
|
# http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-environment
|
2016-03-10 16:57:12 +01:00
|
|
|
export AWS_ACCESS_KEY_ID=$(echo "$payload" | jq -r '.source.access_key_id')
|
|
|
|
export AWS_SECRET_ACCESS_KEY=$(echo "$payload" | jq -r '.source.secret_access_key')
|
|
|
|
|
2016-03-10 09:57:41 +01:00
|
|
|
aws s3 sync $source "s3://$bucket"
|
2016-03-10 16:57:12 +01:00
|
|
|
|
2016-03-10 09:57:41 +01:00
|
|
|
echo "...done."
|
2016-03-10 09:01:02 +01:00
|
|
|
|
2016-03-10 16:57:12 +01:00
|
|
|
|
2016-03-10 09:01:02 +01:00
|
|
|
# use the current UNIX time as the version
|
|
|
|
# https://github.com/concourse/git-resource/blob/6fcfbd4/assets/out#L133-L136
|
|
|
|
jq -n "{
|
|
|
|
version: {
|
2016-03-10 17:40:41 +01:00
|
|
|
timestamp: \"$(date +%s)\"}
|
2016-03-10 09:01:02 +01:00
|
|
|
}" >&3
|