-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathentrypoint.sh
executable file
·96 lines (80 loc) · 2.39 KB
/
entrypoint.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash -l
set -eo pipefail
# check configuration
err=0
if [ -z "$DISTRIBUTION" ]; then
echo "error: DISTRIBUTION is not set"
err=1
fi
if [[ -z "$PATHS" && -z "$PATHS_FROM" ]]; then
echo "error: PATHS or PATHS_FROM is not set"
err=1
fi
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
echo "error: AWS_ACCESS_KEY_ID is not set"
err=1
fi
if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
echo "error: AWS_SECRET_ACCESS_KEY is not set"
err=1
fi
if [ -z "$AWS_REGION" ]; then
echo "error: AWS_REGION is not set"
err=1
fi
if [ $err -eq 1 ]; then
exit 1
fi
# run
# Set it here to avoid logging keys/secrets
if [ "$DEBUG" = "1" ]; then
echo "*** Enabling debug output (set -x)"
set -x
fi
# Ensure we have jq-1.6
jq="jq"
if [[ ! -x "$(command -v $jq)" || "$($jq --version)" != "jq-1.6" ]]; then
if [[ $(uname) == "Darwin" ]]; then
jqbin="jq-osx-amd64"
elif [[ $(uname) == "Linux" ]]; then
jqbin="jq-linux64"
fi
if [[ -n "$jqbin" ]]; then
jq="/usr/local/bin/jq16"
wget -nv -O $jq /~https://github.com/stedolan/jq/releases/download/jq-1.6/$jqbin
chmod 755 $jq
fi
fi
if [[ -n "$PATHS_FROM" ]]; then
echo "*** Reading PATHS from $PATHS_FROM"
if [[ ! -f $PATHS_FROM ]]; then
echo "PATHS file not found. nothing to do. exiting"
exit 0
fi
PATHS=$(cat $PATHS_FROM | tr '\n' ' ')
echo "PATHS=$PATHS"
if [[ -z "$PATHS" ]]; then
echo "PATHS is empty. nothing to do. exiting"
exit 0
fi
fi
# Handle multiple space-separated paths, particularly containing wildcards.
# i.e., if PATHS="/* /foo"
IFS=' ' read -r -a PATHS_ARR <<<"$PATHS"
echo -n "${PATHS}" >"${RUNNER_TEMP}/paths.txt"
JSON_PATHS=$($jq --null-input --compact-output --monochrome-output --rawfile inarr "${RUNNER_TEMP}/paths.txt" '$inarr | rtrimstr(" ") | rtrimstr("\n") | split(" ")')
LEN="${#PATHS_ARR[@]}"
CR="$(date +"%s")$RANDOM"
cat <<-EOF >"${RUNNER_TEMP}/invalidation-batch.json"
{ "InvalidationBatch": { "Paths": { "Quantity": ${LEN}, "Items": ${JSON_PATHS} }, "CallerReference": "${CR}" } }
EOF
if [ "$DEBUG" = "1" ]; then
echo "> wrote ${RUNNER_TEMP}/invalidation-batch.json"
cat "${RUNNER_TEMP}/invalidation-batch.json"
fi
# Support v1.x of the awscli which does not have this flag
[[ "$(aws --version)" =~ "cli/2" ]] && pagerflag="--no-cli-pager"
aws $pagerflag \
cloudfront create-invalidation \
--distribution-id "$DISTRIBUTION" \
--cli-input-json "file://${RUNNER_TEMP}/invalidation-batch.json"