-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeploy.sh
74 lines (63 loc) · 2.22 KB
/
deploy.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
#!/usr/bin/env bash
set -euo pipefail
# catch exit 1 (which is a special case in grep meaning 'no matches') so that we can use pipefail
_grep() { grep "$@" || test $? = 1; }
# First Install any required helm plugins
if [ -n "${PLUGINS_LIST}" ]; then
plugins=${PLUGINS_LIST//,/ }
for plugin in $plugins
do
echo "installing helm plugin: [$plugin]"
helm plugin install $plugin
done
fi
helm plugin list
echo "Logging into kubernetes cluster $CLUSTER_NAME"
if [ -n "$CLUSTER_ROLE_ARN" ]; then
aws eks \
--region ${AWS_REGION} \
update-kubeconfig --name ${CLUSTER_NAME} \
--role-arn=${CLUSTER_ROLE_ARN}
else
aws eks \
--region ${AWS_REGION} \
update-kubeconfig --name ${CLUSTER_NAME}
fi
# Check if namespace exists and create it if it doesn't.
KUBE_NAMESPACE_EXISTS=$(kubectl get namespaces | _grep ^${DEPLOY_NAMESPACE})
if [ -z "${KUBE_NAMESPACE_EXISTS}" ]; then
echo "The namespace ${DEPLOY_NAMESPACE} does not exists. Creating..."
kubectl create namespace "${DEPLOY_NAMESPACE}"
else
echo "The namespace ${DEPLOY_NAMESPACE} exists. Skipping creation..."
fi
# Checking to see if a repo URL is in the path, if so add it or update.
if [ -n "${HELM_REPOSITORY}" ]; then
HELM_CHART_NAME="${DEPLOY_CHART_PATH%/*}"
HELM_REPOS=$(helm repo list || true)
CHART_REPO_EXISTS=$(echo $HELM_REPOS | _grep ^${HELM_CHART_NAME})
if [ -z "${CHART_REPO_EXISTS}" ]; then
echo "Adding repo ${HELM_CHART_NAME} (${HELM_REPOSITORY})"
helm repo add "${HELM_CHART_NAME}" "${HELM_REPOSITORY}"
else
echo "Updating repo ${HELM_CHART_NAME}"
helm repo update "${HELM_CHART_NAME}"
fi
fi
# Upgrade or install the chart. This does it all.
HELM_COMMAND="helm upgrade --install --timeout ${TIMEOUT}"
# Set paramaters
for config_file in ${DEPLOY_CONFIG_FILES//,/ }
do
HELM_COMMAND="${HELM_COMMAND} -f ${config_file}"
done
if [ -n "$DEPLOY_NAMESPACE" ]; then
HELM_COMMAND="${HELM_COMMAND} -n ${DEPLOY_NAMESPACE}"
fi
if [ -n "$DEPLOY_VALUES" ]; then
HELM_COMMAND="${HELM_COMMAND} --set ${DEPLOY_VALUES}"
fi
# Execute Commands
HELM_COMMAND="${HELM_COMMAND} ${DEPLOY_NAME} ${DEPLOY_CHART_PATH}"
echo "Executing: ${HELM_COMMAND}"
${HELM_COMMAND}