agones.dev/agones@v1.54.0/build/includes/sdk.mk (about)

     1  # Copyright 2019 Google LLC All Rights Reserved.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  
    16  #         ____  ____   ____   _____           _ _
    17  #    __ _|  _ \|  _ \ / ___| |_   _|__   ___ | (_)_ __   __ _
    18  #   / _` | |_) | |_) | |       | |/ _ \ / _ \| | | '_ \ / _` |
    19  #  | (_| |  _ <|  __/| |___    | | (_) | (_) | | | | | | (_| |
    20  #   \__, |_| \_\_|    \____|   |_|\___/ \___/|_|_|_| |_|\__, |
    21  #   |___/                                               |___/
    22  
    23  grpc_release_tag = v1.76.0
    24  
    25  build_sdk_base_version = $(call sha,$(build_path)/build-sdk-images/tool/base/Dockerfile)_$(grpc_release_tag)
    26  build_sdk_base_tag = agones-build-sdk-base:$(build_sdk_base_version)
    27  
    28  # Calculate sha hash of sha hashes of all files in a specified SDK_FOLDER
    29  build_sdk_version = $(call sha_dir,$(build_path)/build-sdk-images/$(SDK_FOLDER)/*)
    30  build_sdk_base_remote_tag = $(REGISTRY)/$(build_sdk_base_tag)
    31  build_sdk_prefix = agones-build-sdk-
    32  sdk_build_folder = build-sdk-images/
    33  examples_folder = ../examples/
    34  SDK_FOLDER ?= go
    35  COMMAND ?= gen
    36  SDK_IMAGE_TAG=$(build_sdk_prefix)$(SDK_FOLDER):$(build_sdk_version)
    37  DEFAULT_CONFORMANCE_TESTS = ready,allocate,setlabel,setannotation,gameserver,health,shutdown,watch,reserve
    38  ALPHA_CONFORMANCE_TESTS = getplayercapacity,setplayercapacity,playerconnect,playerdisconnect,getplayercount,isplayerconnected,getconnectedplayers
    39  # TODO: Move Counter and List tests into DEFAULT_CONFORMANCE_TESTS once the they are written for all SDKs
    40  COUNTS_AND_LISTS_TESTS = getcounter,updatecounter,setcountcounter,setcapacitycounter,getlist,updatelist,addlistvalue,removelistvalue
    41  
    42  .PHONY: test-sdks test-sdk build-sdks build-sdk gen-all-sdk-grpc gen-sdk-grpc run-all-sdk-command run-sdk-command build-example
    43  
    44  # Tests all the sdks
    45  test-sdks: COMMAND := test
    46  test-sdks: run-all-sdk-command
    47  
    48  # Tests a single sdk, use SDK_FOLDER variable to specify the sdk folder.
    49  test-sdk: COMMAND := test
    50  test-sdk: run-sdk-command
    51  
    52  # Builds all the sdks
    53  build-sdks: COMMAND := build
    54  build-sdks: run-all-sdk-command
    55  
    56  # Builds a single sdk, use SDK_FOLDER variable to specify the sdk folder.
    57  build-sdk: COMMAND := build
    58  build-sdk: run-sdk-command
    59  
    60  # Generates grpc server and client for all supported languages.
    61  gen-all-sdk-grpc: COMMAND := gen
    62  gen-all-sdk-grpc: run-all-sdk-command
    63  
    64  # Generates grpc server and client for a single sdk, use SDK_FOLDER variable to specify the sdk folder.
    65  gen-sdk-grpc: COMMAND := gen
    66  gen-sdk-grpc: run-sdk-command
    67  
    68  # Runs a command on all supported languages, use COMMAND variable to select which command.
    69  run-all-sdk-command: run-sdk-command-go run-sdk-command-rust run-sdk-command-cpp run-sdk-command-node run-sdk-command-restapi run-sdk-command-csharp
    70  
    71  run-sdk-command-node:
    72  	$(MAKE) run-sdk-command COMMAND=$(COMMAND) SDK_FOLDER=node
    73  
    74  run-sdk-command-cpp:
    75  	$(MAKE) run-sdk-command COMMAND=$(COMMAND) SDK_FOLDER=cpp
    76  
    77  run-sdk-command-rust:
    78  	$(MAKE) run-sdk-command COMMAND=$(COMMAND) SDK_FOLDER=rust
    79  
    80  run-sdk-command-go:
    81  	$(MAKE) run-sdk-command COMMAND=$(COMMAND) SDK_FOLDER=go
    82  
    83  run-sdk-command-restapi:
    84  	$(MAKE) run-sdk-command COMMAND=$(COMMAND) SDK_FOLDER=restapi
    85  
    86  run-sdk-command-csharp:
    87  	$(MAKE) run-sdk-command COMMAND=$(COMMAND) SDK_FOLDER=csharp
    88  
    89  # Runs a command for a specific SDK if it exists.
    90  run-sdk-command:
    91  	@cd $(sdk_build_folder); \
    92  	if [ "$(SDK_FOLDER)" != "tool" ] && [ -f $(SDK_FOLDER)/$(COMMAND).sh ] ; then \
    93  		cd - ; \
    94  		$(MAKE) ensure-build-sdk-image SDK_FOLDER=$(SDK_FOLDER) ; \
    95  		docker run --rm $(common_mounts) -e "VERSION=$(VERSION)" \
    96  			$(DOCKER_RUN_ARGS) $(SDK_IMAGE_TAG) $(COMMAND) ; \
    97  	else \
    98  		echo "Command $(COMMAND) not found - nothing to execute" ; \
    99  	fi
   100  
   101  # Builds the base GRPC docker image.
   102  build-build-sdk-image-base: DOCKER_BUILD_ARGS= --build-arg GRPC_RELEASE_TAG=$(grpc_release_tag)
   103  build-build-sdk-image-base:
   104  	docker build --tag=$(build_sdk_base_tag) $(build_path)build-sdk-images/tool/base $(DOCKER_BUILD_ARGS)
   105  
   106  # Builds the docker image used by commands for a specific sdk
   107  build-build-sdk-image: DOCKER_BUILD_ARGS= --build-arg BASE_IMAGE=$(build_sdk_base_tag)
   108  build-build-sdk-image: ensure-build-sdk-image-base
   109  		docker build --tag=$(SDK_IMAGE_TAG) $(build_path)build-sdk-images/$(SDK_FOLDER) $(DOCKER_BUILD_ARGS)
   110  
   111  # attempt to pull the image, if it exists and rename it to the local tag
   112  # exit's clean if it doesn't exist, so can be used on CI
   113  pull-build-sdk-base-image:
   114  	$(MAKE) pull-remote-build-image REMOTE_TAG=$(build_sdk_base_remote_tag) LOCAL_TAG=$(build_sdk_base_tag)
   115  
   116  # push the local build image up to your repository
   117  push-build-sdk-base-image:
   118  	$(MAKE) push-remote-build-image REMOTE_TAG=$(build_sdk_base_remote_tag) LOCAL_TAG=$(build_sdk_base_tag)
   119  
   120  # create the sdk base build image if it doesn't exist
   121  ensure-build-sdk-image-base:
   122  	$(MAKE) ensure-image IMAGE_TAG=$(build_sdk_base_tag) BUILD_TARGET=build-build-sdk-image-base
   123  
   124  # create the build image sdk if it doesn't exist
   125  ensure-build-sdk-image:
   126  	$(MAKE) ensure-image IMAGE_TAG=$(SDK_IMAGE_TAG) BUILD_TARGET=build-build-sdk-image SDK_FOLDER=$(SDK_FOLDER)
   127  
   128  # Run SDK conformance Sidecar server in docker in order to run
   129  # SDK client test against it. Useful for test development
   130  run-sdk-conformance-local: TIMEOUT ?= 40
   131  run-sdk-conformance-local: TESTS ?= ready,allocate,setlabel,setannotation,gameserver,health,shutdown,watch,reserve
   132  run-sdk-conformance-local: FEATURE_GATES ?=
   133  run-sdk-conformance-local: ensure-agones-sdk-image
   134  	docker run -e "ADDRESS=" -p 9357:9357 -p 9358:9358 \
   135  	 -e "TEST=$(TESTS)" -e "TIMEOUT=$(TIMEOUT)" -e "FEATURE_GATES=$(FEATURE_GATES)" $(sidecar_linux_amd64_tag)
   136  
   137  # Run SDK conformance test, previously built, for a specific SDK_FOLDER
   138  # Sleeps the start of the sidecar to test that the SDK blocks on connection correctly
   139  run-sdk-conformance-no-build: TIMEOUT ?= 40
   140  run-sdk-conformance-no-build: RANDOM := $(shell bash -c 'echo $$RANDOM')
   141  run-sdk-conformance-no-build: DELAY ?= $(shell bash -c "echo $$[ ($(RANDOM) % 5 ) + 1 ]")
   142  run-sdk-conformance-no-build: TESTS ?= $(DEFAULT_CONFORMANCE_TESTS)
   143  run-sdk-conformance-no-build: GRPC_PORT ?= 9357
   144  run-sdk-conformance-no-build: HTTP_PORT ?= 9358
   145  run-sdk-conformance-no-build: FEATURE_GATES ?=
   146  run-sdk-conformance-no-build: ensure-agones-sdk-image
   147  run-sdk-conformance-no-build: ensure-build-sdk-image
   148  	DOCKER_RUN_ARGS="--net host -e AGONES_SDK_GRPC_PORT=$(GRPC_PORT) -e AGONES_SDK_HTTP_PORT=$(HTTP_PORT) -e FEATURE_GATES='$(FEATURE_GATES)' $(DOCKER_RUN_ARGS)" COMMAND=sdktest $(MAKE) run-sdk-command & \
   149  	CONFORMANCE_TEST_PID=$$! && \
   150  	docker run -p $(GRPC_PORT):$(GRPC_PORT) -p $(HTTP_PORT):$(HTTP_PORT) -e "FEATURE_GATES=$(FEATURE_GATES)" -e "ADDRESS=" -e "TEST=$(TESTS)" -e "SDK_NAME=$(SDK_FOLDER)" -e "TIMEOUT=$(TIMEOUT)" -e "DELAY=$(DELAY)" \
   151  	--net=host $(sidecar_linux_amd64_tag) --grpc-port $(GRPC_PORT) --http-port $(HTTP_PORT) && \
   152  	wait $$CONFORMANCE_TEST_PID
   153  
   154  # Run SDK conformance test for a specific SDK_FOLDER
   155  run-sdk-conformance-test: TRIES=5
   156  run-sdk-conformance-test: ensure-agones-sdk-image
   157  run-sdk-conformance-test: ensure-build-sdk-image
   158  	@echo "\n\n^^^ Building: $(SDK_FOLDER)\n\n"
   159  	$(MAKE) run-sdk-command COMMAND=build-sdk-test
   160  	@for try in `seq 1 $(TRIES)`; do \
   161  	  echo "\n\n>>> Starting: ($$try/$(TRIES)) $(SDK_FOLDER)\n\n" && \
   162  	  $(MAKE) run-sdk-conformance-no-build && echo "\n\n+++ Success: ($$try/$(TRIES)) $(SDK_FOLDER)\n\n" && break || \
   163  	    echo "\n\n*** Failure: ($$try/$(TRIES)) $(SDK_FOLDER)\n\n" && false; \
   164  	done
   165  
   166  run-sdk-conformance-test-cpp:
   167  	$(MAKE) run-sdk-conformance-test SDK_FOLDER=cpp GRPC_PORT=9003 HTTP_PORT=9103
   168  
   169  run-sdk-conformance-test-node:
   170  	# run with on-by-default (Beta) feature flags enabled. If running locally first run `SDK_FOLDER=node make test-sdk` to build dependencies.
   171  	$(MAKE) run-sdk-conformance-test SDK_FOLDER=node GRPC_PORT=9002 HTTP_PORT=9102 TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(COUNTS_AND_LISTS_TESTS)
   172  
   173  run-sdk-conformance-test-go:
   174  	# run with on-by-default (Beta) feature flags enabled
   175  	$(MAKE) run-sdk-conformance-test SDK_FOLDER=go GRPC_PORT=9001 HTTP_PORT=9101 TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(COUNTS_AND_LISTS_TESTS)
   176  	# run with Alpha and Beta feature flags enabled
   177  	$(MAKE) run-sdk-conformance-test SDK_FOLDER=go GRPC_PORT=9001 HTTP_PORT=9101 FEATURE_GATES=$(ALPHA_FEATURE_GATES) TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(ALPHA_CONFORMANCE_TESTS),$(COUNTS_AND_LISTS_TESTS)
   178  
   179  run-sdk-conformance-test-rust:
   180  	# run without feature flags
   181  	$(MAKE) run-sdk-conformance-test SDK_FOLDER=rust GRPC_PORT=9004 HTTP_PORT=9104
   182  	# run without feature flags and with RUN_ASYNC=true
   183  	DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS) -e RUN_ASYNC=true" $(MAKE) run-sdk-conformance-test SDK_FOLDER=rust GRPC_PORT=9004 HTTP_PORT=9104
   184  	# run with feature flags enabled
   185  	$(MAKE) run-sdk-conformance-test SDK_FOLDER=rust GRPC_PORT=9004 HTTP_PORT=9104 FEATURE_GATES=PlayerTracking=true TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(ALPHA_CONFORMANCE_TESTS)
   186  	# run with feature flags enabled and with RUN_ASYNC=true
   187  	DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS) -e RUN_ASYNC=true" $(MAKE) run-sdk-conformance-test SDK_FOLDER=rust GRPC_PORT=9004 HTTP_PORT=9104 FEATURE_GATES=PlayerTracking=true TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(ALPHA_CONFORMANCE_TESTS)
   188  
   189  run-sdk-conformance-test-csharp:
   190  	# run with Beta feature flags enabled
   191  	$(MAKE) run-sdk-conformance-test SDK_FOLDER=csharp GRPC_PORT=9005 HTTP_PORT=9105 FEATURE_GATES=$(BETA_FEATURE_GATES) TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(COUNTS_AND_LISTS_TESTS)
   192  	# run with Alpha feature flags enabled
   193  	$(MAKE) run-sdk-conformance-test SDK_FOLDER=csharp GRPC_PORT=9005 HTTP_PORT=9105 FEATURE_GATES=$(ALPHA_FEATURE_GATES) TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(ALPHA_CONFORMANCE_TESTS)
   194  
   195  run-sdk-conformance-test-rest:
   196  	# (note: the restapi folder doesn't use GRPC_PORT but run-sdk-conformance-no-build defaults it, so we supply a unique value here)
   197  	# run with Beta feature flags enabled
   198  	$(MAKE) run-sdk-conformance-test SDK_FOLDER=restapi GRPC_PORT=9050 HTTP_PORT=9150 FEATURE_GATES=$(BETA_FEATURE_GATES) TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(COUNTS_AND_LISTS_TESTS)
   199  	# run with Alpha feature flags enabled
   200  	$(MAKE) run-sdk-conformance-test SDK_FOLDER=restapi GRPC_PORT=9050 HTTP_PORT=9150 FEATURE_GATES=$(ALPHA_FEATURE_GATES) TESTS=$(DEFAULT_CONFORMANCE_TESTS),$(ALPHA_CONFORMANCE_TESTS)
   201  
   202  	$(MAKE) run-sdk-command COMMAND=clean SDK_FOLDER=restapi
   203  
   204  # Run a conformance test for all SDKs supported
   205  run-sdk-conformance-tests: run-sdk-conformance-test-node run-sdk-conformance-test-go run-sdk-conformance-test-rust run-sdk-conformance-test-rest run-sdk-conformance-test-cpp run-sdk-conformance-test-csharp
   206  
   207  # Clean package directories and binary files left
   208  # after building conformance tests for all SDKs supported
   209  clean-sdk-conformance-tests:
   210  	$(MAKE) run-all-sdk-command COMMAND=clean
   211  
   212  # Start a shell in the SDK image. This is primarily used for publishing packages.
   213  # Using a shell is the easiest, because of Google internal processes and interactive commands required.
   214  sdk-shell:
   215  	$(MAKE) ensure-build-sdk-image SDK_FOLDER=$(SDK_FOLDER)
   216  	docker run --rm -it $(common_mounts) -v ~/.ssh:/tmp/.ssh:ro $(DOCKER_RUN_ARGS) \
   217   	--entrypoint=/root/shell.sh $(SDK_IMAGE_TAG)
   218  
   219  # SDK shell for node
   220  sdk-shell-node:
   221  	$(MAKE) sdk-shell SDK_FOLDER=node
   222  
   223  # SDK shell for csharp
   224  sdk-shell-csharp:
   225  	$(MAKE) sdk-shell SDK_FOLDER=csharp
   226  
   227  # Publish csharp SDK to NuGet
   228  sdk-publish-csharp: RELEASE_VERSION ?= $(base_version)
   229  sdk-publish-csharp:
   230  	$(MAKE) run-sdk-command-csharp COMMAND=publish VERSION=$(RELEASE_VERSION) DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS) -it"
   231  
   232  # SDK shell for rust
   233  sdk-shell-rust:
   234  	$(MAKE) sdk-shell SDK_FOLDER=rust
   235  
   236  # Publish the Rust SDK to crates.io
   237  sdk-publish-rust:
   238  	$(MAKE) run-sdk-command-rust VERSION=$(RELEASE_VERSION) DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS) -it" COMMAND=publish
   239  
   240  # difference in sdks before and after gen-all-sdk-grpc target
   241  test-gen-all-sdk-grpc:
   242  	make gen-all-sdk-grpc
   243  	@echo; \
   244  	echo "=== Diffing workspace after 'make gen-all-sdk-grpc'"; \
   245  	diff_output=$$(git diff HEAD -- ../sdks); \
   246  	diff_output_test_sdk=$$(git diff HEAD -- ../test/sdk); \
   247  	if [ -z "$$diff_output" ] && [ -z "$$diff_output_test_sdk" ]; then \
   248  		echo "+++ Success: No differences found."; \
   249  	else \
   250  		echo "*** Failure: Differences found:"; \
   251  		echo "Changes in ../sdks:"; \
   252  		echo "$$diff_output"; \
   253  		echo "Changes in ../test/sdk:"; \
   254  		echo "$$diff_output_test_sdk"; \
   255  		exit 1; \
   256  	fi