diff --git a/examples/k8s/Makefile b/examples/k8s/Makefile new file mode 100644 index 0000000..e9af61d --- /dev/null +++ b/examples/k8s/Makefile @@ -0,0 +1,10 @@ +SOURCES := $(shell find . -name "*.proto" -not -path ./vendor/\*) + +TARGETS_K8S := $(foreach source, $(SOURCES), $(source)_k8s) + +.PHONY: build +build: $(TARGETS_K8S) + +$(TARGETS_K8S): %_k8s: + @mkdir -p $(dir $*)gen + protoc $(PROTOC_OPTS) --gotemplate_out=debug=true,template_dir=./templates:$(dir $*)gen "$*" \ No newline at end of file diff --git a/examples/k8s/gen/nginx/dpl.yaml b/examples/k8s/gen/nginx/dpl.yaml new file mode 100644 index 0000000..342d1b0 --- /dev/null +++ b/examples/k8s/gen/nginx/dpl.yaml @@ -0,0 +1,18 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: nginx + labels: + method: Hello-World-nginx +spec: + replicas: 3 + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx + ports: + - containerPort: 80 \ No newline at end of file diff --git a/examples/k8s/gen/nginx/svc.yaml b/examples/k8s/gen/nginx/svc.yaml new file mode 100644 index 0000000..485e0e7 --- /dev/null +++ b/examples/k8s/gen/nginx/svc.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: nginx +spec: + selector: + app: nginx + ports: + - name: http + port: 80 \ No newline at end of file diff --git a/examples/k8s/nginx.proto b/examples/k8s/nginx.proto new file mode 100644 index 0000000..2b2d776 --- /dev/null +++ b/examples/k8s/nginx.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package nginx; + +message Empty { +} + +service Nginx { + rpc Hello(Empty) returns (Empty) {} + rpc World(Empty) returns (Empty) {} +} \ No newline at end of file diff --git a/examples/k8s/templates/{{.File.Package}}/dpl.yaml.tmpl b/examples/k8s/templates/{{.File.Package}}/dpl.yaml.tmpl new file mode 100644 index 0000000..946526c --- /dev/null +++ b/examples/k8s/templates/{{.File.Package}}/dpl.yaml.tmpl @@ -0,0 +1,18 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{.File.Package}} + labels: + method: {{range .Service.Method}}{{.Name}}-{{end}}{{.File.Package}} +spec: + replicas: 3 + template: + metadata: + labels: + app: {{.File.Package}} + spec: + containers: + - name: nginx + image: nginx + ports: + - containerPort: 80 \ No newline at end of file diff --git a/examples/k8s/templates/{{.File.Package}}/svc.yaml.tmpl b/examples/k8s/templates/{{.File.Package}}/svc.yaml.tmpl new file mode 100644 index 0000000..1fc1d86 --- /dev/null +++ b/examples/k8s/templates/{{.File.Package}}/svc.yaml.tmpl @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{.File.Package}} +spec: + selector: + app: {{.File.Package}} + ports: + - name: http + port: 80 \ No newline at end of file