Skip to content

Commit

Permalink
generate go code from protos (#392)
Browse files Browse the repository at this point in the history
* generate go code from protos

* bazel

* check gencode without git

* dont get workspace status when checking gen go

* SOURCE_VERSION is a file not an env-var
  • Loading branch information
yuval-k authored Jan 2, 2025
1 parent f39969c commit 33a74fc
Show file tree
Hide file tree
Showing 41 changed files with 15,973 additions and 398 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ build-arm:
.PHONY: docker-release-arm
docker-release-arm:
cd ci && docker build -f Dockerfile-arm -t $(REGISTRY)/envoy-gloo-arm:$(VERSION) . && docker push $(REGISTRY)/envoy-gloo-arm:$(VERSION)

gengo:
./ci/gen_go.sh
cd go; go mod tidy
cd go; go build ./...

check-gencode:
touch SOURCE_VERSION
CHECK=1 ./ci/gen_go.sh
rm SOURCE_VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package envoy.config.filter.http.aws_lambda.v2;
option java_package = "io.envoyproxy.envoy.config.filter.http.aws_lambda.v2";
option java_outer_classname = "AwsLambdaProto";
option java_multiple_files = true;
option go_package = "github.com/solo-io/envoy-gloo/go/config/filter/http/aws_lambda/v2;v2";
import "google/protobuf/wrappers.proto";
import "google/protobuf/duration.proto";
import "validate/validate.proto";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package envoy.config.filter.http.nats.streaming.v2;
option java_package = "io.envoyproxy.envoy.config.filter.http.nats.streaming.v2";
option java_outer_classname = "NatsStreamingProto";
option java_multiple_files = true;
option go_package = "github.com/solo-io/envoy-gloo/go/config/filter/http/nats/streaming/v2;v2";

import "google/protobuf/duration.proto";
import "validate/validate.proto";

Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/filter/http/nats/streaming/v2/payload.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package pb;
option java_package = "io.envoyproxy.pb";
option java_outer_classname = "PayloadProto";
option java_multiple_files = true;
option go_package = "github.com/solo-io/envoy-gloo/go/config/filter/http/nats/streaming/v2;v2";

message Payload {
map<string, string> headers = 1;
bytes body = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package envoy.api.v2.filter.http;
option java_package = "io.envoyproxy.envoy.api.v2.filter.http";
option java_outer_classname = "TransformationFilterProto";
option java_multiple_files = true;
option go_package = "transformation";
option go_package = "github.com/solo-io/envoy-gloo/go/config/filter/http/transformation/v2;v2";

import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ package envoy.config.filter.http.upstream_wait.v2;
option java_package = "io.envoyproxy.envoy.config.filter.http.upstream_wait.v2";
option java_outer_classname = "UpstreamWaitFilterProto";
option java_multiple_files = true;
option go_package = "upstream_wait";
option go_package = "github.com/solo-io/envoy-gloo/go/config/filter/http/upstream_wait/v2;v2";

message UpstreamWaitFilterConfig {}
14 changes: 0 additions & 14 deletions api/envoy/config/filter/network/consul_connect/v2/BUILD

This file was deleted.

23 changes: 0 additions & 23 deletions api/envoy/config/filter/network/consul_connect/v2/authorize.proto

This file was deleted.

This file was deleted.

2 changes: 2 additions & 0 deletions api/envoy/type/streaming/protocol.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
syntax = "proto3";
package pb;

option go_package = "github.com/solo-io/envoy-gloo/go/type/streaming;streaming";

// import "github.com/gogo/protobuf/gogoproto/gogo.proto";

// option (gogoproto.marshaler_all) = true;
Expand Down
13 changes: 13 additions & 0 deletions ci/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
steps:
- name: 'envoyproxy/envoy-build-ubuntu:f94a38f62220a2b017878b790b6ea98a0f6c5f9c'
id: 'gengo'
args: ['make', 'check-gencode']
volumes:
- name: 'vol-build'
path: '/build'
env:
- 'COMMIT_SHA=$COMMIT_SHA'
- 'BAZEL_REMOTE_CACHE=https://storage.googleapis.com/envoy-build-cache-solo-io'
- 'BUILD_TYPE=$_BUILD_TYPE'
secretEnv:
- 'GCP_SERVICE_ACCOUNT_KEY'

- name: 'envoyproxy/envoy-build-ubuntu:f94a38f62220a2b017878b790b6ea98a0f6c5f9c'
id: 'do_ci'
args: ['ci/do_ci.sh', 'release', '//test/extensions/...', '//test/common/...', '//test/integration/...']
Expand Down
52 changes: 52 additions & 0 deletions ci/gen_go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
set -e
set -x

# copied from bazel_envoy_api_go_build in envoy's do_ci.sh

# TODO: if we ever have protos using other protos from our repos, we'll need to fix this to not be envoyproxy
GO_IMPORT_BASE="github.com/envoyproxy/go-control-plane/api/envoy"
GO_TARGETS=(//api/envoy/...)
read -r -a GO_PROTOS <<< "$(bazel query "${BAZEL_GLOBAL_OPTIONS[@]}" "kind('go_proto_library', ${GO_TARGETS[*]})" | tr '\n' ' ')"
bazel build "${BAZEL_BUILD_OPTIONS[@]}" \
--experimental_proto_descriptor_sets_include_source_info \
--remote_download_outputs=all \
"${GO_PROTOS[@]}"
rm -rf build_go
mkdir -p build_go
echo "Copying go protos -> build_go"
BAZEL_BIN="$(bazel info "${BAZEL_BUILD_OPTIONS[@]}" bazel-bin)"
for GO_PROTO in "${GO_PROTOS[@]}"; do
# strip @envoy_api//
RULE_DIR="$(echo "${GO_PROTO:12}" | cut -d: -f1)"
PROTO="$(echo "${GO_PROTO:12}" | cut -d: -f2)"
INPUT_DIR="${BAZEL_BIN}/api/envoy/${RULE_DIR}/${PROTO}_/${GO_IMPORT_BASE}/${RULE_DIR}"
OUTPUT_DIR="build_go/${RULE_DIR}"
mkdir -p "$OUTPUT_DIR"
if [[ ! -e "$INPUT_DIR" ]]; then
echo "Unable to find input ${INPUT_DIR}" >&2
exit 1
fi
# echo "Copying go files ${INPUT_DIR} -> ${OUTPUT_DIR}"
while read -r GO_FILE; do
if [[ "$GO_FILE" = *.validate.go ]]; then
sed -i '1s;^;//go:build !disable_pgv\n;' "$GO_FILE"
fi

# if check is not empty, then we will check diff; otherwise we will just copy
if [ -n "$CHECK" ]; then
diff "$GO_FILE" "go/${RULE_DIR}/$(basename "$GO_FILE")"
else
cp -a "$GO_FILE" "$OUTPUT_DIR"
fi
done <<< "$(find "$INPUT_DIR" -name "*.go")"
done

# remove all folders from the `go` folder
if [ -z "$CHECK" ]; then
rm -rf ./go/config
rm -rf ./go/type
cp -r build_go/* ./go
fi

rm -rf build_go
30 changes: 0 additions & 30 deletions e2e/extensions/filters/network/consul_connect/BUILD

This file was deleted.

Empty file.

This file was deleted.

Loading

0 comments on commit 33a74fc

Please sign in to comment.