forked from panubo/docker-staticsite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths3sync.sh
More file actions
executable file
·71 lines (57 loc) · 1.91 KB
/
s3sync.sh
File metadata and controls
executable file
·71 lines (57 loc) · 1.91 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
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
[[ "${DEBUG:-}" == 'true' ]] && set -x
CACHE_CONTROL_DEFAULT="${CACHE_CONTROL_DEFAULT-public, max-age=3600}"
CACHE_CONTROL_DEFAULT_OVERRIDE="${CACHE_CONTROL_DEFAULT_OVERRIDE-public, max-age=60, s-maxage=60}"
s3sync() {
# Configuration checks
if [[ -z "${AWS_BUCKET_NAME:-}" ]]; then
echo "Error: AWS_BUCKET_NAME is not specified"
exit 128
fi
if [[ -z "${AWS_ACCESS_KEY_ID:-}" ]]; then
echo "Warning: AWS_ACCESS_KEY_ID not specified"
fi
if [[ -z "${AWS_SECRET_ACCESS_KEY:-}" ]]; then
echo "Warning: AWS_SECRET_ACCESS_KEY not specified"
fi
CMD=()
OVERRIDE_CMD=("--exclude" '*')
# Add --dryrun if DEBUG=true
if [[ "${DEBUG:-}" == "true" ]]; then
CMD+=("--dryrun")
OVERRIDE_CMD+=("--dryrun")
fi
# Add the Cache Control default if set
if [[ -n "${CACHE_CONTROL_DEFAULT}" ]]; then
CMD+=("--cache-control" "${CACHE_CONTROL_DEFAULT}")
fi
# Add exclude when an override is set
while read -r line; do
# value="$(
# export "${line?}"
# name="${line%%\=*}"
# echo "${!name}"
# )"
# IFS=":" read -r -a override <<<"${value}"
IFS=":" read -r -a override <<<"${line#*\=}"
CMD+=("--exclude" "${override[0]}")
echo ">> Adding exclude for: ${override[0]}"
done < <(env | grep "^CACHE_CONTROL_OVERRIDE")
# Run the main sync (excludes overrides)
set -x
aws s3 sync /var/www/html "s3://${AWS_BUCKET_NAME}" --delete "${CMD[@]}"
set +x
# Run the override syncs
while read -r line; do
IFS=":" read -r -a override <<<"${line#*\=}"
echo ">> Override sync for: ${override[0]}"
cache_control="${override[1]:-${CACHE_CONTROL_DEFAULT_OVERRIDE}}"
set -x
aws s3 sync /var/www/html "s3://${AWS_BUCKET_NAME}" --delete "${OVERRIDE_CMD[@]}" --include "${override[0]}" --cache-control "${cache_control}"
set +x
done < <(env | grep "^CACHE_CONTROL_OVERRIDE")
}
s3sync
echo ">> Sync done"