-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy
executable file
·91 lines (74 loc) · 2.26 KB
/
deploy
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
#!/bin/bash
# Deploys a unikorn component. Will only work if the chart version
# has been bumped, otherwise you will need to manually restart all
# the pods with kubectl.
#
# NOTE: must be run from the component's root directory.
# Get the environemnt.
ENVIRONMENT="local"
# A prefix to add to namespaces to avoid clashes
NAMESPACE_PREFIX="unikorn"
# A production deployment will use public helm charts.
PRODUCTION=""
# Template renders the chart to stdout, very useful if you are piping
# the output into kubectl diff...
TEMPLATE=""
while getopts "e:n:pt" opt; do
case "${opt}" in
e)
ENVIRONMENT=${OPTARG}
;;
n)
NAMESPACE_PREFIX=${OPTARG}
;;
p)
PRODUCTION="true"
;;
t)
TEMPLATE="true"
;;
*)
echo "Unexpected flag -${opt}"
exit 1
esac
done
# Figure out some repo constants.
GIT_REPO=""
if [[ -f go.mod ]]; then
GIT_REPO="$(head -n1 go.mod | awk '{print $2}')"
elif [[ -f package.json ]]; then
GIT_REPO="$(jq -r .repository.url package.json | sed -e 's,https://,,')"
fi
GIT_ORG_NAME=$(echo -n "${GIT_REPO}" | cut -d '/' -f 2)
GIT_REPO_NAME=$(echo -n "${GIT_REPO}" | cut -d '/' -f 3)
HELM_REPO="https://${GIT_ORG_NAME}.github.io/${GIT_REPO_NAME}"
HELM_CHART_DIR="charts/${GIT_REPO_NAME}"
HELM_CHART=$(yq .name "${HELM_CHART_DIR}/Chart.yaml")
HELM_CRD_DIR="${HELM_CHART_DIR}/crds"
# Define some constants for Helm
NAMESPACE="${NAMESPACE_PREFIX}-${GIT_REPO_NAME}"
ARGS=()
# Add an values files you need.
GLOBAL_VALUES_FILE="${HOME}/.config/unikorn/${ENVIRONMENT}/global.yaml"
if [[ -f ${GLOBAL_VALUES_FILE} ]]; then
ARGS+=("-f" "${GLOBAL_VALUES_FILE}")
fi
VALUES_FILE="${HOME}/.config/unikorn/${ENVIRONMENT}/${GIT_REPO_NAME}.yaml"
if [[ -f ${VALUES_FILE} ]]; then
ARGS+=("-f" "${VALUES_FILE}")
fi
COMMAND=(upgrade --install --create-namespace)
# If we are doing a non-template run, update the CRDs as helm doesn't do this.
if [[ -z ${TEMPLATE} ]]; then
if [[ -d ${HELM_CRD_DIR} ]]; then
kubectl apply -f "${HELM_CRD_DIR}"
fi
else
COMMAND=(template --no-hooks --skip-tests)
fi
if [[ -z ${PRODUCTION} ]]; then
# Deploy the actual chart.
helm "${COMMAND[@]}" -n "${NAMESPACE}" "${GIT_REPO_NAME}" "${HELM_CHART_DIR}" "${ARGS[@]}"
else
helm "${COMMAND[@]}" -n "${NAMESPACE}" "${GIT_REPO_NAME}" "${HELM_CHART}" --repo "${HELM_REPO}" "${ARGS[@]}"
fi