agones.dev/agones@v1.54.0/build/build-allocation-images/go/gen.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright 2019 Google LLC All Rights Reserved.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  set -ex
    18  
    19  header() {
    20      cat /go/src/agones.dev/agones/build/boilerplate.go.txt "$1" | sponge "$1"
    21  }
    22  
    23  export GO111MODULE=on
    24  
    25  mkdir -p /go/src/
    26  cp -r /go/src/agones.dev/agones/vendor/* /go/src/
    27  
    28  cd /go/src/agones.dev/agones
    29  go install -mod=vendor github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway
    30  go install -mod=vendor github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
    31  
    32  outputpath=pkg/allocation/go
    33  protopath=proto/allocation
    34  googleapis=/go/src/agones.dev/agones/proto/googleapis
    35  gatewaygrpc=/go/src/agones.dev/agones/proto/grpc-gateway
    36  protofile=${protopath}/allocation.proto
    37  processor_protofile=${protopath}/processor.proto
    38  
    39  rm ./${outputpath}/allocation.pb.go || true
    40  rm ./${outputpath}/allocation.gw.pb.go || true
    41  rm ./${outputpath}/allocation_grpc.pb.go || true
    42  rm ./${outputpath}/processor.pb.go || true
    43  rm ./${outputpath}/processor_grpc.pb.go || true
    44  
    45  # generate the go code
    46  protoc -I ${googleapis} -I ${gatewaygrpc} -I . -I ./vendor ${protofile} --go_out=proto --go-grpc_opt=require_unimplemented_servers=false --go-grpc_out=proto
    47  protoc -I ${googleapis} -I ${gatewaygrpc} -I . -I ./vendor ${processor_protofile} --go_out=proto --go-grpc_opt=require_unimplemented_servers=false --go-grpc_out=proto
    48  
    49  # generate grpc gateway
    50  protoc -I ${googleapis} -I ${gatewaygrpc} -I . -I ./vendor ${protofile} --go_out=proto --grpc-gateway_out=logtostderr=true:proto
    51  
    52  # generate openapi v2
    53  protoc -I ${googleapis} -I ${gatewaygrpc} -I . -I ./vendor ${protofile} --openapiv2_opt=logtostderr=true,simple_operation_ids=true,disable_default_errors=true --openapiv2_out=json_names_for_fields=false,logtostderr=true:.
    54  
    55  # hard coding because protoc-gen-openapiv2 doesn't work well in description
    56  cat ./${protopath}/allocation.swagger.json | jq '.definitions.allocationAllocationRequest.properties.multiClusterSetting |= .+{"description": "If specified, multi-cluster policies are applied. Otherwise, allocation will happen locally."}' | sponge ./${protopath}/allocation.swagger.json
    57  cat ./${protopath}/allocation.swagger.json | jq '.definitions.allocationAllocationRequest.properties.requiredGameServerSelector |= .+{"description": "Deprecated: Please use gameServerSelectors instead. This field is ignored if the\ngameServerSelectors field is set\nThe required allocation. Defaults to all GameServers."}' | sponge ./${protopath}/allocation.swagger.json
    58  cat ./${protopath}/allocation.swagger.json | jq '.definitions.allocationAllocationRequest.properties.scheduling |= .+{"description": "Scheduling strategy. Defaults to \"Packed\"."}' | sponge ./${protopath}/allocation.swagger.json
    59  cat ./${protopath}/allocation.swagger.json | jq '.definitions.allocationAllocationRequest.properties.metaPatch |= .+{"title": "Deprecated: Please use metadata instead. This field is ignored if the\nmetadata field is set"}' | sponge ./${protopath}/allocation.swagger.json
    60  cat ./${protopath}/allocation.swagger.json | jq '.definitions.allocationAllocationRequest.properties.metadata |= .+{"title": "Metadata is optional custom metadata that is added to the game server at\nallocation. You can use this to tell the server necessary session data"}' | sponge ./${protopath}/allocation.swagger.json
    61  cat ./${protopath}/allocation.swagger.json | jq '.definitions.allocationMultiClusterSetting.properties.policySelector |= .+{"description": "Selects multi-cluster allocation policies to apply. If not specified, all multi-cluster allocation policies are to be applied."}' | sponge ./${protopath}/allocation.swagger.json
    62  
    63  jq 'del(.schemes[] | select(. == "http"))' ./${protopath}/allocation.swagger.json > ./${outputpath}/allocation.swagger.json
    64  
    65  rm ${protopath}/allocation.swagger.json
    66  
    67  header ${protopath}/allocation.pb.go
    68  header ${protopath}/allocation.pb.gw.go
    69  header ${protopath}/allocation_grpc.pb.go
    70  header ${protopath}/processor.pb.go
    71  header ${protopath}/processor_grpc.pb.go
    72  
    73  mv ${protopath}/allocation.pb.go ${outputpath}/allocation.pb.go
    74  mv ${protopath}/allocation.pb.gw.go ${outputpath}/allocation.pb.gw.go
    75  mv ${protopath}/allocation_grpc.pb.go ${outputpath}/allocation_grpc.pb.go
    76  
    77  mv ${protopath}/processor.pb.go ${outputpath}/processor.pb.go
    78  mv ${protopath}/processor_grpc.pb.go ${outputpath}/processor_grpc.pb.go
    79  
    80  goimports -w ./${outputpath}