Simple gRPC based echoserver, which returns a string containing whatever the client sends in the request.
This repo contains a Makefile and a Dockerfile, all the dependencies are added to the Dockerfile.
To build gRPC server run the following command
make build
This command will generate a Docker image called echoserver, this image contains both the server and the test client library to test the server.
To run the echoserver in a container use the following commands. Name the Docker container
server
, this way when the client container is started it can run the network namespace
as server container.
docker run -d --rm --name=server echoserver /bin/server
docker run --rm --net=container:server echoserver /bin/client -msg=hi
To run the complete test suite including unit tests and integrations tests
make test
root@ubuntu:/# docker run -ti --rm --name=server echoserver /bin/server
2019/06/03 04:45:40 Receive message hi
root@ubuntu:/# docker run --rm --net=container:server echoserver /bin/client -msg=hi
2019/06/03 04:45:40 Response from server: hi
root@ubuntu:/# docker run -ti --rm --name=server echoserver /bin/server -help
Usage of /bin/server:
-port int
gRPC server port (default 8080)
root@ubuntu:/# docker run --rm --net=container:server echoserver /bin/client -help
Usage of /bin/client:
-msg string
Message to be sent to the server (default "hello")
-port int
gRPC server port (default 8080)
Update the server API in api/api.proto file, this will generate the server and client gRPC libraries
apt-get install unzip && \
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.8.0/protoc-3.8.0-linux-x86_64.zip && \
unzip protoc-3.8.0-linux-x86_64.zip -d /tmp/ && mv /tmp/bin/protoc /usr/bin/
go get -u github.com/golang/protobuf/protoc-gen-go
Note: Make sure $PATH on the host contains $GOPATH/bin, else do export PATH=$PATH:$GOPATH/bin/
Once, you have both protoc and protoc-gen-go installed, run the following command to generate server and client stub package in api/api.pb.go
protoc -I api/ -I${GOPATH}/src --go_out=plugins=grpc:api api/api.proto