-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrender-configs.sh
executable file
·100 lines (90 loc) · 2.75 KB
/
render-configs.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
97
98
99
100
#!/bin/bash
# Populates configurations necessary for local development.
# Certs are regenerated on a 3-month rotation so this script is optimized for that task.
# You MUST be on the Broad VPN
# You MUST have jq, gcloud and kubectl installed to run this script.
# You MUST authenticate via gcloud
#
# See usage section below for more details. All arguments are optional.
set -eu
set -o pipefail
usage() {
cat <<EOF
Usage: $0 [OPTION]...
Generate cert files for local development
--project PROJECT Google project where cert files are stored
--write_env WRITE_ENV Write an .env.local file to project root. true|false. Defaults to false
--write_config WRITE_CONFIG Write a config.json file in public. true|false. Defaults to false
--help Display this help and exit
EOF
exit 0
}
error() {
echo "ERROR: $1" >&2
exit 1
}
# default values that may be overridden by command line arguments
PROJECT="broad-dsde-dev"
WRITE_ENV="false"
WRITE_CONFIG="false"
parse_cli_args() {
while [ $# -gt 0 ]; do
case "$1" in
--project)
PROJECT=$2
shift 2
;;
--write_env)
WRITE_ENV=$2
shift 2
;;
--write_config)
WRITE_CONFIG=$2
shift 2
;;
--help)
usage
;;
*)
error "Unknown option: $1. Try --help to see a list of all options."
;;
esac
done
}
auth_gcloud() {
echo "Getting cluster credentials"
gcloud container clusters get-credentials --zone us-central1-a --project "$PROJECT" terra-dev
}
write_certs() {
echo "Writing cert files"
kubectl -n local-dev get secrets local-dev-cert -o 'go-template={{ index .data "tls.crt" | base64decode }}' > ../server.crt
kubectl -n local-dev get secrets local-dev-cert -o 'go-template={{ index .data "tls.key" | base64decode }}' > ../server.key
kubectl -n local-dev get configmaps kube-root-ca.crt -o 'go-template={{ index .data "ca.crt" }}' > ../ca-bundle.crt
}
write_env() {
echo "Generating .env.local file"
echo "
HOST=local.dsde-dev.broadinstitute.org
HTTPS=true
SSL_CRT_FILE=server.crt
SSL_KEY_FILE=server.key" > ../.env.local
}
write_config() {
echo "Generating public/config.json file"
JSON=$(curl https://duos-k8s.dsde-dev.broadinstitute.org/config.json)
echo "$JSON" > ../public/config.json
jq '.env = "local"' ../public/config.json > /dev/null
jq '.tag = "dev"' ../public/config.json > /dev/null
jq '.hash = "dev"' ../public/config.json > /dev/null
}
parse_cli_args "$@"
auth_gcloud
write_certs
if [ "$WRITE_ENV" == "true" ]
then
write_env
fi
if [ "$WRITE_CONFIG" == "true" ]
then
write_config
fi