Skip to content

Commit

Permalink
sdk arm64 images (googleforgames#2521)
Browse files Browse the repository at this point in the history
* Build both arm64 and amd64 sdk img

Co-authored-by: Mark Mandel <markmandel@google.com>
Co-authored-by: Robert Bailey <robertbailey@google.com>
  • Loading branch information
3 people authored Apr 29, 2022
1 parent f9c333d commit aed208d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 41 deletions.
76 changes: 41 additions & 35 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ controller_tag = $(REGISTRY)/agones-controller:$(VERSION)
sidecar_tag = $(REGISTRY)/agones-sdk:$(VERSION)

ifeq ($(WITH_WINDOWS), 1)
sidecar_linux_amd64_tag = $(sidecar_tag)-linux_amd64
sidecar_linux_amd64_tag = $(REGISTRY)/agones-sdk:$(VERSION)-linux-amd64
sidecar_linux_arm64_tag = $(REGISTRY)/agones-sdk:$(VERSION)-linux-arm64
else
sidecar_linux_amd64_tag = $(sidecar_tag)
sidecar_linux_amd64_tag = $(REGISTRY)/agones-sdk:$(VERSION)-amd64
sidecar_linux_arm64_tag = $(REGISTRY)/agones-sdk:$(VERSION)-arm64
endif

ping_tag = $(REGISTRY)/agones-ping:$(VERSION)
Expand Down Expand Up @@ -230,9 +232,6 @@ build: build-images build-sdks

# build the docker images
build-images: build-controller-image build-agones-sdk-image build-ping-image build-allocator-image
ifeq ($(WITH_WINDOWS), 1)
build-images: build-agones-sdk-image-windows
endif

# package the current agones helm chart
build-chart: RELEASE_VERSION ?= $(base_version)
Expand Down Expand Up @@ -360,7 +359,6 @@ uninstall: $(ensure-build-image)
$(DOCKER_RUN) \
helm uninstall agones --namespace=agones-system


# Build a static binary for the gameserver controller
ifeq ($(WITH_ARM64), 1)
build-controller-binary: $(ensure-build-image) build-controller-binary-linux-amd64 build-controller-binary-linux-arm64
Expand Down Expand Up @@ -428,34 +426,28 @@ build-agones-sdk-binary-windows: $(ensure-build-image)
-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

ensure-windows-buildx:
# TODO: Remove `--use` and specify `--builder` for each buildx command once Docker 19.03.13 is available.
# `--use` sets the global default buildx context to $(BUILDX_WINDOWS_BUILDER).
#
# Windows image builds must be directed to a specific buildx context.
# The default context does not support building cross platform images.
-DOCKER_CLI_EXPERIMENTAL=enabled docker buildx create --name=$(BUILDX_WINDOWS_BUILDER) --use
-docker buildx create --name=$(BUILDX_WINDOWS_BUILDER)

# Build the image for the gameserver sidecar and SDK binaries
build-agones-sdk-image: $(ensure-build-image) build-agones-sdk-binary build-licenses build-required-src-dist
build-agones-sdk-image: $(ensure-build-image) build-agones-sdk-binary build-licenses build-required-src-dist build-agones-sdk-image-amd64
ifeq ($(WITH_ARM64), 1)
build-agones-sdk-image: build-agones-sdk-image-arm64
endif
ifeq ($(WITH_WINDOWS), 1)
build-agones-sdk-image: build-agones-sdk-image-windows
endif

build-agones-sdk-image-amd64: $(ensure-build-image) build-agones-sdk-binary
docker build $(agones_path)/cmd/sdk-server/ --tag=$(sidecar_linux_amd64_tag) $(DOCKER_BUILD_ARGS)
build-agones-sdk-image-arm64: $(ensure-build-image) build-agones-sdk-binary
docker buildx build --platform linux/arm64 --build-arg ARCH=arm64 $(agones_path)/cmd/sdk-server/ --tag=$(sidecar_linux_arm64_tag) $(DOCKER_BUILD_ARGS)

build-agones-sdk-image-windows: build-agones-sdk-binary
build-agones-sdk-image-windows: $(foreach winver, $(WINDOWS_VERSIONS), build-agones-sdk-image-windows-$(winver))

# Build the image for the gameserver sidecar and SDK binaries
build-agones-sdk-image-windows-%: $(ensure-build-image) build-agones-sdk-binary build-licenses build-required-src-dist ensure-windows-buildx
# TODO: Use `--builder $(BUILDX_WINDOWS_BUILDER)` later once Docker 19.03.13 is the build target. Cloud Build has 19.03.08 https://cloud.google.com/cloud-build/release-notes
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform windows/amd64 -f $(agones_path)/cmd/sdk-server/Dockerfile.windows --tag=$(sidecar_tag)-windows_amd64-$* --build-arg WINDOWS_VERSION=$* $(DOCKER_BUILD_ARGS) $(agones_path)/cmd/sdk-server/ $(WINDOWS_DOCKER_PUSH_ARGS)

# Build sidecar image only
build-agones-sdk-server-image: $(ensure-build-image) build-agones-sdk-binary-linux build-licenses build-required-src-dist
docker build $(agones_path)/cmd/sdk-server/ --tag=$(sidecar_linux_amd64_tag) $(DOCKER_BUILD_ARGS)

build-agones-sdk-server-image-windows: $(foreach winver, $(WINDOWS_VERSIONS), build-agones-sdk-server-image-windows-$(winver))

# Build sidecar image only
build-agones-sdk-server-image-windows-%: $(ensure-build-image) build-agones-sdk-binary-linux build-licenses build-required-src-dist ensure-windows-buildx
# TODO: Use `--builder $(BUILDX_WINDOWS_BUILDER)` later once Docker 19.03.13 is the build target. Cloud Build has 19.03.08 https://cloud.google.com/cloud-build/release-notes
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build $(agones_path)/cmd/sdk-server/ -f $(agones_path)/cmd/sdk-server/Dockerfile.windows --platform windows/amd64 --tag=$(sidecar_tag)-windows_amd64-$* --build-arg WINDOWS_VERSION=$* $(DOCKER_BUILD_ARGS) $(WINDOWS_DOCKER_PUSH_ARGS)
docker buildx build --platform windows/amd64 --builder $(BUILDX_WINDOWS_BUILDER) -f $(agones_path)/cmd/sdk-server/Dockerfile.windows --tag=$(sidecar_tag)-windows_amd64-$* --build-arg WINDOWS_VERSION=$* $(DOCKER_BUILD_ARGS) $(agones_path)/cmd/sdk-server/ $(WINDOWS_DOCKER_PUSH_ARGS)

# Build a static binary for the ping service
build-ping-binary: $(ensure-build-image)
Expand Down Expand Up @@ -495,23 +487,37 @@ push-allocator-image: $(ensure-build-image)
build-allocator-image: $(ensure-build-image) build-allocator-binary build-licenses build-required-src-dist
docker build $(agones_path)/cmd/allocator/ --tag=$(allocator_tag) $(DOCKER_BUILD_ARGS)

# build list of images to include in the manifest for the sidecar image.
push_manifest = $(sidecar_linux_amd64_tag)
ifeq ($(WITH_WINDOWS), 1)
push_manifest += $(foreach windows_version, $(WINDOWS_VERSIONS), $(sidecar_tag)-windows_amd64-$(windows_version))
endif
ifeq ($(WITH_ARM64), 1)
push_manifest += $(sidecar_linux_arm64_tag)
endif

# push the gameservers sidecar image
push-agones-sdk-image: push-agones-sdk-linux-image
push-agones-sdk-image: push-agones-sdk-linux-image-amd64
ifeq ($(WITH_WINDOWS), 1)
push-agones-sdk-image: push-agones-sdk-windows
endif
ifeq ($(WITH_ARM64), 1)
push-agones-sdk-image: push-agones-sdk-linux-image-arm64
endif
# Ensure that the sidecar manifest is removed before creating a new one.
-DOCKER_CLI_EXPERIMENTAL=enabled docker manifest rm $(sidecar_tag)
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create $(sidecar_tag) $(push_manifest)
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push $(sidecar_tag)

push-agones-sdk-windows:
# Using docker buildx with foreign OSes is a bit awkward. Since the layers but not the tag
# was cached we have to rebuild the image (which should be fast since it's cached).
$(MAKE) WINDOWS_DOCKER_PUSH_ARGS=--push build-agones-sdk-image-windows
# Agones should start using the -linux_amd64 suffix for Linux images. This allows multi-arch support in the future.
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create $(sidecar_tag) $(sidecar_linux_amd64_tag) $(foreach windows_version, $(WINDOWS_VERSIONS), $(sidecar_tag)-windows_amd64-$(windows_version))
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push $(sidecar_tag)
else
push-agones-sdk-image: push-agones-sdk-linux-image
endif

# push the gameservers sidecar image
push-agones-sdk-linux-image: $(ensure-build-image)
push-agones-sdk-linux-image-arm64: $(ensure-build-image)
$(MAKE) DOCKER_BUILD_ARGS=--push build-agones-sdk-image-arm64

push-agones-sdk-linux-image-amd64: $(ensure-build-image)
docker push $(sidecar_linux_amd64_tag)

# Generate the Embedded CRD openapi
Expand Down
6 changes: 6 additions & 0 deletions build/includes/build-image.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ build-build-image:
clean-build-image:
docker rmi $(build_tag)

ensure-arm-builder:
docker run --privileged --rm tonistiigi/binfmt:qemu-v6.2.0 --install arm64

ensure-build-config:
-mkdir -p $(kubeconfig_path)
-mkdir -p $(build_path)/.gocache
Expand All @@ -39,6 +42,9 @@ ensure-build-config:
# create the build image if it doesn't exist
ensure-build-image: ensure-build-config
$(MAKE) ensure-image IMAGE_TAG=$(build_tag) BUILD_TARGET=build-build-image
ifeq ($(WITH_ARM64), 1)
ensure-build-image: ensure-arm-builder
endif

# attempt to pull the image, if it exists and rename it to the local tag
# exit's clean if it doesn't exist, so can be used on CI
Expand Down
7 changes: 3 additions & 4 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ steps:
# Print Docker version
#

- name: "gcr.io/cloud-builders/docker"
- name: "gcr.io/cloud-builders/docker:20.10.13"
id: docker-version
args: ["--version"]

Expand Down Expand Up @@ -51,7 +51,6 @@ steps:
- '--key=$_CPP_SDK_CONFORMANCE_CACHE_KEY-$( checksum sdks/cpp/cmake/prerequisites.cmake )'
waitFor: ['-']


- name: gcr.io/$PROJECT_ID/restore_cache
id: rust-sdk-build-restore-cache
args:
Expand All @@ -64,9 +63,9 @@ steps:
#

- name: "ubuntu"
args: ["bash", "-c", "echo 'FROM gcr.io/cloud-builders/docker\nRUN apt-get install make\nENTRYPOINT [\"/usr/bin/make\"]' > Dockerfile.build"]
args: ["bash", "-c", "echo 'FROM gcr.io/cloud-builders/docker:20.10.13\nRUN apt-get install make\nENTRYPOINT [\"/usr/bin/make\"]' > Dockerfile.build"]
waitFor: ['-']
- name: "gcr.io/cloud-builders/docker"
- name: "gcr.io/cloud-builders/docker:20.10.13"
id: build-make-docker
args: ['build', '-f', 'Dockerfile.build', '-t', 'make-docker', '.'] # we need docker and make to run everything.

Expand Down
4 changes: 2 additions & 2 deletions cmd/sdk-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# limitations under the License.

FROM alpine:3.14

ARG ARCH=amd64
RUN apk --update add ca-certificates && \
adduser -D -u 1000 agones

COPY --chown=agones:agones ./bin/sdk-server.linux.amd64 /home/agones/sdk-server
COPY --chown=agones:agones ./bin/sdk-server.linux.$ARCH /home/agones/sdk-server
COPY --chown=agones:agones ./bin/LICENSES ./bin/dependencies-src.tgz /home/agones/

USER 1000
Expand Down

0 comments on commit aed208d

Please sign in to comment.