github.com/m3db/m3@v1.5.0/scripts/proto-gen.sh (about)

     1  #!/bin/bash
     2  
     3  # include poratable readlink
     4  source $(dirname $0)/realpath.sh
     5  
     6  # paranoia, ftw
     7  set -e
     8  
     9  PROTOC_IMAGE_VERSION=${PROTOC_IMAGE_VERSION:-"znly/protoc:0.2.0"}
    10  
    11  # ensure docker is running
    12  docker run --rm hello-world >/dev/null
    13  
    14  UID_FLAGS="-u $(id -u)"
    15  if [[ -n "$BUILDKITE" ]]; then
    16  	UID_FLAGS="-u root"
    17  fi
    18  
    19  PROTO_SRC=$1
    20  for i in "${GOPATH}/src/${PROTO_SRC}"/*; do
    21  	if ! [ -d $i ]; then
    22  		continue
    23  	fi
    24  
    25  	if ls $i/*.proto > /dev/null 2>&1; then
    26  		proto_files=$(ls $i/*.proto | sed -e "s@${GOPATH}@@g")
    27  		echo "generating from ${proto_files}"
    28  		# need the additional m3db_path mount in docker because it's a symlink on the CI.
    29  		m3db_path=$(realpath $GOPATH/src/github.com/m3db/m3)
    30      resolve_protos="Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types"
    31  
    32  		docker run --rm -w /src -v $GOPATH/src:/src -v ${m3db_path}:/src/github.com/m3db/m3 \
    33  		$UID_FLAGS $PROTOC_IMAGE_VERSION \
    34  			 --gogofaster_out=${resolve_protos},plugins=grpc:/src \
    35  			 -I/src -I/src/github.com/m3db/m3/vendor ${proto_files}
    36  	fi
    37  done