-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·76 lines (68 loc) · 1.5 KB
/
deploy.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
#
# $ npm run deploy # upload a release from dist/index.html to s3idx
# $ npm run deploy -- -n [bucket...] # upload dist/index.html to multiple buckets
set -e
ARGS=()
cache=1
dry_run=
tag=
while (("$#")); do
case "$1" in
-t | --tag)
shift
tag="$1"
shift
;;
-C | --no-cache)
shift
cache=
;;
-n | --dry-run)
shift
dry_run=1
;;
-*|--*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
ARGS+=("$1")
shift
;;
esac
done
set -- "${ARGS[@]}"
if [ -z "$tag" ]; then
tag="$(git tag --points-at HEAD)"
fi
args=(--content-type="text/html; charset=utf-8" --acl public-read)
if [ -n "$cache" ]; then
cache_args=()
else
cache_args=(--cache-control max-age=0,public)
fi
run() {
if [ -n "$dry_run" ]; then
echo "Would run: $@"
else
echo "Running: $@"
"$@"
fi
}
if [ $# -gt 0 ]; then
for bucket in "$@"; do
if [ -z "$tag" ]; then
src=dist/index.html
else
src="s3://s3idx/$tag/index.html"
fi
run aws s3 cp "$src" s3://$bucket/index.html "${args[@]}" "${cache_args[@]}"
done
else
bucket=s3idx
# Always disable caching on the top-level index.html
run aws s3 cp dist/index.html s3://$bucket/index.html "${args[@]}" --cache-control max-age=0,public
# Enable caching on specific release tags (unless -C|--no-cache was passed explicitly)
run aws s3 cp dist/index.html s3://$bucket/$tag/index.html "${args[@]}" "${cache_args[@]}"
fi