Skip to content

Commit ab30e52

Browse files
committed
polish start.bash
1 parent 57394fd commit ab30e52

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

provision.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ apt-get update
1313

1414
echo "Installing Docker ..."
1515
# c.f. https://dockr.ly/3cExcay
16-
if ! which docker > /dev/null; then
16+
if which docker > /dev/null; then
1717
echo "Docker had been installed. Skip."
1818
else
1919
best_install_url=$(find_fastest_docker_url)

start.bash

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
if [[ "$(whoami)" != "root" ]]; then
15+
echo "Please change to root user and retry."
16+
exit
17+
fi
1418

15-
echo "Docker pull SQLFlow images ..."
19+
echo "Docker pull dependency images ..."
1620
# c.f. https://github.com/sql-machine-learning/sqlflow/blob/develop/.travis.yml
1721
docker pull sqlflow/sqlflow:jupyter
1822
docker pull sqlflow/sqlflow:mysql
1923
docker pull sqlflow/sqlflow:server
2024
docker pull sqlflow/sqlflow:step
25+
docker pull argoproj/argoexec:v2.7.7
2126
echo "Done."
2227

2328
# NOTE: According to https://stackoverflow.com/a/16619261/724872,
@@ -29,6 +34,23 @@ source $(dirname $0)/sqlflow/docker/dev/find_fastest_resources.sh
2934
# Find a way that we do not need to use 'set -e'
3035
set +e
3136

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+
3254
# Use a faster kube image and docker registry
3355
echo "Start minikube cluster ..."
3456
minikube_status=$(minikube status | grep "apiserver: Running")
@@ -49,15 +71,17 @@ else
4971
fi
5072
fi
5173

74+
wait_until "minikube" "minikube status" "apiserver: Running"
75+
5276
# Test if a Kubernetes resource is alive
5377
# "$1" shoulde be namespace id e.g. argo
5478
# "$2" should be resource id e.g. pod/argo-server
5579
function is_resource_alive() {
5680
local type=$(echo "$2" | cut -d / -f1)
5781
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
5983
# 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
6185
echo "yes"
6286
else
6387
echo "no"
@@ -74,14 +98,16 @@ if [[ "$argo_server_alive" == "yes" ]]; then
7498
else
7599
$(dirname $0)/sqlflow/scripts/travis/start_argo.sh
76100
fi
101+
wait_until "argo" "is_resource_alive argo service/argo-server" "yes"
77102

78-
echo "Strat Kubernetes Dashboard..."
103+
echo "Strat Kubernetes Dashboard ..."
79104
dashboard_alive=$(is_resource_alive "kubernetes-dashboard" "service/kubernetes-dashboard")
80105
if [[ "$dashboard_alive" == "yes" ]]; then
81106
echo "Already in running."
82107
else
83108
nohup minikube dashboard &
84109
fi
110+
wait_until "Kubernetes Dashboard" "is_resource_alive kubernetes-dashboard service/kubernetes-dashboard" "yes"
85111

86112
echo "Strat SQLFlow ..."
87113
sqlflow_alive=$(is_resource_alive "default" "pod/sqlflow-server")
@@ -90,27 +116,20 @@ if [[ "$sqlflow_alive" == "yes" ]]; then
90116
else
91117
kubectl apply -f sqlflow/doc/run/k8s/install-sqlflow.yaml
92118
fi
119+
wait_until "SQLFlow" "is_resource_alive default pod/sqlflow-server" "yes"
93120

94121
# Kill port exposing if it already exist
95122
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
97124
}
98125

99126
# Kubernetes port-forwarding
100127
# "$1" should be namespace
101128
# "$2" should be resource, e.g. service/argo-server
102129
# "$3" should be port mapping, e.g. 8000:80
103130
function expose() {
104-
echo "Stop exposing $3..."
105131
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 ..."
114133
nohup kubectl port-forward -n $1 --address='0.0.0.0' $2 $3 >>port-forward-log 2>&1 &
115134
}
116135

@@ -119,18 +138,25 @@ expose kubernetes-dashboard service/kubernetes-dashboard 9000:80
119138
expose argo service/argo-server 9001:2746
120139
expose default pod/sqlflow-server 8888:8888
121140
expose default pod/sqlflow-server 3306:3306
141+
expose default pod/sqlflow-server 50051:50051
122142

123143
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"
124145

125-
cat <<EOF
146+
echo -e "
147+
\033[32m
126148
Congratulations, SQLFlow playground is up!
127149
128150
Access Jupyter Notebook at: $jupyter_addr
129151
Access Kubernetes Dashboard at: http://localhost:9000
130152
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\""
132154
133155
Stop minikube with: minikube stop
134-
Stop vagrant with: vagrant halt
135-
EOF
156+
Stop vagrant vm with: vagrant halt
136157
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

Comments
 (0)