Skip to content

gabihodoroaga/http-grpc-websocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

http-grpc-websocket

A demo project about how you can run HTTP, gRPC and websocket in Cloud Run using a single port. You can follow this tutorial HTTP, gRPC, and websocket on Google Cloud Run to find out more.

Run and test locally

Run

go run main.go

On a separate terminal,

test HTTP

curl http://localhost:8080/ping

test gRPC

go run clients/grpc/main.go

test Websocket

go run clients/ws/main.go

Run and test on Cloud Run with authentication

Set your variables

PROJECT_ID=$(gcloud config list project --format='value(core.project)')
REGION=us-central1

Create a service account

gcloud iam service-accounts create demo-grpc-sa \
  --display-name "Demo service account for gRPC on Cloud Run"

Create a new key for this service account

gcloud iam service-accounts keys create key.json \
  --iam-account demo-grpc-sa@${PROJECT_ID}.iam.gserviceaccount.com

Build the image

gcloud builds submit --tag gcr.io/$PROJECT_ID/grpcwebapp --project $PROJECT_ID .

Deploy the service

gcloud run deploy grpcwebapp \
--image gcr.io/$PROJECT_ID/grpcwebapp \
--set-env-vars=AUTH_SERVICE_ACCOUNTS="demo-grpc-sa@${PROJECT_ID}.iam.gserviceaccount.com",AUTH_AUDIENCE=webapp \
--allow-unauthenticated \
--timeout=10m \
--project $PROJECT_ID \
--region $REGION

Get the public URL

SERVICE_URL=$(gcloud run services describe grpcwebapp --platform managed --region $REGION --format 'value(status.url)')
echo $SERVICE_URL
SERVICE_HOST=$(echo "$SERVICE_URL" | awk -F/ '{print $3}')
echo $SERVICE_HOST

test HTTPS

curl -v $SERVICE_URL/ping

test gRPC

go run clients/grpc/main.go --server "$SERVICE_HOST:443" --key key.json --insecure=false

test Websocket

go run clients/ws/main.go --server "wss://$SERVICE_HOST/ws" --key key.json

Generate protobuffer files.

protoc \
--proto_path=grpc/proto \
--go_out=plugins=grpc:. \
./grpc/proto/*.proto

References

This example was based on this post Serving gRPC+HTTP/2 from the same Cloud Run container written by Ahmet Alp Balkan (https://github.com/ahmetb).

About

How to run HTTP, gRPC, websocket all on the same port on Google Cloud Run

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors