finish up the out script

also add a `run` script for testing purposes
This commit is contained in:
Aidan Feldman 2016-03-10 03:01:02 -05:00
parent 0f17495982
commit 2202ac6080
6 changed files with 58 additions and 6 deletions

6
.env.example Normal file
View file

@ -0,0 +1,6 @@
# 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>
# exclude the `s3://` prefix/protocol
S3_BUCKET=<bucket name>

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.env

View file

@ -6,5 +6,3 @@ RUN pip install --upgrade pip
RUN pip install --upgrade awscli
ADD assets/ /opt/resource/
CMD echo Simple S3 Resource ready.

View file

@ -1,10 +1,17 @@
# Simple S3 Resource for [Concourse CI](http://concourse.ci)
Resource to upload files to S3. Unlike the [the official S3 Resource](https://github.com/concourse/s3-resource), this Resource doesn't care about files being versioned.
## Usage
TODO
## Development
Requires Docker.
```bash
docker build -t s3-resource-simple .
docker run --rm s3-resource-simple /opt/resource/out
cp .env.example .env
# modify .env
./script/run /full/path/to/dir/or/file
```

View file

@ -1,6 +1,26 @@
#!/bin/sh
# https://github.com/concourse/git-resource/blob/6fcfbd4/assets/out#L4-L16
set -e
set -x
echo foo
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
#######################################
# credentials are provided via environment variables
# http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-environment
aws s3 sync $source "s3://$S3_BUCKET"
# use the current UNIX time as the version
# https://github.com/concourse/git-resource/blob/6fcfbd4/assets/out#L133-L136
jq -n "{
version: {
timestamp: $(date +%s)}
}" >&3

20
script/run Executable file
View file

@ -0,0 +1,20 @@
#!/bin/sh
set -e
set -x
source=$1
if [ -z "$source" ]; then
echo "usage: $0 </full/path/to/dir/or/file>"
exit 1
fi
docker build -t s3-resource-simple .
docker run \
--env-file .env \
--rm \
-v $source:/tmp/input \
s3-resource-simple \
/opt/resource/out /tmp/input