Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding make file to generate allocation go from proto #1041

Merged
merged 2 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ include ./includes/minikube.mk
include ./includes/kind.mk
include ./includes/website.mk
include ./includes/sdk.mk
include ./includes/allocation.mk

# _____ _
# |_ _|_ _ _ __ __ _ ___| |_ ___
Expand Down
38 changes: 38 additions & 0 deletions build/build-allocation-images/go/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2019 Google LLC All Rights Reserved.
roberthbailey marked this conversation as resolved.
Show resolved Hide resolved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ARG BASE_IMAGE=agones-build-allocator-base:latest
pooneh-m marked this conversation as resolved.
Show resolved Hide resolved
FROM $BASE_IMAGE

RUN apt-get update && \
apt-get install -y wget jq && \
apt-get clean

# install go
WORKDIR /usr/local
ENV GO_VERSION=1.12
ENV GO111MODULE=on
ENV GOPATH /go
RUN wget -q https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && \
tar -xzf go${GO_VERSION}.linux-amd64.tar.gz && rm go${GO_VERSION}.linux-amd64.tar.gz && mkdir -p ${GOPATH}

ENV PATH /usr/local/go/bin:/go/bin:$PATH

# install go-proto-gen 1.1
pooneh-m marked this conversation as resolved.
Show resolved Hide resolved
RUN go get github.com/golang/protobuf/[email protected] && \
go get -u golang.org/x/tools/cmd/goimports


# code generation scripts
COPY *.sh /root/
RUN chmod +x /root/*.sh
51 changes: 51 additions & 0 deletions build/build-allocation-images/go/gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

# Copyright 2019 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -ex

export GO111MODULE=on

mkdir -p /go/src/
cp -r /go/src/agones.dev/agones/vendor/* /go/src/

cd /go/src/agones.dev/agones
go install -mod=vendor github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go install -mod=vendor github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger

outputpath=./pkg/allocation/go
protopath=proto/allocation/v1alpha1
googleapis=/go/src/agones.dev/agones/vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis
protofile=${protopath}/allocation.proto


protoc -I ${googleapis} -I . -I ./vendor ${protofile} --go_out=plugins=grpc:.
protoc -I ${googleapis} -I . -I ./vendor ${protofile} --grpc-gateway_out=logtostderr=true:.
protoc -I ${googleapis} -I . -I ./vendor ${protofile} --swagger_out=logtostderr=true:.
jq 'del(.schemes[] | select(. == "http"))' ./${protopath}/allocation.swagger.json > ./${outputpath}/allocation.swagger.json

cat ./build/boilerplate.go.txt ./${protopath}/allocation.pb.go >> ./allocation.pb.go
cat ./build/boilerplate.go.txt ./${protopath}/allocation.pb.gw.go >> ./allocation.pb.gw.go

goimports -w ./allocation.pb.go
goimports -w ./allocation.pb.gw.go

mv ./allocation.pb.go ./${outputpath}/allocation.pb.go
mv ./allocation.pb.gw.go ./${outputpath}/allocation.gw.pb.go

rm ./${protopath}/allocation.pb.go
rm ./${protopath}/allocation.pb.gw.go
rm ./${protopath}/allocation.swagger.json

57 changes: 57 additions & 0 deletions build/includes/allocation.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2019 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# ____ ____ ____ _____ _ _
# __ _| _ \| _ \ / ___| |_ _|__ ___ | (_)_ __ __ _
# / _` | |_) | |_) | | | |/ _ \ / _ \| | | '_ \ / _` |
# | (_| | _ <| __/| |___ | | (_) | (_) | | | | | | (_| |
# \__, |_| \_\_| \____| |_|\___/ \___/|_|_|_| |_|\__, |
# |___/ |___/

build_base_version = $(call sha,$(build_path)/build-sdk-images/tool/base/Dockerfile)
build_base_tag = agones-build-allocation-base:$(build_base_version)

# Calculate sha hash of sha hashes of all files in a specified ALLOCATION_FOLDER
allocation_build_folder = build-allocation-images/
build_allocation_version = $(call sha_dir,$(build_path)/$(allocation_build_folder)/$(ALLOCATION_FOLDER)/*)
build_allocation_prefix = agones-build-allocation-
ALLOCATION_FOLDER ?= go
ALLOCATION_IMAGE_TAG=$(build_allocation_prefix)$(ALLOCATION_FOLDER):$(build_allocation_version)

.PHONY: gen-allocation-grpc

# Builds the base GRPC docker image.
build-build-image-base: DOCKER_BUILD_ARGS= --build-arg GRPC_RELEASE_TAG=$(grpc_release_tag)
build-build-image-base:
docker build --tag=$(build_base_tag) $(build_path)build-sdk-images/tool/base $(DOCKER_BUILD_ARGS)

# create the GRPC base build image if it doesn't exist
ensure-build-image-base:
$(MAKE) ensure-image IMAGE_TAG=$(build_base_tag) BUILD_TARGET=build-build-image-base

# create the build image allocation if it doesn't exist
ensure-build-allocation-image:
$(MAKE) ensure-image IMAGE_TAG=$(ALLOCATION_IMAGE_TAG) BUILD_TARGET=build-build-allocation-image ALLOCATION_FOLDER=$(ALLOCATION_FOLDER)

# Builds the docker image
build-build-allocation-image: ensure-build-image-base
docker build --tag=$(ALLOCATION_IMAGE_TAG) $(build_path)$(allocation_build_folder)$(ALLOCATION_FOLDER) --build-arg BASE_IMAGE=$(build_base_tag)

# Generates grpc server and client for a single allocation, use ALLOCATION_FOLDER variable to specify the allocation folder.
gen-allocation-grpc:
cd $(allocation_build_folder); \
cd - ; \
$(MAKE) ensure-build-allocation-image ALLOCATION_FOLDER=$(ALLOCATION_FOLDER) ; \
docker run --rm $(common_mounts) -e "VERSION=$(VERSION)" $(ALLOCATION_IMAGE_TAG) gen
135 changes: 135 additions & 0 deletions pkg/allocation/go/allocation.gw.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading