-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·128 lines (105 loc) · 6.11 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/zsh
# **************************************************************************** #
# #
# ::: :::::::: #
# setup.sh :+: :+: :+: #
# +:+ +:+ +:+ #
# By: hyechoi <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/04/05 13:16:14 by hyechoi #+# #+# #
# Updated: 2021/04/05 13:27:18 by hyechoi ### ########.fr #
# #
# **************************************************************************** #
# Welcome!
echo "\n$(tput setaf 7; tput setab 5; tput bold)# ************************ #$(tput sgr 0)"
echo "$(tput setaf 7; tput setab 5; tput bold)# ft_services by hyechoi #$(tput sgr 0)"
echo "$(tput setaf 7; tput setab 5; tput bold)# ************************ #$(tput sgr 0)\n"
# Check dependencies.
echo "$(tput setaf 7; tput setab 4; tput bold)___Check dependencies.___$(tput sgr 0)\n"
## Check if docker is available.
echo "$(tput setaf 7; tput setab 2; tput bold)___Check if Docker is available.___$(tput sgr 0)"
which docker
if [[ "$?" != "0" ]]; then
echo "$(tput setaf 7; tput setab 1; tput bold)Docker is unavailable.$(tput sgr 0)\n"
exit $?
fi
pgrep -x Docker
if [[ "$?" != "0" ]]; then
echo "$(tput setaf 7; tput setab 1; tput bold)Docker for Mac is not running. Run 'open -g -a Docker'.$(tput sgr 0)\n"
exit $?
fi
## Check if virtualbox is available.
echo "$(tput setaf 7; tput setab 2; tput bold)___Check if VirtualBox is available.___$(tput sgr 0)"
which virtualbox
if [[ "$?" != "0" ]]; then
echo "$(tput setaf 7; tput setab 1; tput bold)VirtualBox is unavailable.$(tput sgr 0)\n"
exit $?
fi
## Check if minikube is available.
echo "$(tput setaf 7; tput setab 2; tput bold)___Check if Minikube is available.___$(tput sgr 0)"
which minikube
if [[ "$?" != "0" ]]; then
echo "$(tput setaf 7; tput setab 1; tput bold)Minikube is unavailable.$(tput sgr 0)\n"
exit $?
fi
# minikube delte before minikube start.
echo "\n$(tput setaf 7; tput setab 4; tput bold)___Delete minikube setup before start.___$(tput sgr 0)"
minikube delete
minikube delete --all
# Run minikube.
echo "\n$(tput setaf 7; tput setab 4; tput bold)___Run minikube start with VirtualBox vm driver.___$(tput sgr 0)"
export MINIKUBE_HOME=~/goinfre
echo "\n$(tput setaf 7; tput setab 2; tput bold)___Set minikube config memory.___$(tput sgr 0)"
minikube config set memory 4096
echo "\n$(tput setaf 7; tput setab 2; tput bold)___Set minikube config disk-size.___$(tput sgr 0)"
minikube config set disk-size 5120
minikube start --wait=false --vm-driver=virtualbox
if [[ "$?" != "0" ]]; then
echo "$(tput setaf 7; tput setab 1; tput bold)Can't 'minikube start'.$(tput sgr 0)\n"
exit $?
fi
# Install metallb.
echo "\n$(tput setaf 7; tput setab 4; tput bold)___Install metallb.___$(tput sgr 0)"
minikube addons enable metallb
MINIKUBE_IP=$(minikube ip)
sed "s/MINIKUBE_IP/$MINIKUBE_IP/g" ./srcs/metallb/manifests/configmap.yaml > ./configmap_sed.yaml
kubectl apply -f ./configmap_sed.yaml
rm -f ./configmap_sed.yaml
# Link minikube to local docker.
echo "\n$(tput setaf 7; tput setab 4; tput bold)___Link minikube to local docker.___$(tput sgr 0)"
eval $(minikube docker-env)
# Build container images in need.
ALPINE_APK_MIRROR_REPO="http://alpine.cs.nctu.edu.tw/"
echo "\n$(tput setaf 7; tput setab 4; tput bold)___Set alpine apk mirror repo.___$(tput sgr 0)"
echo "$ALPINE_APK_MIRROR_REPO"
echo "\n$(tput setaf 7; tput setab 4; tput bold)___Build container images in need.___$(tput sgr 0)"
echo "$(tput setaf 7; tput setab 2; tput bold)___Build ft-influxdb.___$(tput sgr 0)"
docker build ./srcs/influxdb/ -t alpine:ft-influxdb --build-arg minikube_ip=$MINIKUBE_IP --build-arg alpine_apk_mirror_repo=$ALPINE_APK_MIRROR_REPO
echo "$(tput setaf 7; tput setab 2; tput bold)___Build ft-grafana.___$(tput sgr 0)"
docker build ./srcs/grafana/ -t alpine:ft-grafana --build-arg minikube_ip=$MINIKUBE_IP --build-arg alpine_apk_mirror_repo=$ALPINE_APK_MIRROR_REPO
echo "$(tput setaf 7; tput setab 2; tput bold)___Build ft-nginx.___$(tput sgr 0)"
docker build ./srcs/nginx/ -t alpine:ft-nginx --build-arg minikube_ip=$MINIKUBE_IP --build-arg alpine_apk_mirror_repo=$ALPINE_APK_MIRROR_REPO
echo "$(tput setaf 7; tput setab 2; tput bold)___Build ft-mysql.___$(tput sgr 0)"
docker build ./srcs/mysql/ -t alpine:ft-mysql --build-arg alpine_apk_mirror_repo=$ALPINE_APK_MIRROR_REPO
echo "$(tput setaf 7; tput setab 2; tput bold)___Build ft-phpmyadmin.___$(tput sgr 0)"
docker build ./srcs/phpmyadmin/ -t alpine:ft-phpmyadmin --build-arg alpine_apk_mirror_repo=$ALPINE_APK_MIRROR_REPO
echo "$(tput setaf 7; tput setab 2; tput bold)___Build ft-wordpress.___$(tput sgr 0)"
docker build ./srcs/wordpress/ -t alpine:ft-wordpress --build-arg minikube_ip=$MINIKUBE_IP --build-arg alpine_apk_mirror_repo=$ALPINE_APK_MIRROR_REPO
echo "$(tput setaf 7; tput setab 2; tput bold)___Build ft-ftps.___$(tput sgr 0)"
docker build ./srcs/ftps/ -t alpine:ft-ftps --build-arg minikube_ip=$MINIKUBE_IP --build-arg alpine_apk_mirror_repo=$ALPINE_APK_MIRROR_REPO
# Apply container images to kube.
echo "\n$(tput setaf 7; tput setab 4; tput bold)___Apply container images to kube.___$(tput sgr 0)"
kubectl apply -f ./srcs/secrets.yaml
kubectl apply -f ./srcs/influxdb/manifest.yaml
kubectl apply -f ./srcs/grafana/manifest.yaml
kubectl apply -f ./srcs/mysql/manifest.yaml
kubectl apply -f ./srcs/nginx/manifest.yaml
kubectl apply -f ./srcs/phpmyadmin/manifest.yaml
kubectl apply -f ./srcs/ftps/manifest.yaml
kubectl apply -f ./srcs/wordpress/manifest.yaml
# Enable dashboard, metrics-server.
echo "\n$(tput setaf 7; tput setab 4; tput bold)___Enable dashboard, metrics-server.___$(tput sgr 0)"
minikube addons enable dashboard
minikube addons enable metrics-server
echo "\n$(tput setaf 7; tput setab 4; tput bold)___Run dashboard on background.___$(tput sgr 0)"
minikube dashboard &