forked from cfpb/consumerfinance.gov
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helm-install.sh
executable file
·125 lines (110 loc) · 3.14 KB
/
helm-install.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
# Flags
## Disable ES Chart Tests by default
ES_TEST_OVERRIDE="--set elasticsearch.tests.enabled=false"
if [ ! -z $ES_ENABLE_CHART_TESTS ]; then
ES_TEST_OVERRIDE="--set elasticsearch.tests.enabled=true"
fi
## Option to skip --wait and set timeout
WAIT_TIMEOUT="--timeout=${WAIT_TIMEOUT:-10m0s}"
WAIT_OPT="--wait ${WAIT_TIMEOUT}"
if [ -z $RUN_CHART_TESTS ] && [ ! -z $SKIP_WAIT ]; then
echo "WARNING: Skipping --wait!"
WAIT_OPT=""
fi
## Namespace
NAMESPACE_OPT=""
if [ ! -z $NAMESPACE ]; then
NAMESPACE_OPT="--namespace ${NAMESPACE}"
if [ ! -z $CREATE_NAMESPACE ]; then
NAMESPACE_OPT="${NAMESPACE_OPT} --create-namespace"
fi
fi
## Image Option
if [ -z $IMAGE ]; then
IMAGE=""
else
IMAGE="--set image.repository=${IMAGE}"
fi
## Tag Option
if [ -z $TAG ]; then
TAG=""
else
TAG="--set image.tag=${TAG}"
fi
## Set release name
export RELEASE=${RELEASE:-cfgov}
# Setup
## Get absolute path to helm-install.sh
realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
## Get Project Dir path containing helm-install.sh
export PROJECT_DIR="$(dirname "$(realpath "$0")")"
## Set Default Args
DEFAULT_ARGS="${PROJECT_DIR}/helm/overrides/local-dev.yaml ${PROJECT_DIR}/helm/overrides/dev-vars.yaml ${PROJECT_DIR}/helm/overrides/services.yaml ${PROJECT_DIR}/helm/overrides/required.yaml"
## Source .env, if it exists
if [ -f .env ]; then
source .env
fi
# Prerequisites
## Ensure helm is installed and available via PATH
if ! command -v helm &> /dev/null; then
echo "Helm not found in PATH. Please install helm (brew install helm) or add it to PATH."
exit 1
fi
## Build Dependency Charts
if [ ! -d ./helm/cfgov/charts ]; then
echo "Building dependency charts..."
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add elastic https://helm.elastic.co/
helm repo add opensearch https://opensearch-project.github.io/helm-charts/
helm repo update
helm dependency build ./helm/cfgov
else
if [ -z $SKIP_DEP_UPDATE ]; then
helm dependency update ./helm/cfgov
fi
fi
# Generate Overrides
## Parse overrides list
if [ $# -eq 0 ]; then
ARGS=${DEFAULT_ARGS}
else
ARGS="$@ ${PROJECT_DIR}/helm/overrides/required.yaml"
fi
## Separate --set from files, substitute Environment Variables in override files
tempFiles=()
unset PENDING_SET
OVERRIDES=""
for i in $ARGS; do
if [ ! -z $PENDING_SET ]; then
OVERRIDES="${OVERRIDES} --set ${i}"
unset PENDING_SET
elif [ "${i}" == "--set" ]; then
PENDING_SET=true
else
tempFile=$(mktemp)
envsubst < ${i} > "$tempFile"
OVERRIDES="$OVERRIDES -f $tempFile"
tempFiles+=($tempFile)
fi
done
# Execute
## Install/Upgrade cfgov release
helm upgrade --install ${WAIT_OPT} \
"${RELEASE}" ${NAMESPACE_OPT} ${OVERRIDES} ${IMAGE} ${TAG} \
${PROJECT_DIR}/helm/cfgov
# Add these in for local SSL.
# --set ingress.tls[0].secretName="${RELEASE}-tls" \ # local SSL
# --set ingress.tls[0].hosts[0]="${RELEASE}.localhost" \ # local SSL
## Run chart tests, if RUN_CHART_TESTS is set
if [ ! -z $RUN_CHART_TESTS ]; then
echo "Running chart tests against ${RELEASE}..."
helm test "${RELEASE}"
fi
# Cleanup
## Remove temp files
for i in "${tempFiles[@]}"; do
rm "$i"
done