Skip to content

Commit

Permalink
Simplify example running from docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
stanley-cheung committed Mar 16, 2018
1 parent 2bde3dc commit 2278180
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 54 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ Nginx gateway. In future, we expect gRPC-Web to be supported in
language-specific Web frameworks, such as Go, Java, and Node, which will
eliminate the need to deploy a gateway at all.

## Quick start

Try gRPC-Web and run a quick Echo example from the browser!

From the repo root directory:

```sh
$ docker build -t grpc-web --build-arg with_examples=true \
-f net/grpc/gateway/docker/ubuntu_16_04/Dockerfile .
$ docker run -t -p 8080:8080 grpc-web
```

Open a browser tab, and inspect
```
http://localhost:8080/net/grpc/gateway/examples/echo/echotest.html
```

## How it works

Let's take a look at how gRPC-Web works with a simple example. You can find out
Expand Down Expand Up @@ -59,9 +76,9 @@ from the browser!
Create your client
```js
var echoService = new proto.grpc.gateway.testing.EchoServiceClient(
'http://localhost:9091');
'http://localhost:8080');
```

Make a unary RPC call
```js
var unaryRequest = new proto.grpc.gateway.testing.EchoRequest();
Expand Down
19 changes: 7 additions & 12 deletions net/grpc/gateway/docker/debian_stretch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,14 @@
#
# RUN
#
# 1. Nginx gateway:
# 1. Run the docker container
#
# $ docker run -itp 8080:8080 -p 9091:9091 --name grpc-web grpc-web /bin/bash
# $ cd /github/grpc-web/gConnector && ./nginx.sh
# $ docker run -t -p 8080:8080 grpc-web
#
# 2. Backend gRPC server:
# 2. Browser example:
# (if you had built the end-to-end example with Option 2 in the BUILD section)
#
# $ docker exec -it grpc-web \
# /github/grpc-web/net/grpc/gateway/examples/echo/echo_server
#
# 3. Browser example:
# (if you had built the end-to-end example with Option 2 in the BUILD section)
#
# Once the Nginx gateway and the Echo server are both running in different
# terminals, you can point a web browser to
# Point a web browser to
#
# http://localhost:8080/net/grpc/gateway/examples/echo/echotest.html

Expand Down Expand Up @@ -86,3 +78,6 @@ RUN cd /github/grpc-web && \

RUN cd /github/grpc-web && \
./scripts/build_examples.sh

EXPOSE 8080
CMD ["/github/grpc-web/gConnector/run_example.sh"]
19 changes: 7 additions & 12 deletions net/grpc/gateway/docker/ubuntu_14_04/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,14 @@
#
# RUN
#
# 1. Nginx gateway:
# 1. Run the docker container
#
# $ docker run -itp 8080:8080 -p 9091:9091 --name grpc-web grpc-web /bin/bash
# $ cd /github/grpc-web/gConnector && ./nginx.sh
# $ docker run -t -p 8080:8080 grpc-web
#
# 2. Backend gRPC server:
# 2. Browser example:
# (if you had built the end-to-end example with Option 2 in the BUILD section)
#
# $ docker exec -it grpc-web \
# /github/grpc-web/net/grpc/gateway/examples/echo/echo_server
#
# 3. Browser example:
# (if you had built the end-to-end example with Option 2 in the BUILD section)
#
# Once the Nginx gateway and the Echo server are both running in different
# terminals, you can point a web browser to
# Point a web browser to
#
# http://localhost:8080/net/grpc/gateway/examples/echo/echotest.html

Expand Down Expand Up @@ -88,3 +80,6 @@ RUN cd /github/grpc-web && \

RUN cd /github/grpc-web && \
./scripts/build_examples.sh

EXPOSE 8080
CMD ["/github/grpc-web/gConnector/run_example.sh"]
19 changes: 7 additions & 12 deletions net/grpc/gateway/docker/ubuntu_16_04/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,14 @@
#
# RUN
#
# 1. Nginx gateway:
# 1. Run the docker container
#
# $ docker run -itp 8080:8080 -p 9091:9091 --name grpc-web grpc-web /bin/bash
# $ cd /github/grpc-web/gConnector && ./nginx.sh
# $ docker run -t -p 8080:8080 grpc-web
#
# 2. Backend gRPC server:
# 2. Browser example:
# (if you had built the end-to-end example with Option 2 in the BUILD section)
#
# $ docker exec -it grpc-web \
# /github/grpc-web/net/grpc/gateway/examples/echo/echo_server
#
# 3. Browser example:
# (if you had built the end-to-end example with Option 2 in the BUILD section)
#
# Once the Nginx gateway and the Echo server are both running in different
# terminals, you can point a web browser to
# Point a web browser to
#
# http://localhost:8080/net/grpc/gateway/examples/echo/echotest.html

Expand Down Expand Up @@ -85,3 +77,6 @@ RUN cd /github/grpc-web && \

RUN cd /github/grpc-web && \
./scripts/build_examples.sh

EXPOSE 8080
CMD ["/github/grpc-web/gConnector/run_example.sh"]
1 change: 1 addition & 0 deletions net/grpc/gateway/examples/echo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ package:
cp echo_server $(ROOT_DIR)/gConnector
cp echotest.html $(ROOT_DIR)/gConnector/$(EXAMPLES_PATH)
cp compiled.js $(ROOT_DIR)/gConnector
cp run_example.sh $(ROOT_DIR)/gConnector
zip -r $(ROOT_DIR)/gConnector.zip $(ROOT_DIR)/gConnector/*

echo_server: echo.pb.o echo.grpc.pb.o echo_server.o echo_service_impl.o
Expand Down
21 changes: 18 additions & 3 deletions net/grpc/gateway/examples/echo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,23 @@ our [pre-requisites](../../../../../INSTALL.md):
1. Protocol buffers
2. gRPC
3. Closure compiler




## Using Docker

From the repo root directory:

```sh
$ docker build -t grpc-web --build-arg with_examples=true \
-f net/grpc/gateway/docker/ubuntu_16_04/Dockerfile .
$ docker run -t -p 8080:8080 grpc-web
```

Open a browser tab, and inspect
```
http://<hostname>:8080/net/grpc/gateway/examples/echo/echotest.html
```

## Build the example

From the repo root directory:
Expand Down Expand Up @@ -45,7 +60,7 @@ $ cd net/grpc/gateway/examples/echo && ./echo_server &
$ cd gConnector && ./nginx.sh &
```

