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
go run main.goOn a separate terminal,
test HTTP
curl http://localhost:8080/pingtest gRPC
go run clients/grpc/main.gotest Websocket
go run clients/ws/main.goSet your variables
PROJECT_ID=$(gcloud config list project --format='value(core.project)')
REGION=us-central1Create 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.comBuild 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 $REGIONGet 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_HOSTtest HTTPS
curl -v $SERVICE_URL/pingtest gRPC
go run clients/grpc/main.go --server "$SERVICE_HOST:443" --key key.json --insecure=falsetest Websocket
go run clients/ws/main.go --server "wss://$SERVICE_HOST/ws" --key key.jsonprotoc \
--proto_path=grpc/proto \
--go_out=plugins=grpc:. \
./grpc/proto/*.protoThis 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).