12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
- echo " Docker pull SQLFlow images ..."
15
+ cat << EOF
16
+ This script is safe to re-run, feel free to retry when it exits abnormally.
17
+ Especially when we are waiting for a pod in Kubernetes cluster, it may
18
+ pull image from registry and take a lot of time to startup.
19
+
20
+ EOF
21
+
22
+ if [[ " $( whoami) " != " root" ]]; then
23
+ echo " Please change to root user and retry."
24
+ exit 1
25
+ fi
26
+
27
+ echo " Docker pull dependency images, you can comment this if already have them ..."
16
28
# c.f. https://github.com/sql-machine-learning/sqlflow/blob/develop/.travis.yml
17
29
docker pull sqlflow/sqlflow:jupyter
18
30
docker pull sqlflow/sqlflow:mysql
19
31
docker pull sqlflow/sqlflow:server
20
32
docker pull sqlflow/sqlflow:step
33
+ docker pull argoproj/argoexec:v2.7.7
34
+ docker pull argoproj/argocli:v2.7.7
35
+ docker pull argoproj/workflow-controller:v2.7.7
21
36
echo " Done."
22
37
23
38
# NOTE: According to https://stackoverflow.com/a/16619261/724872,
@@ -29,6 +44,26 @@ source $(dirname $0)/sqlflow/docker/dev/find_fastest_resources.sh
29
44
# Find a way that we do not need to use 'set -e'
30
45
set +e
31
46
47
+ # Execute cmd until given output is present
48
+ # or exit when timeout (50*3s)
49
+ # "$1" is user message
50
+ # "$2" is cmd
51
+ # "$3" is expected output
52
+ function wait_or_exit() {
53
+ echo -n " Waiting for $1 "
54
+ for i in {1..50}; do
55
+ $2 | grep -o -q " $3 "
56
+ if [[ $? -eq 0 ]]; then
57
+ echo " Done"
58
+ return
59
+ fi
60
+ echo -n " ."
61
+ sleep 3
62
+ done
63
+ echo " Fail"
64
+ exit
65
+ }
66
+
32
67
# Use a faster kube image and docker registry
33
68
echo " Start minikube cluster ..."
34
69
minikube_status=$( minikube status | grep " apiserver: Running" )
49
84
fi
50
85
fi
51
86
52
- # Test if a Kubernetes resource is alive
87
+ wait_or_exit " minikube" " minikube status" " apiserver: Running"
88
+
89
+ # Test if a Kubernetes pod is ready
53
90
# "$1" shoulde be namespace id e.g. argo
54
- # "$2" should be resource id e.g. pod/argo-server
55
- function is_resource_alive() {
56
- local type=$( echo " $2 " | cut -d / -f1)
57
- local name=$( echo " $2 " | cut -d / -f2)
58
- if kubectl get -n " $1 " " $2 " | grep -q -o " $name " > /dev/null; then
59
- # make sure relative pod is alive
60
- if kubectl get pod -n " $1 " | grep " $name " | grep " Running" > /dev/null; then
61
- echo " yes"
62
- else
63
- echo " no"
64
- fi
91
+ # "$2" should be pod selector e.g. k8s-app=kubernetes-dashboard
92
+ function is_pod_ready() {
93
+ pod=$( kubectl get pod -n " $1 " -l " $2 " -o name | tail -1)
94
+ if [[ -z " $pod " ]]; then
95
+ echo " no"
96
+ return
97
+ fi
98
+ ready=$( kubectl get -n " $1 " " $pod " -o jsonpath=' {.status.containerStatuses[0].ready}' )
99
+ if [[ " $ready " == " true" ]]; then
100
+ echo " yes"
65
101
else
66
102
echo " no"
67
103
fi
68
104
}
69
105
70
106
echo " Start argo ..."
71
- argo_server_alive=$( is_resource_alive " argo" " service/ argo-server" )
107
+ argo_server_alive=$( is_pod_ready " argo" " app= argo-server" )
72
108
if [[ " $argo_server_alive " == " yes" ]]; then
73
109
echo " Already in running."
74
110
else
75
111
$( dirname $0 ) /sqlflow/scripts/travis/start_argo.sh
76
112
fi
113
+ wait_or_exit " argo" " is_pod_ready argo app=argo-server" " yes"
77
114
78
- echo " Strat Kubernetes Dashboard..."
79
- dashboard_alive=$( is_resource_alive " kubernetes-dashboard" " service/ kubernetes-dashboard" )
115
+ echo " Strat Kubernetes Dashboard ..."
116
+ dashboard_alive=$( is_pod_ready " kubernetes-dashboard" " k8s-app= kubernetes-dashboard" )
80
117
if [[ " $dashboard_alive " == " yes" ]]; then
81
118
echo " Already in running."
82
119
else
83
- nohup minikube dashboard &
120
+ nohup minikube dashboard > /dev/null 2>&1 &
84
121
fi
122
+ wait_or_exit " Kubernetes Dashboard" " is_pod_ready kubernetes-dashboard k8s-app=kubernetes-dashboard" " yes"
85
123
86
124
echo " Strat SQLFlow ..."
87
- sqlflow_alive=$( is_resource_alive " default" " pod/ sqlflow-server" )
125
+ sqlflow_alive=$( is_pod_ready " default" " app= sqlflow-server" )
88
126
if [[ " $sqlflow_alive " == " yes" ]]; then
89
127
echo " Already in running."
90
128
else
91
129
kubectl apply -f sqlflow/doc/run/k8s/install-sqlflow.yaml
92
130
fi
131
+ wait_or_exit " SQLFlow" " is_pod_ready default app=sqlflow-server" " yes"
93
132
94
133
# Kill port exposing if it already exist
95
134
function stop_expose() {
96
- ps -elf | grep " kubectl port-forward" | grep " $1 " | grep " $2 " | awk ' {print $4}' | xargs kill > /dev/null
135
+ ps -elf | grep " kubectl port-forward" | grep " $1 " | grep " $2 " | awk ' {print $4}' | xargs kill > /dev/null 2>&1
97
136
}
98
137
99
138
# Kubernetes port-forwarding
100
139
# "$1" should be namespace
101
140
# "$2" should be resource, e.g. service/argo-server
102
141
# "$3" should be port mapping, e.g. 8000:80
103
142
function expose() {
104
- echo " Stop exposing $3 ..."
105
143
stop_expose " $2 " " $3 "
106
- echo " Detecting service and exposing port ..."
107
- while [[ true ]]; do
108
- local alive=$( is_resource_alive " $1 " " $2 " )
109
- if [[ " $alive " == " yes" ]]; then
110
- break
111
- fi
112
- sleep 1
113
- done
144
+ echo " Exposing port for $2 at $3 ..."
114
145
nohup kubectl port-forward -n $1 --address=' 0.0.0.0' $2 $3 >> port-forward-log 2>&1 &
115
146
}
116
147
@@ -119,18 +150,25 @@ expose kubernetes-dashboard service/kubernetes-dashboard 9000:80
119
150
expose argo service/argo-server 9001:2746
120
151
expose default pod/sqlflow-server 8888:8888
121
152
expose default pod/sqlflow-server 3306:3306
153
+ expose default pod/sqlflow-server 50051:50051
122
154
123
155
jupyter_addr=$( kubectl logs pod/sqlflow-server notebook | grep -o -E " http://127.0.0.1[^?]+\?token=.*" | head -1)
156
+ mysql_addr=" mysql://root:root@tcp($( kubectl get -o jsonpath=' {.status.podIP}' pod/sqlflow-server) )/?maxAllowedPacket=0"
124
157
125
- cat << EOF
158
+ echo -e "
159
+ \033[32m
126
160
Congratulations, SQLFlow playground is up!
127
161
128
162
Access Jupyter Notebook at: $jupyter_addr
129
163
Access Kubernetes Dashboard at: http://localhost:9000
130
164
Access Argo Dashboard at: http://localhost:9001
131
- Access SQLFlow with cli: refer to https://github.com/sql-machine-learning/sqlflow/blob/develop/doc/run/cli.md
165
+ Access SQLFlow with cli: ./sqlflow --datasource= " \" $mysql_addr \" "
132
166
133
167
Stop minikube with: minikube stop
134
- Stop vagrant with: vagrant halt
135
- EOF
168
+ Stop vagrant vm with: vagrant halt
136
169
170
+ [Dangerous]
171
+ Destroy minikube with: minikube delete && rm -rf ~/.minikube
172
+ Destroy vagrant vm with: vagrant destroy
173
+ \033[0m
174
+ "
0 commit comments