-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.sh
More file actions
130 lines (111 loc) · 3.8 KB
/
common.sh
File metadata and controls
130 lines (111 loc) · 3.8 KB
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
129
130
#!/usr/bin/env bash
image_version="0.0.10"
project_name=`python scripts/lookup_value_from_json google_service_key.json project_id`
repo_name="gcr.io/${project_name}/easy_ml"
user_name="$( echo $USER | tr '[:upper:]' '[:lower:]')"
cluster_name="${user_name}-ml-cluster"
# This zone is set by default.
zone=`gcloud config list |grep '^zone'|cut -d '=' -f 2|tr -d '[:space:]'`
remote_image=`gcloud beta container images list-tags ${repo_name} | grep ${image_version} | tr -d '[:space:]'`
echoRun() {
echo "${yellow}> $1${reset}"
eval $1
}
patch() {
bumpversion patch --allow-dirty
}
build() {
docker build -t ${repo_name} .
}
push() {
if [ -z ${remote_image} ]
then
echo "building and pushing image version ${image_version}"
docker build -t ${repo_name}:${image_version} .
gcloud docker -- push ${repo_name}:${image_version}
else
echo "Current version tag already in container repository. If you've made changes, please bump the version with 'sh deployment.sh patch'"
exit 1
fi
}
make_disk() {
disk_name=${user_name}-notebook-persistent-disk
if gcloud compute disks list | grep -q "^${disk_name}[[:space:]]"
then
echo "Persistent disk ${disk_name} found"
else
echo "Persistent disk ${disk_name} not found, creating"
gcloud compute disks create --size=500GB --zone=${zone} ${disk_name}
fi
}
make_cluster() {
if gcloud container clusters list | grep -q "^${cluster_name}[[:space:]]"
then
echo "Kubernetes Cluster ${cluster_name} found"
else
echo "Kubernetes Cluster ${cluster_name} not found, creating"
gcloud container clusters create ${cluster_name} --zone=${zone} --num-nodes=1 --machine-type=n1-standard-4
fi
gcloud container clusters get-credentials ${cluster_name}
}
make_pod() {
if kubectl get pod | grep -q jupyter-server-pod
then
echo ""
cat jupyter-server.yaml | sed "s#NOTEBOOK_IMAGE#${repo_name}:${image_version}#" \
| sed "s/DISK_NAME/${disk_name}/" \
| kubectl delete -f -
fi
cat jupyter-server.yaml | sed "s#NOTEBOOK_IMAGE#${repo_name}:${image_version}#" \
| sed "s/DISK_NAME/${disk_name}/" \
| kubectl create -f -
}
deploy() {
if [ -z ${remote_image} ]
then
echo "Current version tag not yet in container repository. Please push with 'sh deployment.sh push'"
exit 1
fi
make_disk
make_cluster
make_pod
}
tear_down() {
if gcloud container clusters list | grep -q "^${cluster_name}[[:space:]]"
then
echo "Deleting cluster ${cluster_name}"
gcloud container clusters delete ${cluster_name}
else
echo "Cluster ${cluster_name} not found"
exit 1
fi
}
port_forward() {
pod_name=`kubectl get pod -o=custom-columns=NAME:.metadata.name | grep jupyter-server-pod`
if [ -z ${pod_name} ]
then
echo "No running jupyter pod found. Please deploy one first"
exit 1
fi
status=`kubectl get pod ${pod_name} -o=custom-columns=NAME:.status.phase --no-headers`
while [ ${status} = "ContainerCreating" ] || [ ${status} = "Pending" ]
do
sleep 2
printf "."
status=`kubectl get pod ${pod_name} -o=custom-columns=NAME:.status.phase --no-headers`
done
if [ ${status} != "Running" ]
then
echo "Pod status is ${status}, aborting"
exit 1
fi
echo "Notebook running at http://localhost:8889"
kubectl port-forward ${pod_name} 8889:8888
}
run_local_notebook() {
echo "starting local notebook at `docker-machine ls | grep default | \
awk '{print $5}' | \
awk '{ gsub("tcp://", "http://") ; system( "echo " $0)}' | \
awk '{ gsub(":2376", ":8888") ; system("echo " $0)}'`"
docker run -it -p 8888:8888 ${repo_name}:${image_version}
}