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

Renaming to frees-rpc. Moves examples to its own repository #40

Merged
merged 1 commit into from
Sep 5, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ project/plugins/project/
.DS_Store

/secring.gpg
demo/http/gateway/*json
demo/http/gateway/*go
15 changes: 0 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ scala:
jdk:
- oraclejdk8

env:
global:
- GOPATH="${HOME}/go"
- PATH="${GOPATH}/bin:${PATH}"

before_cache:
- du -h -d 1 $HOME/.ivy2/
- du -h -d 2 $HOME/.sbt/
Expand All @@ -35,19 +30,9 @@ before_install:
- if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then
openssl aes-256-cbc -K $encrypted_80bb47bfd841_key -iv $encrypted_80bb47bfd841_iv -in secring.gpg.enc -out secring.gpg -d;
fi
- sh ./scripts/protobuf.sh
- sh ./scripts/gimme.sh

install:
- go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
- 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 -v google.golang.org/grpc
- go get -u github.com/golang/protobuf/protoc-gen-go

script:
- sbt ++$TRAVIS_SCALA_VERSION orgScriptCI
- sbt -Dgo.path=$GOPATH ++$TRAVIS_SCALA_VERSION validateHttpDemo

after_success:
- bash <(curl -s https://codecov.io/bash) -t 5b75b318-ab71-4fbc-9203-bfa7765cdbdc
Expand Down
108 changes: 2 additions & 106 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,113 +9,9 @@

Simple RPC with Freestyle

## Greeting Demo
# Demo

Run server:

```
sbt runServer
```

Run client:

```
sbt runClient
```

## User Demo

Based on https://github.com/grpc-ecosystem/grpc-gateway.

[grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway) is a plugin of protoc. It reads gRPC service definition, and generates a reverse-proxy server which translates a RESTful JSON API into gRPC.
This server is generated according to [custom options](https://cloud.google.com/service-management/reference/rpc/google.api#http) in your gRPC definition.

### Prerequisites

It's mandatory to follow these [instructions](https://github.com/grpc-ecosystem/grpc-gateway#installation) before proceeding. You might want use `brew install protobuf` if you're using OSX.

And then:

```bash
$ brew install go
$ go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
$ 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 -v google.golang.org/grpc
$ go get -u github.com/golang/protobuf/protoc-gen-go
```

Finally, make sure that your `$GOPATH/bin` is in your `$PATH`.

### Troubleshooting

#### `failed to run aclocal: No such file or directory`

The development release of a program source code often comes with `autogen.sh` which is used to prepare a build process, including verifying program functionality and generating configure script. This `autogen.sh` script then relies on `autoreconf` to invoke `autoconf`, `automake`, `aclocal` and other related tools.

The missing `aclocal` is part of `automake` package. Thus, to fix this error, install `automake` package.

* `OSX`:

https://gist.github.com/justinbellamy/2672db1c78f024f2d4fe

* `Debian`, `Ubuntu` or `Linux Mint`:

```bash
$ sudo apt-get install automake
```

* `CentOS`, `Fedora` or `RHEL`:

```bash
$ sudo yum install automake
```

## Run Demo

### Running the Server

```
sbt -Dgo.path=$GOPATH ";project demo-http;runMain freestyle.rpc.demo.user.UserServerApp"
```

### Running the Client

Now, you could invoke the service:

* Using the client, as usual:

```
sbt -Dgo.path=$GOPATH ";project demo-http;runMain freestyle.rpc.demo.user.UserClientApp"
```

### Generating and Running the Gateway

You could generate a reverse proxy and writing an endpoint as it's described [here](https://github.com/grpc-ecosystem/grpc-gateway#usage).

To run the gateway:

```bash
go run demo/http/gateway/server/entry.go
```

Then, you could use `curl` or similar to fetch the user over `HTTP`:

```bash
curl -X POST \
-H "Content-Type: application/json" \
-H "Cache-Control: no-cache" \
-H "Postman-Token: 1e813409-6aa6-8cd1-70be-51305f31667f" \
-d '{
"password" : "password"
}' "http://127.0.0.1:8080/v1/frees"
```

HTTP Response:

```bash
{"name":"Freestyle","email":"hello@frees.io"}%
```
See [freestyle-rpc-examples repo](https://github.com/frees-io/freestyle-rpc-examples).

[comment]: # (Start Copyright)
# Copyright
Expand Down
90 changes: 5 additions & 85 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import com.trueaccord.scalapb.compiler.{Version => cv}

pgpPassphrase := Some(getEnvVar("PGP_PASSPHRASE").getOrElse("").toCharArray)
pgpPublicRing := file(s"$gpgFolder/pubring.gpg")
pgpSecretRing := file(s"$gpgFolder/secring.gpg")

lazy val root = project
.in(file("."))
.settings(name := "freestyle-rpc")
.settings(moduleName := "root")
.settings(noPublishSettings: _*)
.aggregate(rpc, `demo-greeting`, `demo-protocolgen`)

lazy val rpc = project
.in(file("rpc"))
.settings(moduleName := "freestyle-rpc")
.settings(moduleName := "frees-rpc")
.settings(scalaMetaSettings: _*)
.settings(
Seq(
resolvers += Resolver.bintrayRepo("beyondthelines", "maven"),
Expand All @@ -26,79 +18,7 @@ lazy val rpc = project
"beyondthelines" %% "pbdirect" % "0.0.3",
%%("monix"),
%%("scalamockScalatest") % "test"
)
): _*
)

lazy val protogen = taskKey[Unit]("Generates .proto files from freestyle-rpc service definitions")

lazy val `demo-protocolgen` = project
.in(file("demo/protocolgen"))
.settings(moduleName := "freestyle-rpc-demo-protocolgen")
.aggregate(rpc)
.dependsOn(rpc)
.settings(noPublishSettings: _*)
.settings(commandAliases: _*)
.settings(demoCommonSettings: _*)
.settings(
protogen := {
toError(
(runner in Compile).value
.run(
mainClass = "freestyle.rpc.protocol.ProtoCodeGen",
classpath = sbt.Attributed.data((fullClasspath in Compile).value),
options = Seq(
(baseDirectory.value / "src" / "main" / "scala").absolutePath,
(baseDirectory.value / "src" / "main" / "proto").absolutePath
),
log = streams.value.log
)
)
}
)

lazy val `demo-greeting` = project
.in(file("demo/greeting"))
.settings(moduleName := "freestyle-rpc-demo-greeting")
.aggregate(rpc)
.dependsOn(rpc)
.settings(noPublishSettings: _*)
.settings(commandAliases: _*)
.settings(demoCommonSettings: _*)
.settings(
Seq(
libraryDependencies ++= Seq(
%%("freestyle-async"),
%%("freestyle-config")
)
): _*)

lazy val googleApi = project
.in(file("third_party"))
.settings(
PB.protoSources.in(Compile) ++= Seq(
file(s"$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/")
),
PB.targets.in(Compile) := Seq(scalapb.gen() -> sourceManaged.in(Compile).value),
libraryDependencies += "com.trueaccord.scalapb" %% "scalapb-runtime" % cv.scalapbVersion % "protobuf"
)

lazy val `demo-http` = project
.in(file("demo/http"))
.settings(moduleName := "freestyle-rpc-demo-http")
.aggregate(rpc, googleApi, `demo-greeting`)
.dependsOn(rpc, googleApi, `demo-greeting`)
.settings(noPublishSettings: _*)
.settings(demoCommonSettings: _*)
.settings(
Seq(
PB.protocOptions.in(Compile) ++= Seq(
"-I/usr/local/include -I.",
s"-I$GOPATH/src",
s"-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis",
"--go_out=plugins=grpc:./demo/http/gateway",
"--grpc-gateway_out=logtostderr=true:./demo/http/gateway",
"--swagger_out=logtostderr=true:./demo/http/gateway"
)
),
coverageExcludedPackages := "<empty>;freestyle\\.rpc\\.demo\\..*"
): _*
)
)
9 changes: 0 additions & 9 deletions demo/greeting/src/main/proto/echo.proto

This file was deleted.

11 changes: 0 additions & 11 deletions demo/greeting/src/main/proto/echo_messages.proto

This file was deleted.

19 changes: 0 additions & 19 deletions demo/greeting/src/main/proto/greeting.proto

This file was deleted.

15 changes: 0 additions & 15 deletions demo/greeting/src/main/resources/application.conf

This file was deleted.