Skip to content

Commit

Permalink
add gRPC service
Browse files Browse the repository at this point in the history
  • Loading branch information
philipsahli committed Jan 6, 2019
1 parent f3454cd commit d112f59
Show file tree
Hide file tree
Showing 13 changed files with 524 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ typings/
# gontador
.vscode
vendor
main
gontador
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN chmod +x /usr/bin/dep
# Copy the code from the host and compile it
WORKDIR $GOPATH/src/github.com/philipsahli/gontador/
COPY Gopkg.toml Gopkg.lock ./
RUN dep ensure --vendor-only
RUN dep ensure --vendor-only -v
COPY . ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o /app github.com/philipsahli/gontador/src

Expand Down
115 changes: 115 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# name = "github.com/user/project"
# version = "1.0.0"
#

# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
Expand All @@ -24,6 +25,9 @@
# go-tests = true
# unused-packages = true

[[constraint]]
branch = "master"
name = "github.com/golang/protobuf"

[[constraint]]
branch = "master"
Expand Down
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# contador

A 12-factor counter microservice

## Services
Exposes an HTTP-API and a gRPC Interface.

## Dependant services

### Telegraf
**Telegraf**

Run somewhere
Run somewhere a simple tcp listener to mock a telegraf daemon.

nc -l 2003

### Redis
**Redis**

Run somewhere
Run somewhere a docker container with an unsecured redis daemon.

docker run --name gontador-redis -p 6379:6379 -d redis

Expand All @@ -23,8 +26,20 @@ Run somewhere

### HTTP Interface

A HTTP/1.1 GET request to `/counter` increments the counter by 1 and returns the new counter.

curl http://localhost:3000/counter

### gRPC Service

Gonsumidor increments the counter by 1 and prints out the counter every 2 seconds. Communication over gRPC to the service on port `3001`.

git clone https://github.com/philipsahli/gonsumidor.git
cd gonsumidor && go build -o gonsumidor main.go
go build -o gonsumidor main.go

See https://github.com/philipsahli/gonsumidor/blob/master/README.md

## Test on Openshift

bash -xe deploy/deploy.sh
Expand All @@ -37,3 +52,11 @@ Run somewhere

oc delete all -l app=gontador
oc delete template gontador-template

## Generate grpc service

PROTOC_ZIP=protoc-3.3.0-osx-x86_64.zip\ncurl -OL https://github.com/google/protobuf/releases/download/v3.3.0/$PROTOC_ZIP\nsudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc\nrm -f $PROTOC_ZIP
go get -u github.com/golang/protobuf/protoc-gen-go

protoc -I service/ service/gontador.proto --go_out=plugins=grpc:service

2 changes: 1 addition & 1 deletion deploy/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -xe
#!/bin/bash -x

# Build docker image in openshift
# oc apply -f imagestream.yaml
Expand Down
6 changes: 3 additions & 3 deletions deploy/route.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ metadata:
creationTimestamp: '2018-12-31T10:24:53Z'
labels:
app: gontador
name: gontador
name: gontador-http
namespace: gontador
resourceVersion: '58060'
selfLink: /apis/route.openshift.io/v1/namespaces/gontador/routes/gontador
uid: 50250017-0ce6-11e9-8918-2215dd3699dc
spec:
host: gontador-gontador.192.168.64.7.nip.io
port:
targetPort: gontador
targetPort: gontador-http
to:
kind: Service
name: gontador
name: gontador-http
weight: 100
wildcardPolicy: None
status:
Expand Down
72 changes: 50 additions & 22 deletions deploy/service.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,51 @@
apiVersion: v1
kind: Service
metadata:
annotations:
description: Exposes the gontador service
creationTimestamp: '2018-12-31T06:50:19Z'
labels:
app: gontador
name: gontador
namespace: gontador
resourceVersion: '3000'
spec:
ports:
- name: gontador
port: 3000
protocol: TCP
targetPort: 3000
selector:
app: gontador
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
kind: List
items:
- apiVersion: v1
kind: Service
metadata:
annotations:
description: Exposes the gontador service
creationTimestamp: '2018-12-31T06:50:19Z'
labels:
app: gontador
name: gontador-http
namespace: gontador
resourceVersion: '3000'
spec:
ports:
- name: gontador-http
port: 3000
protocol: TCP
targetPort: 3000
# - name: gontador-grpc
# port: 3001
# protocol: TCP
# targetPort: 3001
selector:
app: gontador
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
- apiVersion: v1
kind: Service
metadata:
annotations:
description: Exposes the gontador grpc service
creationTimestamp: '2018-12-31T06:50:19Z'
labels:
app: gontador
name: gontador-grpc
namespace: gontador
resourceVersion: '3000'
spec:
ports:
- name: gontador-grpc
port: 3001
nodePort: 30001
selector:
app: gontador
type: NodePort
status:
loadBalancer: {}
28 changes: 25 additions & 3 deletions deploy/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,44 @@ metadata:
creationTimestamp: null
name: gontador-template
objects:
- apiVersion: v1
kind: Service
metadata:
annotations:
description: Exposes the gontador grpc service
labels:
app: gontador
name: gontador-grpc
namespace: gontador
spec:
ports:
- name: gontador-grpc
port: 3001
nodePort: 30001
selector:
app: gontador
type: NodePort
status:
loadBalancer: {}
- apiVersion: v1
kind: Service
metadata:
annotations:
description: Exposes the gontador service
creationTimestamp: '2018-12-31T06:50:19Z'
labels:
app: gontador
name: gontador
name: gontador-http
namespace: gontador
spec:
ports:
- name: gontador
- name: gontador-http
port: 3000
protocol: TCP
targetPort: 3000
# - name: gontador-grpc
# port: 3001
# protocol: TCP
# targetPort: 3001
selector:
app: gontador
sessionAffinity: None
Expand Down
Loading

0 comments on commit d112f59

Please sign in to comment.