-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·82 lines (72 loc) · 2.59 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
75
76
77
78
79
80
81
82
#!/bin/bash
set -euo pipefail
if [[ $# -lt 1 || $# -gt 2 || "$1" = "--help" ]]; then
echo "usage: $0 REGISTRY_HOSTNAME [KUBECTL_CONTEXT]"
exit 1
fi
image_registry="keldaio"
blimp_version="0.15.1"
registry_hostname="$1"
kubectl_context=""
if [[ $# -eq 2 ]]; then
kubectl_context="$2"
fi
function _kubectl() {
if [[ -n "$kubectl_context" ]]; then
kubectl --context "$kubectl_context" "$@"
else
kubectl "$@"
fi
}
templates=()
function template() {
file="$1"
shift
sed "$@" "${file}.tmpl" > "${file}"
templates+=("$file")
}
function cleanup_templates() {
for file in "${templates[@]}"; do
rm "$file"
done
}
trap cleanup_templates EXIT
cd "$(dirname "$0")"
## Manager
# Make sure the namespace exists.
_kubectl apply -f manager/0_namespace.yaml
if _kubectl get secret -n manager manager-certs 2>/dev/null > /dev/null; then
echo "Using manager certs already present in cluster."
elif [[ -f secrets/manager.crt.pem && -f secrets/manager.key.pem ]]; then
_kubectl create secret -n manager generic manager-certs \
--from-file=cert.pem=secrets/manager.crt.pem,key.pem=secrets/manager.key.pem
else
echo "Manager certs not found. Please generate secrets (./gen-secrets.sh) and try again."
exit 1
fi
if _kubectl get secret -n manager cluster-auth 2>/dev/null > /dev/null; then
echo "Using cluster auth token already present in cluster."
elif [[ -f secrets/cluster-auth-token ]]; then
_kubectl create secret -n manager generic cluster-auth \
--from-file=token=secrets/cluster-auth-token
else
echo "Cluster auth token not found. Please generate secrets (./gen-secrets.sh) and try again."
exit 1
fi
manager_sed="s|<CLUSTER_MANAGER_IMAGE>|${image_registry}/blimp-cluster-controller:${blimp_version}|;s|<DOCKER_REPO>|${image_registry}|;s|<REGISTRY_HOSTNAME>|${registry_hostname}|;s|<USE_NODE_PORT>|${USE_NODE_PORT:-false}|;s|<LINK_PROXY_BASE_HOSTNAME>|${LINK_PROXY_BASE_HOSTNAME:-invalid}|"
if _kubectl get secret -n manager license 2>/dev/null > /dev/null; then
echo "Using installed license."
template manager/manager-deployment-licensed.yaml "${manager_sed}"
else
template manager/manager-deployment.yaml "${manager_sed}"
fi
_kubectl apply -f manager/
## Registry
# Make sure the registry exists.
_kubectl apply -f registry/0_namespace.yaml
if ! _kubectl get secret -n registry cluster-auth 2>/dev/null > /dev/null; then
_kubectl create secret -n registry generic cluster-auth \
--from-file=token=secrets/cluster-auth-token
fi
template registry/registry-deployment.yaml "s|<REGISTRY_HOSTNAME>|${registry_hostname}|;s|<DOCKER_AUTH_IMAGE>|${image_registry}/blimp-docker-auth:${blimp_version}|"
_kubectl apply -f registry/