Skip to content

Commit

Permalink
Removes the sdk generation tooling from our main build image.
Browse files Browse the repository at this point in the history
Each supported SDK language has its own Dockerfile.
We support 3 commands (gen,build,test) for each SDK.
Add documentation on how to add a new SDK.
  • Loading branch information
Cyril Tovena committed Mar 20, 2019
1 parent cf49d9c commit a651191
Show file tree
Hide file tree
Showing 23 changed files with 470 additions and 101 deletions.
21 changes: 2 additions & 19 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ include ./includes/google-cloud.mk
include ./includes/minikube.mk
include ./includes/kind.mk
include ./includes/website.mk
include ./includes/sdk.mk

# personal includes, excluded from the git repository
-include ./local-includes/*.mk
Expand Down Expand Up @@ -214,21 +215,14 @@ push-release-chart: $(ensure-build-image)
mv /tmp/agones/install/helm/agones $(agones_path)/install/.helm-$(RELEASE_VERSION)/
CHART_DIR=install/.helm-$(RELEASE_VERSION)/agones $(MAKE) push-chart

#build all the sdks
build-sdks: build-sdk-cpp

# Run all tests
test: $(ensure-build-image) test-go test-nodejs test-install-yaml site-test
test: $(ensure-build-image) test-go tesk-sdks test-install-yaml site-test

# Run go tests
test-go:
$(GO_TEST) $(agones_package)/pkg/... \
$(agones_package)/sdks/... $(agones_package)/cmd/...

# Run Node.js SDK tests
test-nodejs:
docker run --rm $(common_mounts) -w $(mount_path)/sdks/nodejs $(build_tag) npm install-test

# Runs end-to-end tests on the current configured cluster
# For minikube user the minikube-test-e2e targets
test-e2e: $(ensure-build-image)
Expand Down Expand Up @@ -339,10 +333,6 @@ push-ping-image: $(ensure-build-image)
build-ping-image: $(ensure-build-image) build-ping-binary
docker build $(agones_path)/cmd/ping/ --tag=$(ping_tag) $(DOCKER_BUILD_ARGS)

# Build the cpp sdk linux archive
build-sdk-cpp: $(ensure-build-image)
docker run --rm $(common_mounts) -w $(mount_path)/sdks/cpp $(build_tag) make build install archive VERSION=$(VERSION)

# push the gameservers sidecar image
push-agones-sdk-image: $(ensure-build-image)
docker push $(sidecar_tag)
Expand All @@ -355,13 +345,6 @@ gen-install: $(ensure-build-image)
--set agones.crds.cleanupOnDelete=false \
> $(mount_path)/install/yaml/install.yaml'

# Generate the SDK gRPC server and client code
gen-gameservers-sdk-grpc: $(ensure-build-image)
docker run --rm $(common_mounts) -w $(mount_path) $(build_tag) /root/gen-grpc-go.sh
docker run --rm $(common_mounts) -w $(mount_path) $(build_tag) /root/gen-grpc-cpp.sh
docker run --rm $(common_mounts) -w $(mount_path) $(build_tag) /root/gen-grpc-rust.sh
docker run --rm $(common_mounts) -w $(mount_path) $(build_tag) /root/gen-grpc-nodejs.sh

# Generate the client for our CustomResourceDefinition
gen-crd-client: $(ensure-build-image)
docker run --rm $(common_mounts) -w $(mount_path) $(build_tag) /root/gen-crd-client.sh
Expand Down
58 changes: 6 additions & 52 deletions build/build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# ForceUpdate 6 -- change here if you need to force a rebuild
# ForceUpdate 7 -- change here if you need to force a rebuild

# compiling proto + grpc takes an exceptionally long time
# so we'll use a base from `base` - which is manually built using the below tag.
FROM gcr.io/agones-images/grpc-cxx:1.16.1
FROM debian:stretch

RUN apt-get update && \
apt-get install -y wget psmisc rsync make python bash-completion zip nano jq graphviz \
gettext-base plantuml && \
apt-get install -y build-essential gnupg curl git wget psmisc rsync make python bash-completion \
zip nano jq graphviz gettext-base plantuml && \
apt-get clean

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

# install rust
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=1.26.1
ENV RUST_ARCH=x86_64-unknown-linux-gnu \
RUSTUP_SHA256=c9837990bce0faab4f6f52604311a19bb8d2cde989bea6a7b605c8e526db6f02
RUN wget -q https://static.rust-lang.org/rustup/archive/1.11.0/${RUST_ARCH}/rustup-init && \
echo "${RUSTUP_SHA256} *rustup-init" | sha256sum -c - && \
chmod +x rustup-init && \
./rustup-init -y --no-modify-path --default-toolchain $RUST_VERSION && \
rm rustup-init && \
rustup --version; \
cargo --version; \
rustc --version;

# install go
WORKDIR /usr/local
ENV GO_VERSION=1.11.5
Expand Down Expand Up @@ -82,26 +57,8 @@ RUN curl -L ${HELM_URL} > /tmp/helm.tar.gz \
&& rm /tmp/helm.tar.gz && rm -rf /tmp/linux-amd64
RUN echo "source <(helm completion bash)" >> /root/.bashrc

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

# install go-proto-gen 1.1
RUN mkdir -p /go/src/github.com/golang && cd /go/src/github.com/golang && \
git clone https://github.com/golang/protobuf.git && \
cd protobuf && git checkout v1.2.0 && \
go install github.com/golang/protobuf/protoc-gen-go

# install rust tooling for SDK generation
RUN cargo install protobuf-codegen --vers 2.0.2
RUN cargo install grpcio-compiler --vers 0.3.0

# install go tooling for development, building and testing
RUN go get -u github.com/golang/dep/cmd/dep && \
go get -u golang.org/x/tools/cmd/goimports
# install go dep for vendoring
RUN go get -u github.com/golang/dep/cmd/dep

# install golang-ci linter
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $GOPATH/bin v1.15.0
Expand All @@ -123,9 +80,6 @@ RUN mkdir /tmp/hugo && \
mv /tmp/hugo/hugo /usr/local/bin/ && \
rm -r /tmp/hugo

RUN curl -sL https://deb.nodesource.com/setup_11.x | bash - && \
apt-get install -y nodejs

# html checker
RUN mkdir /tmp/htmltest && \
wget -O /tmp/htmltest/htmltest.tar.gz https://github.com/wjdp/htmltest/releases/download/v0.10.1/htmltest_0.10.1_linux_amd64.tar.gz && \
Expand Down
64 changes: 64 additions & 0 deletions build/build-sdk-images/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Agones SDKs build

As we seen before GameServers can communicate their current state back to Agones controller using a side car. This sidecar runs a GRPC server handling the communication to Agones, the GameServer connects using a SDK which a thin wrapper around GRPC client code.

By using GRPC, adding more languages should be pretty straigthforward as it supports code generation for many of them.

> if your language doesn't support GRPC you can still create a SDK by connecting to the HTTP GRPC gateway.
This guide explains how to build, test and generate GRPC code for our SDKs but also how to add a new language.

## How it works

Our build system heavily rely on Docker and make, but that's all you need. The rest of the GRPC tooling and language specific dependencies are installed inside Docker images via Dockerfile.

We separated each language specific tooling in their on Docker image, this way building them will be faster and easier to maintain.

A base GRPC image with protoc is provided, every other images inherit from it via the `FROM` Dockerfile syntax. This way SDKs grpc code is generated from the same version of our SDK sidecar.

## Targets

We currently support 3 commands per SDK:

- `gen` to generate GRPC required by SDKs.
- `test` to run SDKs tests.
- `build` to build SDKs binaries.

> All commands might not be required for all SDKs. (e.g. build is only used for our cpp SDK)
SDKs build scripts and Dockerfile are stored in a folder in this directory.

To run tests for a single SDK use with the `SDK_FOLDER` of your choice:

```bash
make test-sdk SDK_FOLDER=go
```

You can also run all SDKs tests by using `make test-sdks`.

To generate GRPC code and build binaries you can respectively use:

```bash
make gen-sdk-grpc SDK_FOLDER=go
make build-sdk SDK_FOLDER=go

# for all SDKs
make gen-all-sdk-grpc
make build-sdks
```

## Adding support for a new language

Makefile targets run docker containers built from Dockerfile in each folder found in this directory. This means you don't need to change our Makefile

Simply create a new directory with the name of your SDK. Then copy our [template](./tool/template) folder content you SDK folder.

Edit the Dockerfile to install all dependencies you need to generate, build and test your SDK. (you should not need to change the base image)

> As explained in our [SDK documentation](https://agones.dev/site/docs/guides/client-sdks/) you have 2 options HTTP or GRPC. If you are using HTTP you don't need to use our base SDK image so feel free to use the distribution of your choice.
Then add your steps in `build.sh`, `test.sh` and `gen.sh` script files.

You should now be able to use your `SDK_FOLDER` with our [Makefile targets](#targets).

Each targets will ensure that your Dockerfile is built and then run the image with a pre-defined command. The Agones code source repository is mounted in the working directory inside the container and you can also access the current Agones version via the environment variable `VERSION`.
23 changes: 23 additions & 0 deletions build/build-sdk-images/cpp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2018 Google Inc. 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.
ARG BASE_IMAGE=agones-build-sdk-base:latest
FROM $BASE_IMAGE

RUN apt-get update && \
apt-get install -y zip && \
apt-get clean

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

# Copyright 2017 Google Inc. 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 -x

cd ./sdks/cpp
make build install archive VERSION=$VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -x
set -ex

header() {
cat /go/src/agones.dev/agones/build/boilerplate.go.txt $1 >> /tmp/cpp/$1 && mv /tmp/cpp/$1 .
Expand Down
40 changes: 40 additions & 0 deletions build/build-sdk-images/go/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2019 Google Inc. 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.
ARG BASE_IMAGE=agones-build-sdk-base:latest
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.11.5
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
RUN mkdir -p /go/src/github.com/golang && cd /go/src/github.com/golang && \
git clone https://github.com/golang/protobuf.git && \
cd protobuf && git checkout v1.2.0 && \
go install github.com/golang/protobuf/protoc-gen-go && \
go get -u golang.org/x/tools/cmd/goimports


# code generation scripts
COPY *.sh /root/
RUN chmod +x /root/*.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -x
set -ex

mkdir -p /go/src/
cp -r /go/src/agones.dev/agones/vendor/* /go/src/
Expand Down
18 changes: 18 additions & 0 deletions build/build-sdk-images/go/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

# Copyright 2017 Google Inc. 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 -x
go test -v -race agones.dev/agones/sdks/...
22 changes: 22 additions & 0 deletions build/build-sdk-images/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2019 Google Inc. 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.
ARG BASE_IMAGE=agones-build-sdk-base:latest
FROM $BASE_IMAGE

RUN curl -sL https://deb.nodesource.com/setup_11.x | bash - && \
apt-get install -y nodejs

# code generation scripts
COPY *.sh /root/
RUN chmod +x /root/*.sh
File renamed without changes.
19 changes: 19 additions & 0 deletions build/build-sdk-images/node/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

# Copyright 2017 Google Inc. 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 -x
cd ./sdks/nodejs
npm install-test
Loading

0 comments on commit a651191

Please sign in to comment.