-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_to_codebuild.sh
executable file
·57 lines (50 loc) · 1.11 KB
/
upload_to_codebuild.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
PREFIX=""
TREEISH="HEAD"
KEY=""
usage() {
cat <<EOF >&2
Usage: $0 -b BUCKET [-p PREFIX] [-t TREEISH] [-k KEY]
BUCKET: The S3 bucket to upload to.
PREFIX: The prefix within the bucket, if any. Note: this adds a trailing /, unless PREFIX is empty.
TREEISH: Git description of the version to upload, defaults to HEAD.
KEY: The key to use under the bucket and prefix. Defaults to "tileops-\$DESC.zip" where DESC is built from the git version.
EOF
exit 1
}
while getopts "b:p:t:k:" opt; do
case $opt in
b)
BUCKET=$OPTARG
;;
p)
PREFIX=$OPTARG
;;
t)
TREEISH=$OPTARG
;;
k)
KEY=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
:)
echo "Option -$OPTARG requires an argument" >&2
usage
;;
esac
done
if [ -z "$BUCKET" ]; then
echo "Bucket parameter is mandatory" >&2
usage
fi
if [ -z "$KEY" ]; then
DESCRIPTION=`git describe --tags --always`
KEY="tileops-${DESCRIPTION}.zip"
fi
if [ -n "$PREFIX" ]; then
PREFIX+="/"
fi
git archive --format zip $TREEISH | aws s3 cp - "s3://$BUCKET/$PREFIX$KEY"