Skip to content

Commit

Permalink
Speed up builds by using local go/zip instead of dockerized ones.
Browse files Browse the repository at this point in the history
This adds LOCAL_GO and LOCAL_ZIP which cause locally-installed Go toolkit and zip tool to be used when building binaries, greatly speeding up incremental rebuilds on a Mac where docker filesystem driver is very slow.

Before:

```
$ time make -j4 build-controller-binary build-agones-sdk-binary

real    1m11.369s
user    0m0.325s
sys     0m0.273s
```

After:

```
$ time make -j4 build-controller-binary build-agones-sdk-binary LOCAL_GO=1 LOCAL_ZIP=1

real    0m4.605s
user    0m3.480s
sys     0m4.527s
```

Note that when using LOCAL_GO, agones.dev must be checked out in a GOPATH and Go compiler must be installed at appropriate version.
Use at your own risk!
  • Loading branch information
jkowalski committed Jan 24, 2019
1 parent d03caff commit a1a9ea5
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ ifndef FULL_BUILD
zip_flags = -0
endif

GO_BUILD_LINUX_AMD64=docker run --rm -e "CGO_ENABLED=0" $(common_mounts) $(build_tag) go build
GO_BUILD_DARWIN_AMD64=docker run --rm -e "GOOS=darwin" -e "GOARCH=amd64" $(common_mounts) $(build_tag) go build
GO_BUILD_WINDOWS_AMD64=docker run --rm -e "GOOS=windows" -e "GOARCH=amd64" $(common_mounts) $(build_tag) go build

go_build_base_path=$(mount_path)

ifdef LOCAL_GO
# use local Go tooling, which greatly speeds up incremental rebuils, in particular on macOS
# Note that agones.dev must be in GOPATH
GO_BUILD_LINUX_AMD64=CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
GO_BUILD_WINDOWS_AMD64=GOOS=linux GOARCH=amd64 go build
GO_BUILD_DARWIN_AMD64=GOOS=darwin GOARCH=amd64 go build
go_build_base_path=$(agones_path)/..
endif

ZIP_SDK=docker run --rm $(common_mounts) -w $(mount_path)/cmd/sdk-server/bin/ $(build_tag) zip $(zip_flags)
ifdef LOCAL_ZIP
ZIP_SDK=cd $(agones_path)/cmd/sdk-server/bin && zip -0
endif

# ___ _ _
# |_ _|_ __ ___| |_ _ __| | ___ ___
# | || '_ \ / __| | | | |/ _` |/ _ \ __|
Expand Down Expand Up @@ -222,8 +242,8 @@ uninstall: $(ensure-build-image)

# Build a static binary for the gameserver controller
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 \
$(GO_BUILD_LINUX_AMD64) \
-tags $(GO_BUILD_TAGS) -o $(go_build_base_path)/cmd/controller/bin/controller \
$(go_rebuild_flags) $(go_version_flags) -installsuffix cgo $(agones_package)/cmd/controller

# Lint the go source code.
Expand All @@ -243,32 +263,32 @@ push-controller-image: $(ensure-build-image)

# build the static binary for the gamesever sidecar
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) \
$(ZIP_SDK) \
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 $(go_rebuild_flags) $(go_version_flags) -installsuffix cgo $(agones_package)/cmd/sdk-server
$(GO_BUILD_LINUX_AMD64) \
-o $(go_build_base_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_rebuild_flags) $(go_version_flags) $(agones_package)/cmd/sdk-server
$(GO_BUILD_DARWIN_AMD64) \
-o $(go_build_base_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_rebuild_flags) $(go_version_flags) $(agones_package)/cmd/sdk-server
$(GO_BUILD_WINDOWS_AMD64) \
-o $(go_build_base_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
docker build $(agones_path)/cmd/sdk-server/ --tag=$(sidecar_tag) $(DOCKER_BUILD_ARGS)

# Build a static binary for the ping service
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 \
$(GO_BUILD_LINUX_AMD64) \
-tags $(GO_BUILD_TAGS) -o $(go_build_base_path)/cmd/ping/bin/ping \
$(go_rebuild_flags) $(go_version_flags) -installsuffix cgo $(agones_package)/cmd/ping

# Pushes up the ping image
Expand Down

0 comments on commit a1a9ea5

Please sign in to comment.