Skip to content

Commit

Permalink
Fix CircleCI configuration (grpc-ecosystem#777)
Browse files Browse the repository at this point in the history
* Fix CircleCI configuration

The original configuration had never actually been run on CircleCI's
servers.

* Replace mentions of Travis with CircleCI
  • Loading branch information
johanbrandhorst authored and achew22 committed Oct 16, 2018
1 parent 39930fd commit 098e557
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 59 deletions.
34 changes: 7 additions & 27 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@ version: 2
jobs:
build:
docker:
- image: "golang:latest"
- image: "jfbrandhorst/grpc-gateway-build-env"
working_directory: /go/src/github.com/grpc-ecosystem/grpc-gateway
steps:
- checkout
- run: curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
- run: dep ensure --vendor-only
- run: go build ./...
test:
docker:
- image: "golang:latest"
- image: "jfbrandhorst/grpc-gateway-build-env"
working_directory: /go/src/github.com/grpc-ecosystem/grpc-gateway
environment:
GLOG_logtostderr: "1"
steps:
- checkout
- run: curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
- run: dep ensure --vendor-only
- run: go test -race -coverprofile=coverage.txt ./...
- run: bash <(curl -s https://codecov.io/bash)
Expand All @@ -27,6 +25,7 @@ jobs:
working_directory: /go/src/github.com/grpc-ecosystem/grpc-gateway
steps:
- checkout
- run: dep ensure --vendor-only
- run: >
. $HOME/.nvm/nvm.sh &&
cd examples/browser &&
Expand All @@ -44,46 +43,27 @@ jobs:
- run: git diff --exit-code
lint:
docker:
- image: "golang:latest"
- image: "jfbrandhorst/grpc-gateway-build-env"
working_directory: /go/src/github.com/grpc-ecosystem/grpc-gateway
steps:
- checkout
- run: curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
- run: dep ensure --vendor-only
- run: go get github.com/golang/lint/golint
- run: go get golang.org/x/lint/golint
- run: make lint
bazel_build:
docker:
- image: "l.gcr.io/google/bazel:latest"
working_directory: /go/src/github.com/grpc-ecosystem/grpc-gateway
steps:
- checkout
- run: >
bazel
--batch
--output_base=$HOME/.cache/_grpc_gateway_bazel
--host_jvm_args=-Xmx500m
--host_jvm_args=-Xms500m
build
--local_resources=400,1,1.0
//...
- run: bazel --batch --output_base=$HOME/.cache/_grpc_gateway_bazel --host_jvm_args=-Xmx500m --host_jvm_args=-Xms500m build --local_resources=400,1,1.0 //...
bazel_test:
docker:
- image: "l.gcr.io/google/bazel:latest"
working_directory: /go/src/github.com/grpc-ecosystem/grpc-gateway
steps:
- checkout
- run: >
bazel
--batch
--output_base=$HOME/.cache/_grpc_gateway_bazel
--host_jvm_args=-Xmx500m
--host_jvm_args=-Xms500m
test
--local_resources=400,1,1.0
--test_output=errors
--features=race
//...
- run: bazel --batch --output_base=$HOME/.cache/_grpc_gateway_bazel --host_jvm_args=-Xmx500m --host_jvm_args=-Xms500m test --local_resources=400,1,1.0 --test_output=errors --features=race //...
workflows:
version: 2
all:
Expand Down
12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,22 @@ $(ECHO_EXAMPLE_SRCS): $(ECHO_EXAMPLE_SPEC)
$(SWAGGER_CODEGEN) generate -i $(ECHO_EXAMPLE_SPEC) \
-l go -o examples/clients/echo --additional-properties packageName=echo
@rm -f $(EXAMPLE_CLIENT_DIR)/echo/README.md \
$(EXAMPLE_CLIENT_DIR)/echo/git_push.sh \
$(EXAMPLE_CLIENT_DIR)/echo/.travis.yml
$(EXAMPLE_CLIENT_DIR)/echo/git_push.sh
$(ABE_EXAMPLE_SRCS): $(ABE_EXAMPLE_SPEC)
$(SWAGGER_CODEGEN) generate -i $(ABE_EXAMPLE_SPEC) \
-l go -o examples/clients/abe --additional-properties packageName=abe
@rm -f $(EXAMPLE_CLIENT_DIR)/abe/README.md \
$(EXAMPLE_CLIENT_DIR)/abe/git_push.sh \
$(EXAMPLE_CLIENT_DIR)/abe/.travis.yml
$(EXAMPLE_CLIENT_DIR)/abe/git_push.sh
$(UNANNOTATED_ECHO_EXAMPLE_SRCS): $(UNANNOTATED_ECHO_EXAMPLE_SPEC)
$(SWAGGER_CODEGEN) generate -i $(UNANNOTATED_ECHO_EXAMPLE_SPEC) \
-l go -o examples/clients/unannotatedecho --additional-properties packageName=unannotatedecho
@rm -f $(EXAMPLE_CLIENT_DIR)/unannotatedecho/README.md \
$(EXAMPLE_CLIENT_DIR)/unannotatedecho/git_push.sh \
$(EXAMPLE_CLIENT_DIR)/unannotatedecho/.travis.yml
$(EXAMPLE_CLIENT_DIR)/unannotatedecho/git_push.sh
$(RESPONSE_BODY_EXAMPLE_SRCS): $(RESPONSE_BODY_EXAMPLE_SPEC)
$(SWAGGER_CODEGEN) generate -i $(RESPONSE_BODY_EXAMPLE_SPEC) \
-l go -o examples/clients/responsebody --additional-properties packageName=responsebody
@rm -f $(EXAMPLE_CLIENT_DIR)/responsebody/README.md \
$(EXAMPLE_CLIENT_DIR)/responsebody/git_push.sh \
$(EXAMPLE_CLIENT_DIR)/responsebody/.travis.yml
$(EXAMPLE_CLIENT_DIR)/responsebody/git_push.sh

examples: $(EXAMPLE_DEPSRCS) $(EXAMPLE_SVCSRCS) $(EXAMPLE_GWSRCS) $(EXAMPLE_SWAGGERSRCS) $(EXAMPLE_CLIENT_SRCS)
test: examples
Expand Down
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# grpc-gateway

[![Build Status](https://travis-ci.org/grpc-ecosystem/grpc-gateway.svg?branch=master)](https://travis-ci.org/grpc-ecosystem/grpc-gateway)
[![CircleCI](https://circleci.com/gh/grpc-ecosystem/grpc-gateway.svg?style=svg)](https://circleci.com/gh/grpc-ecosystem/grpc-gateway)

grpc-gateway is a plugin of [protoc](http://github.com/google/protobuf).
It reads [gRPC](http://github.com/grpc/grpc-common) service definition,
Expand Down Expand Up @@ -43,26 +43,26 @@ go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/golang/protobuf/protoc-gen-go
```

## Usage
Make sure that your `$GOPATH/bin` is in your `$PATH`.

1. Define your service in gRPC

your_service.proto:
```protobuf
syntax = "proto3";
package example;
message StringMessage {
string value = 1;
}
service YourService {
rpc Echo(StringMessage) returns (StringMessage) {}
}
```
2. Add a [`google.api.http`](https://github.com/googleapis/googleapis/blob/master/google/api/http.proto#L46) to your .proto file

your_service.proto:
```diff
syntax = "proto3";
Expand All @@ -73,7 +73,7 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`.
message StringMessage {
string value = 1;
}

service YourService {
- rpc Echo(StringMessage) returns (StringMessage) {}
+ rpc Echo(StringMessage) returns (StringMessage) {
Expand All @@ -88,27 +88,27 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`.
If you do not want to modify the proto file for use with grpc-gateway you can alternatively use an external [gRPC Service Configuration](https://cloud.google.com/endpoints/docs/grpc/grpc-service-config) file. [Check our documentation](https://grpc-ecosystem.github.io/grpc-gateway/docs/grpcapiconfiguration.html) for more information.

3. Generate gRPC stub

```sh
protoc -I/usr/local/include -I. \
-I$GOPATH/src \
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--go_out=plugins=grpc:. \
path/to/your_service.proto
```

It will generate a stub file `path/to/your_service.pb.go`.
4. Implement your service in gRPC as usual
1. (Optional) Generate gRPC stub in the language you want.

e.g.
```sh
protoc -I/usr/local/include -I. \
-I$GOPATH/src \
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--ruby_out=. \
path/to/your/service_proto

protoc -I/usr/local/include -I. \
-I$GOPATH/src \
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
Expand All @@ -118,62 +118,62 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`.
```
2. Add the googleapis-common-protos gem (or your language equivalent) as a dependency to your project.
3. Implement your service

5. Generate reverse-proxy

```sh
protoc -I/usr/local/include -I. \
-I$GOPATH/src \
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--grpc-gateway_out=logtostderr=true:. \
path/to/your_service.proto
```

It will generate a reverse proxy `path/to/your_service.pb.gw.go`.

Note: After generating the code for each of the stubs, in order to build the code, you will want to run ```go get .``` from the directory containing the stubs.

6. Write an entrypoint

Now you need to write an entrypoint of the proxy server.
```go
package main

import (
"flag"
"net/http"

"github.com/golang/glog"
"golang.org/x/net/context"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"

gw "path/to/your_service_package"
)

var (
echoEndpoint = flag.String("echo_endpoint", "localhost:9090", "endpoint of YourService")
)

func run() error {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()

mux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithInsecure()}
err := gw.RegisterYourServiceHandlerFromEndpoint(ctx, mux, *echoEndpoint, opts)
if err != nil {
return err
}

return http.ListenAndServe(":8080", mux)
}

func main() {
flag.Parse()
defer glog.Flush()

if err := run(); err != nil {
glog.Fatal(err)
}
Expand Down Expand Up @@ -240,7 +240,7 @@ But patch is welcome.
* [How gRPC error codes map to HTTP status codes in the response](https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/errors.go#L15)
* HTTP request source IP is added as `X-Forwarded-For` gRPC request header
* HTTP request host is added as `X-Forwarded-Host` gRPC request header
* HTTP `Authorization` header is added as `authorization` gRPC request header
* HTTP `Authorization` header is added as `authorization` gRPC request header
* Remaining Permanent HTTP header keys (as specified by the IANA [here](http://www.iana.org/assignments/message-headers/message-headers.xhtml) are prefixed with `grpcgateway-` and added with their values to gRPC request header
* HTTP headers that start with 'Grpc-Metadata-' are mapped to gRPC metadata (prefixed with `grpcgateway-`)
* While configurable, the default {un,}marshaling uses [jsonpb](https://godoc.org/github.com/golang/protobuf/jsonpb) with `OrigName: true`.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# grpc-gateway

[![Build Status](https://travis-ci.org/grpc-ecosystem/grpc-gateway.svg?branch=master)](https://travis-ci.org/grpc-ecosystem/grpc-gateway)
[![CircleCI](https://circleci.com/gh/johanbrandhorst/grpc-gateway.svg?style=svg)](https://circleci.com/gh/johanbrandhorst/grpc-gateway)

grpc-gateway is a plugin of [protoc](http://github.com/google/protobuf).
It reads [gRPC](http://github.com/grpc/grpc-common) service definition,
Expand Down

0 comments on commit 098e557

Please sign in to comment.