pass the AWS credentials through the Concourse source data

Concourse pipelines dont have a way of setting environment variables,
and this is consistent with how https://github.com/concourse/s3-resource
works.
This commit is contained in:
Aidan Feldman 2016-03-10 10:57:12 -05:00
parent 5dcef5d5f1
commit f1a98f3e9a
6 changed files with 24 additions and 19 deletions

View file

@ -1,3 +0,0 @@
# http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html#cli-signup
AWS_ACCESS_KEY_ID=<key>
AWS_SECRET_ACCESS_KEY=<secret>

2
.gitignore vendored
View file

@ -1 +1 @@
.env config.json

View file

@ -10,11 +10,8 @@ TODO
Requires Docker. Requires Docker.
```bash 1. Run `cp config.example.json config.json`.
cp .env.example .env 1. Modify `config.json`.
* See [the instructions for getting your AWS credentials](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html#cli-signup).
# modify .env * Exclude the `s3://` prefix/protocol for the `bucket`.
1. Run `./script/run </full/path/to/dir/or/file>`.
# exclude the `s3://` prefix/protocol for the `bucket`
./script/run </full/path/to/dir/or/file> <bucket>
```

View file

@ -20,12 +20,18 @@ fi
payload=`cat` payload=`cat`
bucket=$(echo "$payload" | jq -r '.source.bucket') bucket=$(echo "$payload" | jq -r '.source.bucket')
echo "Uploading to S3..." echo "Uploading to S3..."
# credentials are provided via environment variables
# http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-environment # http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-environment
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')
aws s3 sync $source "s3://$bucket" aws s3 sync $source "s3://$bucket"
echo "...done." echo "...done."
# use the current UNIX time as the version # use the current UNIX time as the version
# https://github.com/concourse/git-resource/blob/6fcfbd4/assets/out#L133-L136 # https://github.com/concourse/git-resource/blob/6fcfbd4/assets/out#L133-L136
jq -n "{ jq -n "{

7
config.example.json Normal file
View file

@ -0,0 +1,7 @@
{
"source": {
"access_key_id": "",
"secret_access_key": "",
"bucket": ""
}
}

View file

@ -3,19 +3,17 @@
set -e set -e
source=$1 source=$1
bucket=$2
if [ -z "$source" ] || [ -z "$bucket" ]; then if [ -z "$source" ]; then
echo "usage: $0 </full/path/to/dir/or/file> <bucket>" echo "usage: $0 </full/path/to/dir/or/file>"
exit 1 exit 1
fi fi
json=$(cat .env.json)
docker build -t 18fgsa/s3-resource-simple . docker build -t 18fgsa/s3-resource-simple .
json="{\"source\": {\"bucket\": \"$bucket\"}}"
echo $json | docker run \ echo $json | docker run \
--env-file .env \
-i \ -i \
--rm \ --rm \
-v $source:/tmp/input \ -v $source:/tmp/input \