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