forked from longhorn/longhorn-instance-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_grpc.sh
executable file
·42 lines (35 loc) · 2.09 KB
/
generate_grpc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
set -e
# check and download dependency for gRPC code generate
if [ ! -e ./proto/vendor/protobuf/src/google/protobuf ]; then
rm -rf ./proto/vendor/protobuf/src/google/protobuf
DIR="./proto/vendor/protobuf/src/google/protobuf"
mkdir -p $DIR
wget https://raw.githubusercontent.com/protocolbuffers/protobuf/v3.9.0/src/google/protobuf/empty.proto -P $DIR
fi
DIR="./proto/vendor/github.com/longhorn/longhorn-engine/proto/ptypes"
if [ ! -e ${DIR} ]; then
rm -rf ${DIR}
mkdir -p $DIR
wget https://raw.githubusercontent.com/longhorn/longhorn-engine/master/proto/ptypes/common.proto -P $DIR
wget https://raw.githubusercontent.com/longhorn/longhorn-engine/master/proto/ptypes/controller.proto -P $DIR
wget https://raw.githubusercontent.com/longhorn/longhorn-engine/master/proto/ptypes/syncagent.proto -P $DIR
fi
PKG_DIR="pkg/imrpc"
TMP_DIR_BASE=".protobuild"
TMP_DIR="${TMP_DIR_BASE}/github.com/longhorn/longhorn-instance-manager/pkg/imrpc/"
mkdir -p "${TMP_DIR}"
cp -a "${PKG_DIR}"/*.proto "${TMP_DIR}"
for PROTO in common imrpc proxy disk instance; do
mkdir -p "integration/rpc/${PROTO}"
python3 -m grpc_tools.protoc -I "${TMP_DIR_BASE}" -I "proto/vendor/" -I "proto/vendor/protobuf/src/" --python_out=integration/rpc/${PROTO} --grpc_python_out=integration/rpc/${PROTO} "${TMP_DIR}/${PROTO}.proto"
protoc -I ${TMP_DIR_BASE}/ -I proto/vendor/ -I proto/vendor/protobuf/src/ "${TMP_DIR}/${PROTO}.proto" --go_out=plugins=grpc:"${TMP_DIR_BASE}"
mv "${TMP_DIR}/${PROTO}.pb.go" "${PKG_DIR}/${PROTO}.pb.go"
# Known issue: https://github.com/grpc/grpc/issues/10790
mv integration/rpc/${PROTO}/github.com/longhorn/longhorn_instance_manager/pkg/imrpc/${PROTO}_pb2_grpc.py integration/rpc/${PROTO}/github/com/longhorn/longhorn_instance_manager/pkg/imrpc/${PROTO}_pb2_grpc.py
rm -rf integration/rpc/${PROTO}/github.com
if [ "${PROTO}" != "common" ]; then
cp -a integration/rpc/common/github/com/longhorn/longhorn_instance_manager/pkg/imrpc/*.py integration/rpc/${PROTO}/github/com/longhorn/longhorn_instance_manager/pkg/imrpc/
fi
done
rm -rf "${TMP_DIR_BASE}"