Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Go Wrapper Example for Seldon Core #358

Merged
merged 2 commits into from
Jan 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,6 @@ eggs/
.eggs/
*.egg-info/
./pytest_cache

#go example
examples/wrappers/go/.idea
14 changes: 14 additions & 0 deletions examples/wrappers/go/Dockerfile
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}" ]

28 changes: 28 additions & 0 deletions examples/wrappers/go/Makefile
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
6 changes: 6 additions & 0 deletions examples/wrappers/go/README.md
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.

237 changes: 237 additions & 0 deletions examples/wrappers/go/SeldonGoModel.ipynb
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
}
20 changes: 20 additions & 0 deletions examples/wrappers/go/contract.json
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]
}
]
}


8 changes: 8 additions & 0 deletions examples/wrappers/go/generate_tensorflow_proto.sh
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"

Loading