-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-function.bash
54 lines (48 loc) · 1.43 KB
/
deploy-function.bash
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
force=
while :; do
case "${1:-}" in
-h|--help)
shift
echo "Usage:"
echo " $0 [OPTIONS]"
echo
echo "Options:"
echo " -f, --force Run the the deploy command, even if the function has been deployed"
exit
;;
-f|--force)
force=1
;;
-?*)
echo "Error: unknown option: $1" >&2
exit 1
;;
*)
break
esac
shift
done
packageId="${outPath#/nix/store/}"
hashLabelValue="${packageId%%-*}"
hashLabelKey=function-hash
hashLabel="$hashLabelKey=$hashLabelValue"
deployedHash="$(gcloud functions describe --format="value(labels.$hashLabelKey)" "$functionName" || echo function not deployed yet)"
if [[ "$deployedHash" == "$hashLabelValue" ]]; then
echo "The function $functionName already has the label $hashLabel"
echo "That means it already has all the source and configuration which this command would deploy."
if [[ "$force" != 1 ]]; then
echo "Run with --force to force deployment"
exit 0
else
echo "This script was run with --force; deploying the function anyway!"
fi
else
if [[ "$force" == 1 ]]; then
echo "This script was run with --force, but that was unnecessary; it was going to deploy the function anyway."
fi
fi
echo "Deploying $functionName to Google Cloud Platform..."
gcloud functions deploy "$functionName" \
--update-labels "$hashLabel" \
"${deployFlags[@]}"
echo "Cloud Function $functionName has been deployed"