This repository was archived by the owner on Jul 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
74 lines (56 loc) · 1.73 KB
/
run.sh
File metadata and controls
74 lines (56 loc) · 1.73 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
set -e
if [ -z "$PLUGIN_MOUNT" ]; then
echo "Must specify directories to cache. Exiting!"
exit 1
fi
if [ -z "$PLUGIN_BUCKET" ]; then
echo "Must provide S3 bucket name. Exiting!"
exit 1
fi
VERBOSE=""
if [[ -n "$PLUGIN_VERBOSE" && "$PLUGIN_VERBOSE" == "true" ]]; then
VERBOSE="-v"
fi
CACHE_PATH="$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$DRONE_BRANCH"
FALLBACK_PATH="$DRONE_REPO_OWNER/$DRONE_REPO_NAME/master"
PATHS_TO_TAR=$(echo $PLUGIN_MOUNT | sed 's/,/ /g')
echo "Starting at $(date)"
if [[ -n "$PLUGIN_REBUILD" && "$PLUGIN_REBUILD" == "true" ]]; then
PATHS=""
echo "Compressing selected paths:"
for i in $PATHS_TO_TAR; do
if test -e $i; then
PATHS+=" ${i}"
echo "Adding ${i}"
else
echo "Cannot find ${i}. Skipping."
fi
done
if [[ $PATHS == "" ]]; then
echo "No paths found for cache. Moving on..."
exit 0
else
tar cf - $PATHS | pigz $VERBOSE > archive.tgz
fi
echo "Compression complete, uploading to S3"
s3cmd $VERBOSE sync archive.tgz s3://$PLUGIN_BUCKET/$CACHE_PATH/archive.tgz
echo "Upload completed!"
echo "Finished! Exiting at $(date)" && exit 0
elif [[ -n "$PLUGIN_RESTORE" && "$PLUGIN_RESTORE" == "true" ]]; then
if s3cmd get s3://$PLUGIN_BUCKET/$CACHE_PATH/archive.tgz archive.tgz; then
echo "Cache downloaded successfully."
elif s3cmd get s3://$PLUGIN_BUCKET/$FALLBACK_PATH/archive.tgz archive.tgz; then
echo "Cache downloaded successfully."
else
echo "Cannot find cache. Skipping!"
exit 0
fi
echo "Uncompressing cache file."
unpigz $VERBOSE < archive.tgz | tar $VERBOSE -xC .
echo "Cache uncompressed."
echo "Finished! Exiting at $(date)" && exit 0
else
echo "Must provide either restore or rebuild flag. Exiting!"
exit 1
fi