Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
plan:
- <some Resource or Task that outputs files>
- put: <resource name>
- put: to-s3
get_params: [<optional>, use to not download the contents of the bucket.]
skip_download: true
```

## AWS Credentials
Expand Down Expand Up @@ -69,4 +72,4 @@ region: eu-west-2

Bug reports and pull requests are welcome on GitHub at https://github.com/firespring/concourse-s3-sync-resource.

For details on the pull request process please see our [contributing documentation](CONTRIBUTING.md)
For details on the pull request process please see our [contributing documentation](CONTRIBUTING.md)
42 changes: 26 additions & 16 deletions assets/in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fi
#######################################

# parse incoming config data
skip_download=$(echo "$payload" | jq -r '.params.skip_download // "false"')
payload=`cat`
bucket=$(echo "$payload" | jq -r '.source.bucket')
path=$(echo "$payload" | jq -r '.source.path // ""')
Expand All @@ -34,22 +35,31 @@ fi
# Export AWS_DEFAULT_REGION if set
[ -n "$AWS_DEFAULT_REGION" ] && export AWS_DEFAULT_REGION

echo "Downloading from S3..."
eval aws s3 sync "s3://$bucket/$path" $dest $options
echo "...done."
if [ "$skip_download" != "true" ]; then
echo "Downloading from S3..."
eval aws s3 sync "s3://$bucket/$path" $dest $options
echo "...done."

# Output Link to Coverage Report
prefix="index.html"
if [ -n "$path" ]; then
prefix="$path/index.html"
fi
# Output Link to Coverage Report
prefix="index.html"
if [ -n "$path" ]; then
prefix="$path/index.html"
fi

index_versions=$(aws s3api list-object-versions --bucket $bucket --prefix ${prefix})
version_id=$(echo $index_versions | jq -r '.Versions[0].VersionId')
key=$(echo $index_versions | jq -r '.Versions[0].Key')
url="https://s3-$AWS_DEFAULT_REGION.amazonaws.com/$bucket/$key?versionId=$version_id"

index_versions=$(aws s3api list-object-versions --bucket $bucket --prefix ${prefix})
version_id=$(echo $index_versions | jq -r '.Versions[0].VersionId')
key=$(echo $index_versions | jq -r '.Versions[0].Key')
url="https://s3-$AWS_DEFAULT_REGION.amazonaws.com/$bucket/$key?versionId=$version_id"
echo "{
\"version\": {\"version_id\": \"$version_id\"},
\"metadata\": [{\"name\":\"report url:\",\"value\": \"$url\"}]
}" >&3

else
echo "skip_download parameter is set to \"$skip_download\", skipping download"
echo "{
\"version\": {}
}" >&3
fi

echo "{
\"version\": {\"version_id\": \"$version_id\"},
\"metadata\": [{\"name\":\"report url:\",\"value\": \"$url\"}]
}" >&3