-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.sh
executable file
·128 lines (94 loc) · 2.91 KB
/
setup.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
START=$(date +%s);
start_time=$(date)
minikube delete
check_brew()
{
which -s brew
if [[ $? != 0 ]] ; then
# Install Homebrew
printf "\033[1;32mInstall brew\n\033[0m"
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
}
check_hyperkit()
{
brew list hyperkit || brew install hyperkit
}
check_minikube()
{
which minikube
if [[ $? != 0 ]] ; then
# Install Homebrew
printf "\033[1;32mInstall minikube\n\033[0m"
brew install minikube
fi
}
build_image()
{
docker build srcs/$1 -t hsaadaou/$1 || build_image $1
}
build_and_deploy()
{
printf "\033[1;34m⌛️ Current Step $3\n\033[0m"
printf "\033[1;32m$2 Build \e[4m$1\n\033[0m"
build_image $1
clear
printf "\033[1;32m$2 Deploy \e[4m$1\n\033[0m"
kubectl create -f srcs/$1.yaml
kubectl get pods
}
deploy_metallb()
{
printf "\033[1;32m🚏 Deploy \e[4mMetallb\n\033[0m"
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.5/manifests/namespace.yaml
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.5/manifests/metallb.yaml
kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
sed -e 's/node_ip/'$1'/g' srcs/metallb/metallb.yaml | kubectl create -f -
}
run_minikube()
{
OS=$(uname -s)
check_minikube
if [ $OS = Darwin ]
then
check_brew
minikube start --driver=hyperkit
else
minikube start
fi
minikube kubectl -- get pods -A
}
run_minikube
node_ip=$(kubectl get node -o=custom-columns='DATA:status.addresses[0].address' | sed -n 2p)
deploy_metallb $node_ip
eval $(minikube docker-env)
clear
kubectl create -f srcs/dashboard.yaml >> /dev/null
kubectl create -f srcs/volumes.yaml >> /dev/null
kubectl create -f srcs/secrets.yaml >> /dev/null
printf "🏗\033[1;32m Build \e[4mAlpine base image\n\033[0m"
build_image alpine_base
clear
build_and_deploy "mysql" "🧠" "1/7"
build_and_deploy "influxdb" "💾" "2/7"
build_and_deploy "grafana" "📈" "3/7"
build_and_deploy "phpmyadmin" "📝" "4/7"
build_and_deploy "wordpress" "🛒" "5/7"
build_and_deploy "ftps" "🗂" "6/7"
build_and_deploy "nginx" "🚦" "7/7"
clear
eval $(minikube docker-env -u)
kubectl get pods
printf "\033[1;32m\e[4mAdmin dashboard token :\n\033[0m"
kubectl get secret -n kubernetes-dashboard $(kubectl get serviceaccount admin-user -n kubernetes-dashboard -o jsonpath="{.secrets[0].name}") -o jsonpath="{.data.token}" | base64 --decode
printf "\033[1;32m\n\nCopy the token and past it here https://$node_ip:8080\n\033[0m"
end_time=$(date)
printf "\033[1;34m\nStarted at: \e[4m$start_time\n\033[0m"
printf "\033[1;34mStarted at: \e[4m$end_time\n\033[0m"
END=$(date +%s);
printf "\033[1;34mElapsed time: "
echo $((END-START)) | awk '{printf "%d:%02d:%02d", $1/3600, ($1/60)%60, $1%60}'
printf "\n\033[0m"
printf "\033[1;32m🤩 Everything is up :\n\033[0m"
echo https://$node_ip