-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #358 from cliveseldon/goexample
Initial Go Wrapper Example for Seldon Core
- Loading branch information
Showing
42 changed files
with
11,811 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,3 +149,6 @@ eggs/ | |
.eggs/ | ||
*.egg-info/ | ||
./pytest_cache | ||
|
||
#go example | ||
examples/wrappers/go/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM golang | ||
|
||
RUN go get -u google.golang.org/grpc | ||
|
||
RUN go get -u github.com/gorilla/mux | ||
|
||
WORKDIR /go/src/github.com/seldonio/seldon-core/examples/wrappers/go | ||
|
||
COPY . . | ||
|
||
RUN go build -o /server | ||
|
||
ENTRYPOINT [ "sh", "-c", "/server --server_type ${SERVER_TYPE:-grpc}" ] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
|
||
.PHONY: compile_tensorflow_proto | ||
compile_tensorflow_proto: | ||
./generate_tensorflow_proto.sh | ||
|
||
.PHONY: compile_proto | ||
compile_proto: | ||
cp ../../../proto/prediction.proto pkg/api | ||
cd pkg/api && protoc -I. -I${GOPATH}/src/github.com/tensorflow/tensorflow --go_out=paths=source_relative,plugins=grpc:. prediction.proto | ||
rm pkg/api/prediction.proto | ||
|
||
|
||
.PHONY: build_docker | ||
build_docker: | ||
docker build -t seldonio/gomodel:0.1 . | ||
|
||
.PHONY: test_docker_rest | ||
test_docker_rest: | ||
docker run -d --name "gomodel" -p 10000:10000 -e SERVER_TYPE='rest' --rm seldonio/gomodel:0.1 | ||
|
||
.PHONY: test_docker_grpc | ||
test_docker_grpc: | ||
docker run -d --name "gomodel" -p 10000:10000 --rm seldonio/gomodel:0.1 | ||
|
||
.PHONY: clean | ||
clean: | ||
rm server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Example GO Wrapper (ALPHA) | ||
|
||
This is an initial example Go project to illustrate how Go microservices can be built and deployed for management by Seldon Core. | ||
|
||
Follow the [notebook](SeldonGoModel.ipynb) to test. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,237 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Example Go Wrapper for Seldon Core\n", | ||
"\n", | ||
"This notebook goes through the steps to test the Go wrapper. This is presently an example of how to wrap code to run in Go in Seldon. \n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Below shows example code for a REST and gRPC server in Go that handles the Seldon Core microservice API for MODELs." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!pygmentize server.go" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Local Docker Test\n", | ||
"\n", | ||
"For this test we will use the code as is which returns a hard-wired result. For real use you should copy this Go project to build your own components.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!make build_docker" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Run a REST test" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!make test_docker_rest" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!seldon-core-tester contract.json 0.0.0.0 10000 -p" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!docker rm -f gomodel" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Run a gRPC test" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!make test_docker_grpc" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!seldon-core-tester contract.json 0.0.0.0 10000 -p --grpc --tensor" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!docker rm -f gomodel" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Test in Minikube" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!minikube start --memory 4096" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!kubectl create clusterrolebinding kube-system-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:default" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!helm init" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!kubectl rollout status deploy/tiller-deploy -n kube-system" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!helm install ../../../helm-charts/seldon-core-crd --name seldon-core-crd --set usage_metrics.enabled=true\n", | ||
"!helm install ../../../helm-charts/seldon-core --name seldon-core" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!eval $(minikube docker-env) && make build_docker" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!kubectl create -f resources/deployment_example.json" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!kubectl get seldondeployments example-go -o jsonpath='{.status}'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!seldon-core-api-tester contract.json \\\n", | ||
" `minikube ip` `kubectl get svc -l app=seldon-apiserver-container-app -o jsonpath='{.items[0].spec.ports[0].nodePort}'` \\\n", | ||
" --oauth-key oauth-key --oauth-secret oauth-secret -p" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!minikube delete" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"features":[ | ||
{ | ||
"name":"feature", | ||
"dtype":"FLOAT", | ||
"ftype":"continuous", | ||
"range":[1,10] | ||
} | ||
], | ||
"targets":[ | ||
{ | ||
"name":"class", | ||
"dtype":"FLOAT", | ||
"ftype":"continuous", | ||
"range":[0,1] | ||
} | ||
] | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
git clone https://github.com/tensorflow/tensorflow.git | ||
mkdir -p vendor | ||
PROTOC_OPTS='-I tensorflow --go_out=plugins=grpc:vendor' | ||
eval "protoc $PROTOC_OPTS tensorflow/tensorflow/core/framework/*.proto" | ||
eval "protoc $PROTOC_OPTS tensorflow/tensorflow/core/example/*.proto" | ||
eval "protoc $PROTOC_OPTS tensorflow/tensorflow/core/lib/core/*.proto" | ||
eval "protoc $PROTOC_OPTS tensorflow/tensorflow/core/protobuf/{saver,meta_graph}.proto" | ||
|
Oops, something went wrong.