diff --git a/build/Makefile b/build/Makefile index c5d1575be6..f8f4847841 100644 --- a/build/Makefile +++ b/build/Makefile @@ -85,26 +85,7 @@ ping_tag = $(REGISTRY)/agones-ping:$(VERSION) go_version_flags = -ldflags "-X agones.dev/agones/pkg.Version=$(VERSION)" DOCKER_RUN ?= docker run --rm $(common_mounts) -e "KUBECONFIG=/root/.kube/$(kubeconfig_file)" $(DOCKER_RUN_ARGS) $(build_tag) -# ___ ____ ___ _ _ -# / _ \/ ___| |_ _|_ __ ___| |_ _ __| | ___ -# | | | \___ \ | || '_ \ / __| | | | |/ _` |/ _ \ -# | |_| |___) | | || | | | (__| | |_| | (_| | __/ -# \___/|____/ |___|_| |_|\___|_|\__,_|\__,_|\___| -# - -uname := $(shell uname -s) -ifneq ($(findstring Microsoft,$(shell uname -r)),) - osinclude := windows.mk -else ifeq ($(uname),Linux) - osinclude := linux.mk -else ifeq ($(uname),Darwin) - osinclude := macos.mk -endif -include ./includes/$(osinclude) - -# personal includes, excluded from the git repository --include ./local-includes/*.mk ifdef DOCKER_RUN ensure-build-image += ensure-build-image @@ -150,7 +131,7 @@ ifdef LOCAL_GO GO_BUILD_DARWIN_AMD64=GOOS=darwin GOARCH=amd64 go build GO_TEST=go test -v $(RACE_DETECTOR_ARGS) GO_E2E_TEST_ARGS= - PERF_OUTPUT_DIR=$(build_path)/.perf + PERF_OUTPUT_DIR=$(build_path)/.perf go_build_base_path=$(agones_path) endif @@ -159,6 +140,25 @@ ifdef LOCAL_ZIP ZIP_SDK=cd $(agones_path)/cmd/sdk-server/bin && zip -0 endif + +# ___ ____ ___ _ _ +# / _ \/ ___| |_ _|_ __ ___| |_ _ __| | ___ +# | | | \___ \ | || '_ \ / __| | | | |/ _` |/ _ \ +# | |_| |___) | | || | | | (__| | |_| | (_| | __/ +# \___/|____/ |___|_| |_|\___|_|\__,_|\__,_|\___| +# + +uname := $(shell uname -s) +ifneq ($(findstring Microsoft,$(shell uname -r)),) + osinclude := windows.mk +else ifeq ($(uname),Linux) + osinclude := linux.mk +else ifeq ($(uname),Darwin) + osinclude := macos.mk +endif + +include ./includes/$(osinclude) + # ___ _ _ # |_ _|_ __ ___| |_ _ __| | ___ ___ # | || '_ \ / __| | | | |/ _` |/ _ \ __| @@ -166,8 +166,15 @@ endif # |___|_| |_|\___|_|\__,_|\__,_|\___|___/ # +include ./includes/release.mk +include ./includes/google-cloud.mk +include ./includes/minikube.mk +include ./includes/kind.mk include ./includes/website.mk +# personal includes, excluded from the git repository +-include ./local-includes/*.mk + # _____ _ # |_ _|_ _ _ __ __ _ ___| |_ ___ # | |/ _` | '__/ _` |/ _ \ __/ __| @@ -440,52 +447,6 @@ setup-grafana: --set persistence.enabled=$(PVC),server.persistentVolume.size=$(PV_SIZE) \ --set adminPassword=$(PASSWORD) -f $(mount_path)/build/grafana.yaml -# generate a changelog using github-changelog-generator -gen-changelog: RELEASE_VERSION ?= $(base_version) -gen-changelog: - read -p 'Github Token: ' TOKEN && \ - docker run -it --rm -v "$(agones_path)":/project markmandel/github-changelog-generator \ - --user=GoogleCloudPlatform --project=agones \ - --bug-labels=kind/bug --enhancement-labels=kind/feature \ - --breaking-labels=kind/breaking --security-labels=area/security \ - --future-release "v$(RELEASE_VERSION)" \ - --token $$TOKEN - -# Creates a release. Version defaults to the base_version -# - Checks out a release branch -# - Build binaries and images -# - Creates sdk and binary archives, and moves the into the /release folder for upload -# - Creates a zip of the install.yaml, LICENCE and README.md for installation -# - Pushes the current chart version to the helm repository hosted on gcs. -do-release: RELEASE_VERSION ?= $(base_version) -do-release: - @echo "Starting release for version: $(RELEASE_VERSION)" - git checkout -b release-$(RELEASE_VERSION) - $(MAKE) lint test FULL_BUILD=1 - -rm -rf $(agones_path)/release - mkdir $(agones_path)/release - docker run --rm $(common_mounts) -w $(mount_path)/sdks/cpp $(build_tag) make clean - $(MAKE) build-sdks build-agones-sdk-binary VERSION=$(RELEASE_VERSION) REGISTRY=$(release_registry) FULL_BUILD=1 - cp $(agones_path)/cmd/sdk-server/bin/agonessdk-server-$(RELEASE_VERSION).zip $(agones_path)/release - cp $(agones_path)/sdks/cpp/bin/agonessdk-$(RELEASE_VERSION)-runtime-linux-arch_64.tar.gz $(agones_path)/release - cp $(agones_path)/sdks/cpp/bin/agonessdk-$(RELEASE_VERSION)-dev-linux-arch_64.tar.gz $(agones_path)/release - cp $(agones_path)/sdks/cpp/bin/agonessdk-$(RELEASE_VERSION)-src.zip $(agones_path)/release - cd $(agones_path) && zip -r ./release/agones-install-$(RELEASE_VERSION).zip ./README.md ./install ./LICENSE - - # retag the current master commit images with the release tag. - $(MAKE) do-relase-tag-images RELEASE_VERSION=$(RELEASE_VERSION) - - $(MAKE) push-chart VERSION=$(RELEASE_VERSION) - git push -u upstream release-$(RELEASE_VERSION) - - @echo "Now go make the $(RELEASE_VERSION) release on Github!" - -do-relase-tag-images: RELEASE_VERSION ?= $(base_version) -do-relase-tag-images: - docker run --rm $(common_mounts) $(build_tag) gcloud container images add-tag $(release_registry)/agones-controller:$(VERSION) $(release_registry)/agones-controller:$(RELEASE_VERSION) --quiet - docker run --rm $(common_mounts) $(build_tag) gcloud container images add-tag $(release_registry)/agones-sdk:$(VERSION) $(release_registry)/agones-sdk:$(RELEASE_VERSION) --quiet - docker run --rm $(common_mounts) $(build_tag) gcloud container images add-tag $(release_registry)/agones-ping:$(VERSION) $(release_registry)/agones-ping:$(RELEASE_VERSION) --quiet - setup-test-cluster: DOCKER_RUN_ARGS+=--network=host setup-test-cluster: $(ensure-build-image) $(DOCKER_RUN) kubectl apply -f $(mount_path)/build/helm.yaml @@ -506,247 +467,3 @@ install-custom-pull-secret: docker run --rm $(common_mounts) -e "KUBECONFIG=/root/.kube/$(kubeconfig_file)" -v $(dir $(IMAGE_PULL_SECRET_FILE)):/root/secret $(DOCKER_RUN_ARGS) $(build_tag) \ kubectl apply --namespace default -f /root/secret/$(notdir $(IMAGE_PULL_SECRET_FILE)); \ fi - -# ____ _ ____ _ _ -# / ___| ___ ___ __ _| | ___ / ___| | ___ _ _ __| | -# | | _ / _ \ / _ \ / _` | |/ _ \ | | | |/ _ \| | | |/ _` | -# | |_| | (_) | (_) | (_| | | __/ | |___| | (_) | |_| | (_| | -# \____|\___/ \___/ \__, |_|\___| \____|_|\___/ \__,_|\__,_| -# |___/ - -# Initialise the gcloud login and project configuration, if you are working with GCP -gcloud-init: ensure-build-config - docker run --rm -it $(common_mounts) $(build_tag) gcloud init - -# Creates and authenticates a small, 6 node GKE cluster to work against (2 nodes are used for agones-metrics and agones-system) -gcloud-test-cluster: GCP_CLUSTER_LEGACYABAC ?= false -gcloud-test-cluster: GCP_CLUSTER_NODEPOOL_INITIALNODECOUNT ?= 4 -gcloud-test-cluster: GCP_CLUSTER_NODEPOOL_MACHINETYPE ?= n1-standard-4 -gcloud-test-cluster: $(ensure-build-image) - docker run --rm -it $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) gcloud \ - deployment-manager deployments create $(GCP_CLUSTER_NAME) \ - --properties cluster.zone:$(GCP_CLUSTER_ZONE),cluster.name:$(GCP_CLUSTER_NAME),cluster.nodePool.initialNodeCount:$(GCP_CLUSTER_NODEPOOL_INITIALNODECOUNT),cluster.nodePool.machineType:$(GCP_CLUSTER_NODEPOOL_MACHINETYPE),cluster.legacyAbac:$(GCP_CLUSTER_LEGACYABAC)\ - --template=$(mount_path)/build/gke-test-cluster/cluster.yml.jinja - $(MAKE) gcloud-auth-cluster - $(MAKE) setup-test-cluster - -clean-gcloud-test-cluster: $(ensure-build-image) - docker run --rm -it $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) gcloud \ - deployment-manager deployments delete $(GCP_CLUSTER_NAME) - -# Creates a gcloud cluster for end-to-end -# it installs also a consul cluster to handle build system concurrency using a distributed lock -gcloud-e2e-test-cluster: $(ensure-build-image) - docker run --rm -it $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) gcloud \ - deployment-manager deployments create e2e-test-cluster \ - --config=$(mount_path)/build/gke-test-cluster/cluster-e2e.yml - GCP_CLUSTER_NAME=e2e-test-cluster GCP_CLUSTER_ZONE=us-west1-c $(MAKE) gcloud-auth-cluster - docker run --rm $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) \ - kubectl apply -f $(mount_path)/build/helm.yaml - docker run --rm $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) \ - helm init --service-account helm --wait - docker run --rm $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) \ - helm install --wait --set Replicas=1,uiService.type=ClusterIP --name consul stable/consul - -# Deletes the gcloud e2e cluster and cleanup any left pvc volumes -clean-gcloud-e2e-test-cluster: $(ensure-build-image) - docker run --rm $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) \ - helm delete --purge consul && kubectl delete pvc -l component=consul-consul - GCP_CLUSTER_NAME=e2e-test-cluster $(MAKE) clean-gcloud-test-cluster - -# Pulls down authentication information for kubectl against a cluster, name can be specified through GCP_CLUSTER_NAME -# (defaults to 'test-cluster') -gcloud-auth-cluster: $(ensure-build-image) - docker run --rm $(common_mounts) $(build_tag) gcloud config set container/cluster $(GCP_CLUSTER_NAME) - docker run --rm $(common_mounts) $(build_tag) gcloud config set compute/zone $(GCP_CLUSTER_ZONE) - docker run --rm $(common_mounts) $(build_tag) gcloud container clusters get-credentials $(GCP_CLUSTER_NAME) - -docker run --rm $(common_mounts) $(build_tag) bash -c 'kubectl create clusterrolebinding cluster-admin-binding --clusterrole cluster-admin --user $$(gcloud config get-value account)' - -# authenticate our docker configuration so that you can do a docker push directly -# to the gcr.io repository -gcloud-auth-docker: $(ensure-build-image) - docker run --rm $(common_mounts) $(build_tag) gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://gcr.io - -# Clean the gcloud configuration -clean-gcloud-config: - -sudo rm -r $(build_path)/.config - -# __ __ _ _ _ _ -# | \/ (_)_ __ (_) | ___ _| |__ ___ -# | |\/| | | '_ \| | |/ / | | | '_ \ / _ \ -# | | | | | | | | | <| |_| | |_) | __/ -# |_| |_|_|_| |_|_|_|\_\\__,_|_.__/ \___| -# - -# Switches to an "agones" profile, and starts a kubernetes cluster -# of the right version. -# -# Use MINIKUBE_DRIVER variable to change the VM driver -# (defaults virtualbox for Linux and macOS, hyperv for windows) if you so desire. -minikube-test-cluster: DOCKER_RUN_ARGS+=--network=host -v $(minikube_cert_mount) -minikube-test-cluster: $(ensure-build-image) minikube-agones-profile - # localkube bootstrapper fixes issues with profiles - $(MINIKUBE) start --kubernetes-version v1.11.5 --vm-driver $(MINIKUBE_DRIVER) \ - --extra-config=apiserver.authorization-mode=RBAC - # wait until the master is up - until docker run --rm $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) kubectl cluster-info; \ - do \ - echo "Waiting for cluster to start..."; \ - sleep 1; \ - done - # this is needed for kubernetes component to work correctly while RBAC is enabled - -docker run --rm $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) \ - kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --serviceaccount=kube-system:default - $(MAKE) setup-test-cluster DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS)" - $(MAKE) minikube-post-start - -# switch to the agones cluster -minikube-agones-profile: - $(MINIKUBE) profile $(MINIKUBE_PROFILE) - -# Connecting to minikube requires so enhanced permissions, so use this target -# instead of `make shell` to start an interactive shell for development on minikube. -minikube-shell: $(ensure-build-image) minikube-agones-profile - $(MAKE) shell DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount) $(DOCKER_RUN_ARGS)" - -# Push the local Agones Docker images that have already been built -# via `make build` or `make build-images` into the "agones" minikube instance. -minikube-push: minikube-agones-profile - $(MAKE) minikube-transfer-image TAG=$(sidecar_tag) - $(MAKE) minikube-transfer-image TAG=$(controller_tag) - $(MAKE) minikube-transfer-image TAG=$(ping_tag) - -# Installs the current development version of Agones into the Kubernetes cluster. -# Use this instead of `make install`, as it disables PullAlways on the install.yaml -minikube-install: minikube-agones-profile - $(MAKE) install DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount)" ALWAYS_PULL_SIDECAR=false \ - IMAGE_PULL_POLICY=IfNotPresent PING_SERVICE_TYPE=NodePort - -minikube-uninstall: $(ensure-build-image) minikube-agones-profile - $(MAKE) uninstall DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount)" - -# Convenience target for transferring images into minikube. -# Use TAG to specify the image to transfer into minikube -minikube-transfer-image: - docker save $(TAG) | ($(MINIKUBE_DOCKER_ENV) && docker load) - -# Runs e2e tests against our minikube -minikube-test-e2e: DOCKER_RUN_ARGS=--network=host -v $(minikube_cert_mount) -minikube-test-e2e: minikube-agones-profile test-e2e - -# Runs stress tests against our minikube -minikube-stress-test-e2e: DOCKER_RUN_ARGS=--network=host -v $(minikube_cert_mount) -minikube-stress-test-e2e: minikube-agones-profile stress-test-e2e - -# prometheus on minkube -# we have to disable PVC as it's not supported on minkube. -minikube-setup-prometheus: - $(MAKE) setup-prometheus \ - DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount)" \ - PVC=false HELM_ARGS="--set server.resources.requests.cpu=0,server.resources.requests.memory=0" - - -# grafana on minkube with dashboards and prometheus datasource installed. -# we have to disable PVC as it's not supported on minkube. -minikube-setup-grafana: - $(MAKE) setup-grafana \ - DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount)" - -# minikube port forwarding -minikube-controller-portforward: - $(MAKE) controller-portforward DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount)" - -# minikube port forwarding grafana -minikube-grafana-portforward: - $(MAKE) grafana-portforward \ - DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount)" - -# minikube port forwarding for prometheus web ui -minikube-prometheus-portforward: - $(MAKE) prometheus-portforward \ - DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount)" - -# _ ___ _ -# | |/ (_)_ __ __| | -# | ' /| | '_ \ / _` | -# | . \| | | | | (_| | -# |_|\_\_|_| |_|\__,_| - -# creates a kind cluster for use with agones -# Kind stand for Kubernetes IN Docker -# You can change the cluster name using KIND_PROFILE env var -kind-test-cluster: DOCKER_RUN_ARGS+=--network=host -kind-test-cluster: $(ensure-build-image) - @if [ -z $$(kind get clusters | grep $(KIND_PROFILE)) ]; then\ - echo "Could not find $(KIND_PROFILE) cluster. Creating...";\ - kind create cluster --name $(KIND_PROFILE) --image kindest/node:v1.11.3 --wait 5m;\ - fi - $(MAKE) setup-test-cluster KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS)" - -# deletes the kind agones cluster -# useful if you're want to start from scratch -kind-delete-cluster: - kind delete cluster --name $(KIND_PROFILE) - -# start an interactive shell with kubectl configured to target the kind cluster -kind-shell: $(ensure-build-image) - $(MAKE) shell KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" \ - DOCKER_RUN_ARGS="--network=host $(DOCKER_RUN_ARGS)" - -# installs the current dev version of agones -# you should build-images and kind-push first. -kind-install: - $(MAKE) install DOCKER_RUN_ARGS="--network=host" ALWAYS_PULL_SIDECAR=false \ - IMAGE_PULL_POLICY=IfNotPresent PING_SERVICE_TYPE=NodePort \ - KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" - -# pushses the current dev version of agones to the kind single node cluster. -kind-push: - BUNDLE_FILE=$$(mktemp -d)/agones.tar.gz; \ - docker save \ - $(sidecar_tag) \ - $(controller_tag) \ - $(ping_tag) \ - -o $$BUNDLE_FILE; \ - docker cp $$BUNDLE_FILE $(KIND_CONTAINER_NAME):/agones.tar.gz; \ - docker exec $(KIND_CONTAINER_NAME) docker load -i /agones.tar.gz; \ - rm -f $$BUNDLE_FILE - -# Runs e2e tests against our kind cluster -kind-test-e2e: - $(MAKE) KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" \ - DOCKER_RUN_ARGS=--network=host \ - test-e2e - -# prometheus on kind -# we have to disable PVC as it's not supported on kind. -kind-setup-prometheus: - $(MAKE) setup-prometheus \ - KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" \ - DOCKER_RUN_ARGS="--network=host" PVC=false \ - HELM_ARGS="--set server.resources.requests.cpu=0,server.resources.requests.memory=0" - -# grafana on kind with dashboards and prometheus datasource installed. -# we have to disable PVC as it's not supported on kind. -kind-setup-grafana: - $(MAKE) setup-grafana \ - KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" \ - DOCKER_RUN_ARGS="--network=host" PVC=false - -# kind port forwarding controller web -kind-controller-portforward: - $(MAKE) controller-portforward \ - KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" \ - DOCKER_RUN_ARGS="--network=host" - -# kind port forwarding grafana -kind-grafana-portforward: - $(MAKE) grafana-portforward \ - KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" \ - DOCKER_RUN_ARGS="--network=host" - -# kind port forwarding for prometheus web ui -kind-prometheus-portforward: - $(MAKE) prometheus-portforward \ - KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" \ - DOCKER_RUN_ARGS="--network=host" \ No newline at end of file diff --git a/build/includes/google-cloud.mk b/build/includes/google-cloud.mk new file mode 100644 index 0000000000..ceb8d9076a --- /dev/null +++ b/build/includes/google-cloud.mk @@ -0,0 +1,77 @@ +# 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. + +# ____ _ ____ _ _ +# / ___| ___ ___ __ _| | ___ / ___| | ___ _ _ __| | +# | | _ / _ \ / _ \ / _` | |/ _ \ | | | |/ _ \| | | |/ _` | +# | |_| | (_) | (_) | (_| | | __/ | |___| | (_) | |_| | (_| | +# \____|\___/ \___/ \__, |_|\___| \____|_|\___/ \__,_|\__,_| +# |___/ + +# Initialise the gcloud login and project configuration, if you are working with GCP +gcloud-init: ensure-build-config + docker run --rm -it $(common_mounts) $(build_tag) gcloud init + +# Creates and authenticates a small, 6 node GKE cluster to work against (2 nodes are used for agones-metrics and agones-system) +gcloud-test-cluster: GCP_CLUSTER_LEGACYABAC ?= false +gcloud-test-cluster: GCP_CLUSTER_NODEPOOL_INITIALNODECOUNT ?= 4 +gcloud-test-cluster: GCP_CLUSTER_NODEPOOL_MACHINETYPE ?= n1-standard-4 +gcloud-test-cluster: $(ensure-build-image) + docker run --rm -it $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) gcloud \ + deployment-manager deployments create $(GCP_CLUSTER_NAME) \ + --properties cluster.zone:$(GCP_CLUSTER_ZONE),cluster.name:$(GCP_CLUSTER_NAME),cluster.nodePool.initialNodeCount:$(GCP_CLUSTER_NODEPOOL_INITIALNODECOUNT),cluster.nodePool.machineType:$(GCP_CLUSTER_NODEPOOL_MACHINETYPE),cluster.legacyAbac:$(GCP_CLUSTER_LEGACYABAC)\ + --template=$(mount_path)/build/gke-test-cluster/cluster.yml.jinja + $(MAKE) gcloud-auth-cluster + $(MAKE) setup-test-cluster + +clean-gcloud-test-cluster: $(ensure-build-image) + docker run --rm -it $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) gcloud \ + deployment-manager deployments delete $(GCP_CLUSTER_NAME) + +# Creates a gcloud cluster for end-to-end +# it installs also a consul cluster to handle build system concurrency using a distributed lock +gcloud-e2e-test-cluster: $(ensure-build-image) + docker run --rm -it $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) gcloud \ + deployment-manager deployments create e2e-test-cluster \ + --config=$(mount_path)/build/gke-test-cluster/cluster-e2e.yml + GCP_CLUSTER_NAME=e2e-test-cluster GCP_CLUSTER_ZONE=us-west1-c $(MAKE) gcloud-auth-cluster + docker run --rm $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) \ + kubectl apply -f $(mount_path)/build/helm.yaml + docker run --rm $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) \ + helm init --service-account helm --wait + docker run --rm $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) \ + helm install --wait --set Replicas=1,uiService.type=ClusterIP --name consul stable/consul + +# Deletes the gcloud e2e cluster and cleanup any left pvc volumes +clean-gcloud-e2e-test-cluster: $(ensure-build-image) + docker run --rm $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) \ + helm delete --purge consul && kubectl delete pvc -l component=consul-consul + GCP_CLUSTER_NAME=e2e-test-cluster $(MAKE) clean-gcloud-test-cluster + +# Pulls down authentication information for kubectl against a cluster, name can be specified through GCP_CLUSTER_NAME +# (defaults to 'test-cluster') +gcloud-auth-cluster: $(ensure-build-image) + docker run --rm $(common_mounts) $(build_tag) gcloud config set container/cluster $(GCP_CLUSTER_NAME) + docker run --rm $(common_mounts) $(build_tag) gcloud config set compute/zone $(GCP_CLUSTER_ZONE) + docker run --rm $(common_mounts) $(build_tag) gcloud container clusters get-credentials $(GCP_CLUSTER_NAME) + -docker run --rm $(common_mounts) $(build_tag) bash -c 'kubectl create clusterrolebinding cluster-admin-binding --clusterrole cluster-admin --user $$(gcloud config get-value account)' + +# authenticate our docker configuration so that you can do a docker push directly +# to the gcr.io repository +gcloud-auth-docker: $(ensure-build-image) + docker run --rm $(common_mounts) $(build_tag) gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://gcr.io + +# Clean the gcloud configuration +clean-gcloud-config: + -sudo rm -r $(build_path)/.config \ No newline at end of file diff --git a/build/includes/kind.mk b/build/includes/kind.mk new file mode 100644 index 0000000000..7a6becf720 --- /dev/null +++ b/build/includes/kind.mk @@ -0,0 +1,99 @@ +# 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. + + +# _ ___ _ +# | |/ (_)_ __ __| | +# | ' /| | '_ \ / _` | +# | . \| | | | | (_| | +# |_|\_\_|_| |_|\__,_| + +# creates a kind cluster for use with agones +# Kind stand for Kubernetes IN Docker +# You can change the cluster name using KIND_PROFILE env var +kind-test-cluster: DOCKER_RUN_ARGS+=--network=host +kind-test-cluster: $(ensure-build-image) + @if [ -z $$(kind get clusters | grep $(KIND_PROFILE)) ]; then\ + echo "Could not find $(KIND_PROFILE) cluster. Creating...";\ + kind create cluster --name $(KIND_PROFILE) --image kindest/node:v1.11.3 --wait 5m;\ + fi + $(MAKE) setup-test-cluster KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS)" + +# deletes the kind agones cluster +# useful if you're want to start from scratch +kind-delete-cluster: + kind delete cluster --name $(KIND_PROFILE) + +# start an interactive shell with kubectl configured to target the kind cluster +kind-shell: $(ensure-build-image) + $(MAKE) shell KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" \ + DOCKER_RUN_ARGS="--network=host $(DOCKER_RUN_ARGS)" + +# installs the current dev version of agones +# you should build-images and kind-push first. +kind-install: + $(MAKE) install DOCKER_RUN_ARGS="--network=host" ALWAYS_PULL_SIDECAR=false \ + IMAGE_PULL_POLICY=IfNotPresent PING_SERVICE_TYPE=NodePort \ + KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" + +# pushses the current dev version of agones to the kind single node cluster. +kind-push: + BUNDLE_FILE=$$(mktemp -d)/agones.tar.gz; \ + docker save \ + $(sidecar_tag) \ + $(controller_tag) \ + $(ping_tag) \ + -o $$BUNDLE_FILE; \ + docker cp $$BUNDLE_FILE $(KIND_CONTAINER_NAME):/agones.tar.gz; \ + docker exec $(KIND_CONTAINER_NAME) docker load -i /agones.tar.gz; \ + rm -f $$BUNDLE_FILE + +# Runs e2e tests against our kind cluster +kind-test-e2e: + $(MAKE) KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" \ + DOCKER_RUN_ARGS=--network=host \ + test-e2e + +# prometheus on kind +# we have to disable PVC as it's not supported on kind. +kind-setup-prometheus: + $(MAKE) setup-prometheus \ + KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" \ + DOCKER_RUN_ARGS="--network=host" PVC=false \ + HELM_ARGS="--set server.resources.requests.cpu=0,server.resources.requests.memory=0" + +# grafana on kind with dashboards and prometheus datasource installed. +# we have to disable PVC as it's not supported on kind. +kind-setup-grafana: + $(MAKE) setup-grafana \ + KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" \ + DOCKER_RUN_ARGS="--network=host" PVC=false + +# kind port forwarding controller web +kind-controller-portforward: + $(MAKE) controller-portforward \ + KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" \ + DOCKER_RUN_ARGS="--network=host" + +# kind port forwarding grafana +kind-grafana-portforward: + $(MAKE) grafana-portforward \ + KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" \ + DOCKER_RUN_ARGS="--network=host" + +# kind port forwarding for prometheus web ui +kind-prometheus-portforward: + $(MAKE) prometheus-portforward \ + KUBECONFIG="$(shell kind get kubeconfig-path --name="$(KIND_PROFILE)")" \ + DOCKER_RUN_ARGS="--network=host" \ No newline at end of file diff --git a/build/includes/minikube.mk b/build/includes/minikube.mk new file mode 100644 index 0000000000..60efecb788 --- /dev/null +++ b/build/includes/minikube.mk @@ -0,0 +1,109 @@ +# 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. + + +# __ __ _ _ _ _ +# | \/ (_)_ __ (_) | ___ _| |__ ___ +# | |\/| | | '_ \| | |/ / | | | '_ \ / _ \ +# | | | | | | | | | <| |_| | |_) | __/ +# |_| |_|_|_| |_|_|_|\_\\__,_|_.__/ \___| +# + +# Switches to an "agones" profile, and starts a kubernetes cluster +# of the right version. +# +# Use MINIKUBE_DRIVER variable to change the VM driver +# (defaults virtualbox for Linux and macOS, hyperv for windows) if you so desire. +minikube-test-cluster: DOCKER_RUN_ARGS+=--network=host -v $(minikube_cert_mount) +minikube-test-cluster: $(ensure-build-image) minikube-agones-profile + # localkube bootstrapper fixes issues with profiles + $(MINIKUBE) start --kubernetes-version v1.11.5 --vm-driver $(MINIKUBE_DRIVER) \ + --extra-config=apiserver.authorization-mode=RBAC + # wait until the master is up + until docker run --rm $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) kubectl cluster-info; \ + do \ + echo "Waiting for cluster to start..."; \ + sleep 1; \ + done + # this is needed for kubernetes component to work correctly while RBAC is enabled + -docker run --rm $(common_mounts) $(DOCKER_RUN_ARGS) $(build_tag) \ + kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --serviceaccount=kube-system:default + $(MAKE) setup-test-cluster DOCKER_RUN_ARGS="$(DOCKER_RUN_ARGS)" + $(MAKE) minikube-post-start + +# switch to the agones cluster +minikube-agones-profile: + $(MINIKUBE) profile $(MINIKUBE_PROFILE) + +# Connecting to minikube requires so enhanced permissions, so use this target +# instead of `make shell` to start an interactive shell for development on minikube. +minikube-shell: $(ensure-build-image) minikube-agones-profile + $(MAKE) shell DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount) $(DOCKER_RUN_ARGS)" + +# Push the local Agones Docker images that have already been built +# via `make build` or `make build-images` into the "agones" minikube instance. +minikube-push: minikube-agones-profile + $(MAKE) minikube-transfer-image TAG=$(sidecar_tag) + $(MAKE) minikube-transfer-image TAG=$(controller_tag) + $(MAKE) minikube-transfer-image TAG=$(ping_tag) + +# Installs the current development version of Agones into the Kubernetes cluster. +# Use this instead of `make install`, as it disables PullAlways on the install.yaml +minikube-install: minikube-agones-profile + $(MAKE) install DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount)" ALWAYS_PULL_SIDECAR=false \ + IMAGE_PULL_POLICY=IfNotPresent PING_SERVICE_TYPE=NodePort + +minikube-uninstall: $(ensure-build-image) minikube-agones-profile + $(MAKE) uninstall DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount)" + +# Convenience target for transferring images into minikube. +# Use TAG to specify the image to transfer into minikube +minikube-transfer-image: + docker save $(TAG) | ($(MINIKUBE_DOCKER_ENV) && docker load) + +# Runs e2e tests against our minikube +minikube-test-e2e: DOCKER_RUN_ARGS=--network=host -v $(minikube_cert_mount) +minikube-test-e2e: minikube-agones-profile test-e2e + +# Runs stress tests against our minikube +minikube-stress-test-e2e: DOCKER_RUN_ARGS=--network=host -v $(minikube_cert_mount) +minikube-stress-test-e2e: minikube-agones-profile stress-test-e2e + +# prometheus on minkube +# we have to disable PVC as it's not supported on minkube. +minikube-setup-prometheus: + $(MAKE) setup-prometheus \ + DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount)" \ + PVC=false HELM_ARGS="--set server.resources.requests.cpu=0,server.resources.requests.memory=0" + + +# grafana on minkube with dashboards and prometheus datasource installed. +# we have to disable PVC as it's not supported on minkube. +minikube-setup-grafana: + $(MAKE) setup-grafana \ + DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount)" + +# minikube port forwarding +minikube-controller-portforward: + $(MAKE) controller-portforward DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount)" + +# minikube port forwarding grafana +minikube-grafana-portforward: + $(MAKE) grafana-portforward \ + DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount)" + +# minikube port forwarding for prometheus web ui +minikube-prometheus-portforward: + $(MAKE) prometheus-portforward \ + DOCKER_RUN_ARGS="--network=host -v $(minikube_cert_mount)" diff --git a/build/includes/release.mk b/build/includes/release.mk new file mode 100644 index 0000000000..960af18b88 --- /dev/null +++ b/build/includes/release.mk @@ -0,0 +1,70 @@ +# 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. + +# ____ _ +# | _ \ ___| | ___ __ _ ___ ___ +# | |_) / _ \ |/ _ \/ _` / __|/ _ \ +# | _ < __/ | __/ (_| \__ \ __/ +# |_| \_\___|_|\___|\__,_|___/\___| +# + +# +# targets for an Agones release +# + +# generate a changelog using github-changelog-generator +gen-changelog: RELEASE_VERSION ?= $(base_version) +gen-changelog: + read -p 'Github Token: ' TOKEN && \ + docker run -it --rm -v "$(agones_path)":/project markmandel/github-changelog-generator \ + --user=GoogleCloudPlatform --project=agones \ + --bug-labels=kind/bug --enhancement-labels=kind/feature \ + --breaking-labels=kind/breaking --security-labels=area/security \ + --future-release "v$(RELEASE_VERSION)" \ + --token $$TOKEN + +# Creates a release. Version defaults to the base_version +# - Checks out a release branch +# - Build binaries and images +# - Creates sdk and binary archives, and moves the into the /release folder for upload +# - Creates a zip of the install.yaml, LICENCE and README.md for installation +# - Pushes the current chart version to the helm repository hosted on gcs. +do-release: RELEASE_VERSION ?= $(base_version) +do-release: + @echo "Starting release for version: $(RELEASE_VERSION)" + git checkout -b release-$(RELEASE_VERSION) + $(MAKE) lint test FULL_BUILD=1 + -rm -rf $(agones_path)/release + mkdir $(agones_path)/release + docker run --rm $(common_mounts) -w $(mount_path)/sdks/cpp $(build_tag) make clean + $(MAKE) build-sdks build-agones-sdk-binary VERSION=$(RELEASE_VERSION) REGISTRY=$(release_registry) FULL_BUILD=1 + cp $(agones_path)/cmd/sdk-server/bin/agonessdk-server-$(RELEASE_VERSION).zip $(agones_path)/release + cp $(agones_path)/sdks/cpp/bin/agonessdk-$(RELEASE_VERSION)-runtime-linux-arch_64.tar.gz $(agones_path)/release + cp $(agones_path)/sdks/cpp/bin/agonessdk-$(RELEASE_VERSION)-dev-linux-arch_64.tar.gz $(agones_path)/release + cp $(agones_path)/sdks/cpp/bin/agonessdk-$(RELEASE_VERSION)-src.zip $(agones_path)/release + cd $(agones_path) && zip -r ./release/agones-install-$(RELEASE_VERSION).zip ./README.md ./install ./LICENSE + + # retag the current master commit images with the release tag. + $(MAKE) do-relase-tag-images RELEASE_VERSION=$(RELEASE_VERSION) + + $(MAKE) push-chart VERSION=$(RELEASE_VERSION) + git push -u upstream release-$(RELEASE_VERSION) + + @echo "Now go make the $(RELEASE_VERSION) release on Github!" + +do-relase-tag-images: RELEASE_VERSION ?= $(base_version) +do-relase-tag-images: + docker run --rm $(common_mounts) $(build_tag) gcloud container images add-tag $(release_registry)/agones-controller:$(VERSION) $(release_registry)/agones-controller:$(RELEASE_VERSION) --quiet + docker run --rm $(common_mounts) $(build_tag) gcloud container images add-tag $(release_registry)/agones-sdk:$(VERSION) $(release_registry)/agones-sdk:$(RELEASE_VERSION) --quiet + docker run --rm $(common_mounts) $(build_tag) gcloud container images add-tag $(release_registry)/agones-ping:$(VERSION) $(release_registry)/agones-ping:$(RELEASE_VERSION) --quiet