Skip to content

Commit f8d13f5

Browse files
committed
Initial commit.
0 parents  commit f8d13f5

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# s3put
2+
3+
Upload a file to a s3 bucket.
4+
5+
Synchronized a directory to a s3 bucket. It makes the bucket identical to the `source-dir`.
6+
Note that this means that remote files that are not in the `source-dir` are deleted.
7+
The synchronized files will get an public access level.
8+
9+
You can use application and deployment variables in wercker.
10+
11+
View this step in the [wercker directory](#TODO)
12+
13+
Current status on wercker:
14+
15+
TODO
16+
17+
## Options
18+
19+
* `key-id` (required) The Amazon Access key that will be used for authorization.
20+
* `key-secret` (required) The Amazon Access secret that will be used for authorization.
21+
* `bucket-url` (required) The url of the bucket to sync to, like: `s3://born2code.net`
22+
* `source-file` (required) The local file to upload to s3.
23+
* `dest-file` (required) The name of the file to upload to.
24+
25+
## Example
26+
27+
- s3put:
28+
key-id: $KEY
29+
key-secret: $SECRET
30+
bucket-url: $BUCKET
31+
source-file: myproject-0.1.0.tar.gz
32+
dest-file: myproject-latest.tar.gz

run.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/sh
2+
set -e
3+
cd $HOME
4+
if [ ! -n "$WERCKER_S3PUT_KEY_ID" ]
5+
then
6+
fail 'missing or empty option key_id, please check wercker.yml'
7+
fi
8+
9+
if [ ! -n "$WERCKER_S3PUT_KEY_SECRET" ]
10+
then
11+
fail 'missing or empty option key_secret, please check wercker.yml'
12+
fi
13+
14+
if [ ! -n "$WERCKER_S3PUT_BUCKET_URL" ]
15+
then
16+
fail 'missing or empty option bucket_url, please check wercker.yml'
17+
fi
18+
19+
if [ ! -n "$WERCKER_S3PUT_SOURCE_FILE" ]
20+
then
21+
fail 'missing or empty option source_file, please check wercker.yml'
22+
fi
23+
24+
if [ ! -n "$WERCKER_S3PUT_DEST_FILE" ]
25+
then
26+
fail 'missing or empty option dest_file, please check wercker.yml'
27+
fi
28+
29+
if ! type s3cmd &> /dev/null ;
30+
then
31+
info 's3cmd not found, start installing it'
32+
wget -O- -q http://s3tools.org/repo/deb-all/stable/s3tools.key | sudo apt-key add -
33+
sudo wget -O/etc/apt/sources.list.d/s3tools.list http://s3tools.org/repo/deb-all/stable/s3tools.list
34+
sudo apt-get update && sudo apt-get install s3cmd
35+
success 's3cmd installed succesfully'
36+
else
37+
info 'skip s3cmd install, command already available'
38+
debug "type s3cmd: $(type s3cmd)"
39+
fi
40+
41+
if [ -e '.s3cfg' ]
42+
then
43+
warn '.s3cfg file already exists in home directory and will be overwritten'
44+
fi
45+
46+
echo '[default]' > '.s3cfg'
47+
echo "access_key=$WERCKER_S3PUT_KEY_ID" >> .s3cfg
48+
echo "secret_key=$WERCKER_S3PUT_KEY_SECRET" >> .s3cfg
49+
debug "generated .s3cfg for key $WERCKER_S3PUT_KEY_ID"
50+
51+
source_file="$WERCKER_ROOT/$WERCKER_S3PUT_SOURCE_FILE"
52+
dest_file="$WERCKER_S3PUT_BUCKET_URL/$WERCKER_S3PUT_DEST_FILE"
53+
54+
info 'starting s3 upload'
55+
56+
# TODO make public an option
57+
58+
set +e
59+
debug "s3cmd put --acl-public --verbose '$source_file' '$dest_file'"
60+
sync_output=$(s3cmd sync --acl-public --verbose "$source_file" "$dest_file")
61+
62+
if [[ $? -ne 0 ]];then
63+
warning $sync_output
64+
fail 's3cmd failed';
65+
else
66+
success 'finished s3 upload';
67+
fi
68+
set -e

wercker-step.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: s3put
2+
version: 0.0.1
3+
description: s3put step

0 commit comments

Comments
 (0)