-
Notifications
You must be signed in to change notification settings - Fork 0
/
devkit.sh
executable file
·128 lines (105 loc) · 3.18 KB
/
devkit.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
126
127
128
#!/bin/bash
K8S_CONTEXT_NAME="polyflix-devkit"
CLUSTER_PROVIDER=""
source lib/libk3d.sh
source lib/libopenstack.sh
source lib/libhelper.sh
function clean_exit() {
echo "$@"
exit 1
}
function check_requirements() {
for requirement in "${REQUIREMENTS[@]}"; do
which "$requirement" > /dev/null || clean_exit "[ERROR] Missing requirement. Please install '$requirement' and try re-run the script."
done
}
function get_hosts() {
local ip=${1:-127.0.0.1}
echo "$ip polyflix.local console.minio.polyflix.local kibana.polyflix.local minio keycloak"
}
function install() {
local kubeconfig="$(pwd)/outputs/k8s.yml"
local kubectl_args="--context=$K8S_CONTEXT_NAME --kubeconfig=$kubeconfig"
kubectl $kubectl_args create configmap provisioning --from-file=provisioning.sh=./scripts/provisioning.sh || true
kubectl $kubectl_args create configmap keycloak-realm --from-file=realm.json=./config/keycloak-realm.json || true
# Install Elastic Cloud Kit operator
kubectl $kubectl_args create -f https://download.elastic.co/downloads/eck/2.6.1/crds.yaml || true
kubectl $kubectl_args apply -f https://download.elastic.co/downloads/eck/2.6.1/operator.yaml || true
kubectl $kubectl_args apply -f ./k8s/manifests/eck || true
kubectl $kubectl_args apply -f ./k8s/manifests/postgres || true
# Custom needed tests
kubectl $kubectl_args apply -f ./k8s/manifests/keto/
# We need to instal Polyflix before running the provisioning step
KUBECONFIG=$kubeconfig helmfile --kube-context="$K8S_CONTEXT_NAME" --file ./k8s/helmfile.yaml apply
kubectl $kubectl_args apply -f ./k8s/manifests/polyflix
}
function start() {
check_requirements
# start_k3d
install
inject_hosts
}
function stop() {
stop_k3d
clean_hosts
}
function sub_default(){
local progname=`basename "$0"`
echo "This script will allow you to manage Polyflix development environment."
echo "Usage: $progname <command>"
echo "Commands:"
echo " start <provider> Start a new devkit environment on the given provider."
print_generic_options
}
sub_start() {
local ip=""
if [[ "$#" == 0 ]]; then
sub_default
exit 1
fi
mkdir -p outputs
CLUSTER_PROVIDER=${1:-}
case $CLUSTER_PROVIDER in
openstack)
os_start_cluster
os_get_kubeconfig outputs/k8s.yml "$K8S_CONTEXT_NAME"
ip=$(os_get_cluster_address)
;;
local)
k3d_start_cluster || true
k3d_get_kubeconfig outputs/k8s.yml "$K8S_CONTEXT_NAME"
ip="127.0.0.1"
;;
*)
echo "[ERROR]: Invalid provider given '${CLUSTER_PROVIDER}'. Valid providers are: local, openstack"
exit 1
;;
esac
install
echo $(get_hosts "$ip") | sudo tee -a /etc/hosts
}
sub_stop() {
local ip=""
if [[ "$#" == 0 ]]; then
sub_default
exit 1
fi
CLUSTER_PROVIDER=${1:-}
case $CLUSTER_PROVIDER in
openstack)
ip=$(os_get_cluster_address)
os_stop_cluster
;;
local)
ip="127.0.0.1"
k3d_stop_cluster
;;
*)
echo "[ERROR]: Invalid provider given '${CLUSTER_PROVIDER}'. Valid providers are: local, openstack"
exit 1
;;
esac
sudo sed -i '' "s/$(get_hosts $ip)//g" /etc/hosts
rm -rf outputs
}
parse_and_execute $@