Skip to content

Commit 73cda30

Browse files
authored
Expose Pod, Image, and Gateway over HTTP using GRPC-Gateway (#1391)
<!-- This is an auto-generated description by cubic. --> ## Summary by cubic Expose Pod, Image, and Gateway gRPC services over HTTP using grpc-gateway, mounted at /api/v1/grpc-gateway. This lets clients call JSON endpoints without a gRPC client. - **New Features** - Added grpc-gateway mux and server wiring (initGrpcGateway) and mounted at /api/v1/grpc-gateway/*. - Registered PodService, ImageService, and GatewayService handlers against the gRPC port. - Authorization header is forwarded to gRPC metadata; gRPC interceptors handle auth. - Updated gen_proto.sh to generate grpc-gateway code for pod/image/gateway with generate_unbound_methods=true. - Added generated reverse-proxy files: proto/pod.pb.gw.go, proto/image.pb.gw.go, proto/gateway.pb.gw.go. - **Dependencies** - Added protoc-gen-grpc-gateway@v2.27.1 to bin/setup.sh. - Promoted github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.0 to a direct dependency. <!-- End of auto-generated description by cubic. -->
1 parent b42ff84 commit 73cda30

File tree

26 files changed

+12076
-1334
lines changed

26 files changed

+12076
-1334
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ stop:
6565
protocol:
6666
uv run ./bin/gen_proto.sh
6767

68+
openapi:
69+
@echo "Generating OpenAPI schemas..."
70+
@mkdir -p docs/openapi
71+
protoc -I ./googleapis -I ./pkg/types -I ./pkg/abstractions/pod/ --openapiv2_out=./docs/openapi --openapiv2_opt logtostderr=true ./pkg/abstractions/pod/pod.proto
72+
protoc -I ./googleapis -I ./pkg/abstractions/image/ --openapiv2_out=./docs/openapi --openapiv2_opt logtostderr=true ./pkg/abstractions/image/image.proto
73+
protoc -I ./googleapis -I ./pkg/types -I ./pkg/gateway/ --openapiv2_out=./docs/openapi --openapiv2_opt logtostderr=true ./pkg/gateway/gateway.proto
74+
@echo "OpenAPI schemas generated in docs/openapi/"
75+
6876
verify-protocol:
6977
./bin/verify_proto.sh
7078

bin/gen_proto.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ protoc -I ./pkg/types/ --go_out=./proto --go_opt=paths=source_relative --go-grpc
2121
protoc -I ./pkg/types/ --python_betterproto_beta9_out=./sdk/src/beta9/clients/ ./pkg/types/types.proto
2222

2323
protoc -I ./pkg/scheduler/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/scheduler/scheduler.proto
24-
protoc -I ./pkg/types -I ./pkg/gateway/ -I ./pkg/worker/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/worker/worker.proto
25-
protoc -I ./pkg/types -I ./pkg/gateway/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/gateway/gateway.proto
26-
protoc -I ./pkg/types -I ./pkg/gateway/ --python_betterproto_beta9_out=./sdk/src/beta9/clients/ ./pkg/gateway/gateway.proto
24+
protoc -I ./googleapis -I ./pkg/types -I ./pkg/gateway/ -I ./pkg/worker/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/worker/worker.proto
25+
protoc -I ./googleapis -I ./pkg/types -I ./pkg/gateway/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/gateway/gateway.proto
26+
protoc -I ./googleapis -I ./pkg/types -I ./pkg/gateway/ --python_betterproto_beta9_out=./sdk/src/beta9/clients/ ./pkg/gateway/gateway.proto
2727

2828
# Repository services
29-
protoc -I $PROTOC_INCLUDE_PATH -I ./pkg/types -I ./pkg/gateway/services/repository/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/gateway/services/repository/container_repo.proto
30-
protoc -I $PROTOC_INCLUDE_PATH -I ./pkg/types -I ./pkg/gateway/services/repository/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/gateway/services/repository/worker_repo.proto
29+
protoc -I $PROTOC_INCLUDE_PATH -I ./googleapis -I ./pkg/types -I ./pkg/gateway/services/repository/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/gateway/services/repository/container_repo.proto
30+
protoc -I $PROTOC_INCLUDE_PATH -I ./googleapis -I ./pkg/types -I ./pkg/gateway/services/repository/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/gateway/services/repository/worker_repo.proto
3131

3232
# Generate code for abstractions
33-
protoc -I $PROTOC_INCLUDE_PATH -I ./pkg/abstractions/image/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/abstractions/image/image.proto
34-
protoc -I $PROTOC_INCLUDE_PATH -I ./pkg/abstractions/image/ --python_betterproto_beta9_out=./sdk/src/beta9/clients/ ./pkg/abstractions/image/image.proto
33+
protoc -I $PROTOC_INCLUDE_PATH -I ./googleapis -I ./pkg/abstractions/image/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/abstractions/image/image.proto
34+
protoc -I $PROTOC_INCLUDE_PATH -I ./googleapis -I ./pkg/abstractions/image/ --python_betterproto_beta9_out=./sdk/src/beta9/clients/ ./pkg/abstractions/image/image.proto
3535

3636
protoc -I $PROTOC_INCLUDE_PATH -I ./pkg/abstractions/map/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/abstractions/map/map.proto
3737
protoc -I $PROTOC_INCLUDE_PATH -I ./pkg/abstractions/map/ --python_betterproto_beta9_out=./sdk/src/beta9/clients/ ./pkg/abstractions/map/map.proto
@@ -51,8 +51,16 @@ protoc -I $PROTOC_INCLUDE_PATH -I ./pkg/abstractions/taskqueue/ --python_betterp
5151
protoc -I $PROTOC_INCLUDE_PATH -I ./pkg/abstractions/endpoint/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/abstractions/endpoint/endpoint.proto
5252
protoc -I $PROTOC_INCLUDE_PATH -I ./pkg/abstractions/endpoint/ --python_betterproto_beta9_out=./sdk/src/beta9/clients/ ./pkg/abstractions/endpoint/endpoint.proto
5353

54-
protoc -I $PROTOC_INCLUDE_PATH -I ./pkg/types -I ./pkg/abstractions/pod/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/abstractions/pod/pod.proto
55-
protoc -I $PROTOC_INCLUDE_PATH -I ./pkg/types -I ./pkg/abstractions/pod/ --python_betterproto_beta9_out=./sdk/src/beta9/clients/ ./pkg/abstractions/pod/pod.proto
54+
protoc -I $PROTOC_INCLUDE_PATH -I ./googleapis -I ./pkg/types -I ./pkg/abstractions/pod/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/abstractions/pod/pod.proto
55+
protoc -I $PROTOC_INCLUDE_PATH -I ./googleapis -I ./pkg/types -I ./pkg/abstractions/pod/ --grpc-gateway_out=./proto --grpc-gateway_opt paths=source_relative --grpc-gateway_opt generate_unbound_methods=true ./pkg/abstractions/pod/pod.proto
56+
protoc -I $PROTOC_INCLUDE_PATH -I ./googleapis -I ./pkg/types -I ./pkg/abstractions/pod/ --openapiv2_out=./docs/openapi --openapiv2_opt logtostderr=true ./pkg/abstractions/pod/pod.proto
57+
58+
protoc -I $PROTOC_INCLUDE_PATH -I ./googleapis -I ./pkg/abstractions/image/ --grpc-gateway_out=./proto --grpc-gateway_opt paths=source_relative --grpc-gateway_opt generate_unbound_methods=true ./pkg/abstractions/image/image.proto
59+
protoc -I $PROTOC_INCLUDE_PATH -I ./googleapis -I ./pkg/abstractions/image/ --openapiv2_out=./docs/openapi --openapiv2_opt logtostderr=true ./pkg/abstractions/image/image.proto
60+
61+
protoc -I $PROTOC_INCLUDE_PATH -I ./googleapis -I ./pkg/types -I ./pkg/gateway/ --grpc-gateway_out=./proto --grpc-gateway_opt paths=source_relative --grpc-gateway_opt generate_unbound_methods=true ./pkg/gateway/gateway.proto
62+
protoc -I $PROTOC_INCLUDE_PATH -I ./googleapis -I ./pkg/types -I ./pkg/gateway/ --openapiv2_out=./docs/openapi --openapiv2_opt logtostderr=true ./pkg/gateway/gateway.proto
63+
protoc -I $PROTOC_INCLUDE_PATH -I ./googleapis -I ./pkg/types -I ./pkg/abstractions/pod/ --python_betterproto_beta9_out=./sdk/src/beta9/clients/ ./pkg/abstractions/pod/pod.proto
5664

5765
protoc -I $PROTOC_INCLUDE_PATH -I ./pkg/abstractions/output/ --go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative ./pkg/abstractions/output/output.proto
5866
protoc -I $PROTOC_INCLUDE_PATH -I ./pkg/abstractions/output/ --python_betterproto_beta9_out=./sdk/src/beta9/clients/ ./pkg/abstractions/output/output.proto

bin/setup.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,7 @@ check_status
6767

6868
echo "=> Installing go2proto"
6969
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.31.0
70+
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.27.1
71+
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
7072
go install github.com/beam-cloud/go2proto@latest
7173
check_status

docs/openapi/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# OpenAPI Schemas
2+
3+
This directory contains automatically generated OpenAPI (Swagger) schemas for the Beta9 gRPC Gateway endpoints.
4+
5+
## Generated Schemas
6+
7+
- `pod.swagger.json` - Pod service API endpoints
8+
- `image.swagger.json` - Image service API endpoints
9+
- `gateway.swagger.json` - Gateway service API endpoints
10+
11+
## How to Generate
12+
13+
To regenerate the OpenAPI schemas, run:
14+
15+
```bash
16+
make openapi
17+
```
18+
19+
Or to regenerate all protocol buffers including OpenAPI:
20+
21+
```bash
22+
make protocol
23+
```
24+
25+
## Viewing the Schemas
26+
27+
You can view these schemas using:
28+
29+
1. **Swagger UI**: Upload the JSON files to [Swagger Editor](https://editor.swagger.io/)
30+
2. **Local Swagger UI**: Use tools like `swagger-ui-serve` or similar
31+
3. **API Documentation Tools**: Import into tools like Postman, Insomnia, etc.
32+
33+
## API Endpoints
34+
35+
The schemas include all the HTTP endpoints that gRPC Gateway exposes, including:
36+
37+
- **Pod Service**: Container management, file operations, process control
38+
- **Image Service**: Container image operations
39+
- **Gateway Service**: Core gateway functionality
40+
41+
## Notes
42+
43+
- These schemas are automatically generated from `.proto` files
44+
- The HTTP annotations in the proto files define the REST endpoints
45+
- All endpoints support the same authentication and authorization as the gRPC services
46+
- The schemas include request/response models, parameter validation, and error responses

0 commit comments

Comments
 (0)