Skip to content

Commit

Permalink
added INCREMENTAL_BUILD option to Makefile to speed up rebuilds
Browse files Browse the repository at this point in the history
Before:
=======
$ time make -C build -j4 build-images
real    2m33.772s
user    0m1.302s
sys     0m0.889s

Incremental re-builds:
=======
$ time make -C build -j4 build-controller-image INCREMENTAL_BUILD=1
real    0m1.837s
user    0m0.241s
sys     0m0.085s

$ time make -C build -j4 build-agones-sdk-image INCREMENTAL_BUILD=1
real    0m5.352s
user    0m0.447s
sys     0m0.244s

$ time make -C build -j4 build-ping-image INCREMENTAL_BUILD=1
real    0m1.318s
user    0m0.198s
sys     0m0.063s

$ time make -C build -j4 build-images INCREMENTAL_BUILD=1
real    0m5.506s
user    0m1.177s
sys     0m0.617s
  • Loading branch information
jkowalski committed Dec 21, 2018
1 parent 8170aa0 commit 9b7d27e
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ sidecar_tag = $(REGISTRY)/agones-sdk:$(VERSION)
ping_tag = $(REGISTRY)/agones-ping:$(VERSION)

go_version_flags = -ldflags "-X agones.dev/agones/pkg.Version=$(VERSION)"

# by default perform full rebuild unless INCREMENTAL_BUILD is set
go_rebuild_flags = -a
# zip compression level
zip_flags = -9
DOCKER_RUN ?= docker run --rm $(common_mounts) -e "KUBECONFIG=/root/.kube/$(kubeconfig_file)" $(DOCKER_RUN_ARGS) $(build_tag)
# ___ ____ ___ _ _
# / _ \/ ___| |_ _|_ __ ___| |_ _ __| | ___
Expand All @@ -101,6 +106,13 @@ ifdef DOCKER_RUN
ensure-build-image += ensure-build-image
endif

ifdef INCREMENTAL_BUILD
# keep a cache of files built by Go across docker invocations in a local directory.
common_mounts += -v $(CURDIR)/.gocache:/root/.cache/go-build
go_rebuild_flags =
zip_flags = -0
endif

# _____ _
# |_ _|_ _ _ __ __ _ ___| |_ ___
# | |/ _` | '__/ _` |/ _ \ __/ __|
Expand Down Expand Up @@ -195,7 +207,7 @@ uninstall: $(ensure-build-image)
build-controller-binary: $(ensure-build-image)
docker run --rm -e "CGO_ENABLED=0" $(common_mounts) $(build_tag) go build \
-tags $(GO_BUILD_TAGS) -o $(mount_path)/cmd/controller/bin/controller \
-a $(go_version_flags) -installsuffix cgo $(agones_package)/cmd/controller
$(go_rebuild_flags) $(go_version_flags) -installsuffix cgo $(agones_package)/cmd/controller

# Lint the go source code.
# use LINT_TIMEOUT to manipulate the linter timeout
Expand All @@ -213,15 +225,24 @@ push-controller-image: $(ensure-build-image)
docker push $(controller_tag)

# build the static binary for the gamesever sidecar
build-agones-sdk-binary: $(ensure-build-image)
build-agones-sdk-binary: $(ensure-build-image) build-agones-sdk-binary-linux build-agones-sdk-binary-windows build-agones-sdk-binary-darwin
docker run --rm $(common_mounts) -w $(mount_path)/cmd/sdk-server/bin/ $(build_tag) zip $(zip_flags) \
agonessdk-server-$(VERSION).zip sdk-server.darwin.amd64 sdk-server.linux.amd64 sdk-server.windows.amd64.exe

# build the static binary for the gamesever sidecar for Linux
build-agones-sdk-binary-linux: $(ensure-build-image)
docker run --rm -e "CGO_ENABLED=0" $(common_mounts) $(build_tag) go build \
-o $(mount_path)/cmd/sdk-server/bin/sdk-server.linux.amd64 -a $(go_version_flags) -installsuffix cgo $(agones_package)/cmd/sdk-server
-o $(mount_path)/cmd/sdk-server/bin/sdk-server.linux.amd64 $(go_rebuild_flags) $(go_version_flags) -installsuffix cgo $(agones_package)/cmd/sdk-server

# build the static binary for the gamesever sidecar for Darwin (macOS)
build-agones-sdk-binary-darwin: $(ensure-build-image)
docker run --rm -e "GOOS=darwin" -e "GOARCH=amd64" $(common_mounts) $(build_tag) go build \
-o $(mount_path)/cmd/sdk-server/bin/sdk-server.darwin.amd64 $(go_version_flags) $(agones_package)/cmd/sdk-server
-o $(mount_path)/cmd/sdk-server/bin/sdk-server.darwin.amd64 $(go_rebuild_flags) $(go_version_flags) $(agones_package)/cmd/sdk-server

# build the windows binary for the gamesever sidecar for Windows
build-agones-sdk-binary-windows: $(ensure-build-image)
docker run --rm -e "GOOS=windows" -e "GOARCH=amd64" $(common_mounts) $(build_tag) go build \
-o $(mount_path)/cmd/sdk-server/bin/sdk-server.windows.amd64.exe $(go_version_flags) $(agones_package)/cmd/sdk-server
docker run --rm $(common_mounts) -w $(mount_path)/cmd/sdk-server/bin/ $(build_tag) zip \
agonessdk-server-$(VERSION).zip sdk-server.darwin.amd64 sdk-server.linux.amd64 sdk-server.windows.amd64.exe
-o $(mount_path)/cmd/sdk-server/bin/sdk-server.windows.amd64.exe $(go_rebuild_flags) $(go_version_flags) $(agones_package)/cmd/sdk-server

# Build the image for the gameserver sidecar
build-agones-sdk-image: $(ensure-build-image) build-agones-sdk-binary
Expand All @@ -231,7 +252,7 @@ build-agones-sdk-image: $(ensure-build-image) build-agones-sdk-binary
build-ping-binary: $(ensure-build-image)
docker run --rm -e "CGO_ENABLED=0" $(common_mounts) $(build_tag) go build \
-tags $(GO_BUILD_TAGS) -o $(mount_path)/cmd/ping/bin/ping \
-a $(go_version_flags) -installsuffix cgo $(agones_package)/cmd/ping
$(go_rebuild_flags) $(go_version_flags) -installsuffix cgo $(agones_package)/cmd/ping

# Pushes up the ping image
push-ping-image: $(ensure-build-image)
Expand Down Expand Up @@ -360,7 +381,7 @@ do-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
cd $(agones_path) && zip $(zip_flags) -r ./release/agones-install-$(RELEASE_VERSION).zip ./README.md ./install ./LICENSE
$(MAKE) push-chart
$(MAKE) gcloud-auth-docker push REGISTRY=$(release_registry) VERSION=$(RELEASE_VERSION)
git push -u upstream release-$(RELEASE_VERSION)
Expand Down

0 comments on commit 9b7d27e

Please sign in to comment.