3. Open a browser tab, and Inspect
3. Open a browser tab, and inspect
```
http://<hostname>:8080/net/grpc/gateway/examples/echo/echotest.html
```
Expand Down
2 changes: 1 addition & 1 deletion net/grpc/gateway/examples/echo/echotest.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@

$(document).ready(function() {
echoService = new proto.grpc.gateway.testing.EchoServiceClient(
'http://' + window.location.hostname + ':9091');
'http://' + window.location.hostname + ':8080');

// event handlers
$("#send").click(send);
Expand Down
9 changes: 3 additions & 6 deletions net/grpc/gateway/examples/echo/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ http {
proxy_request_buffering off;
server {
listen 8080;
root /var/www/html;
location / {
}
}
server {
listen 9091;
server_name localhost;
location ~ \.(html|js)$ {
root /var/www/html;
}
location / {
grpc_pass localhost:9090;
if ($request_method = 'OPTIONS') {
Expand Down
18 changes: 18 additions & 0 deletions net/grpc/gateway/examples/echo/run_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cd "$(dirname "$0")"
./nginx.sh &
../net/grpc/gateway/examples/echo/echo_server
13 changes: 7 additions & 6 deletions net/grpc/gateway/examples/echo/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ To serve static content, we just need a simple block like this:
```
server {
listen 8080;
root /var/www/html;
location / {
server_name localhost;
location ~ \.(html|js)$ {
root /var/www/html;
}
}
```
Expand All @@ -44,7 +45,7 @@ this:

```
server {
listen 9091;
listen 8080;
server_name localhost;
location / {
grpc_pass localhost:9090;
Expand All @@ -57,8 +58,8 @@ content.


In this simple example, the HTML and JS assets are served from port `:8080`.
The HTML makes gRPC requests to port `:9091`. Nginx forwards the requests to
the backend gRPC server listening on port `:9090`.
The HTML makes gRPC requests to same port `:8080`. Nginx forwards the request
to the backend gRPC server listening on port `:9090`.



Expand Down Expand Up @@ -154,7 +155,7 @@ Then create the service client.

```js
var service = new proto.grpc.gateway.testing.EchoServiceClient(
'http://localhost:9091');
'http://localhost:8080');
```


Expand Down
1 change: 1 addition & 0 deletions net/grpc/gateway/nginx/package/nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cd "$(dirname "$0")"
./nginx -p . -c conf/nginx.conf

0 comments on commit 2278180

Please sign in to comment.