From 98e0aa364dd09e1aa2aa6ba88e6e7fb9839ee4e3 Mon Sep 17 00:00:00 2001 From: Fernando Takagi Date: Tue, 9 May 2023 21:48:56 -0300 Subject: [PATCH 1/4] Enable cross-compilation in Dockerfiles. --- build/Dockerfile | 6 +++--- build/Dockerfile.dsym | 6 +++--- build/pluginbuilder/Dockerfile | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index 1c5add8c7f..145a0248b2 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -15,13 +15,13 @@ # docker build "$PWD" --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version=v2.1.1 -t heroiclabs/nakama:2.1.1 # docker build "$PWD" --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version="$(git rev-parse --short HEAD)" -t heroiclabs/nakama-prerelease:"$(git rev-parse --short HEAD)" -FROM golang:1.20.3-bullseye as builder +FROM --platform=$BUILDPLATFORM golang:1.20.3-bullseye as builder ARG commit ARG version -ENV GOOS linux -ENV GOARCH amd64 +ENV GOOS $TARGETOS +ENV GOARCH $TARGETARCH ENV CGO_ENABLED 1 RUN apt-get update && \ diff --git a/build/Dockerfile.dsym b/build/Dockerfile.dsym index 2aa0084c0c..7eee045bcf 100644 --- a/build/Dockerfile.dsym +++ b/build/Dockerfile.dsym @@ -15,13 +15,13 @@ # docker build "$PWD" --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version=v2.1.1 -t heroiclabs/nakama:2.1.1 # docker build "$PWD" --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version="v2.1.1-$(git rev-parse --short HEAD)" -t heroiclabs/nakama-prerelease:"2.1.1-$(git rev-parse --short HEAD)" -FROM golang:1.20.3-bullseye as builder +FROM --platform=$BUILDPLATFORM golang:1.20.3-bullseye as builder ARG commit ARG version -ENV GOOS linux -ENV GOARCH amd64 +ENV GOOS $TARGETOS +ENV GOARCH $TARGETARCH ENV CGO_ENABLED 1 RUN apt-get update && \ diff --git a/build/pluginbuilder/Dockerfile b/build/pluginbuilder/Dockerfile index fd3a2eb924..ad5bec0667 100644 --- a/build/pluginbuilder/Dockerfile +++ b/build/pluginbuilder/Dockerfile @@ -15,7 +15,7 @@ # docker build "$PWD" --file ./Dockerfile.pluginbuilder --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version=v2.1.1 -t heroiclabs/nakama-pluginbuilder:2.1.1 # docker build "$PWD" --file ./Dockerfile.pluginbuilder --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version="v2.1.1-$(git rev-parse --short HEAD)" -t heroiclabs/nakama-prerelease:"2.1.1-$(git rev-parse --short HEAD)" -FROM golang:1.20.3-bullseye as builder +FROM --platform=$BUILDPLATFORM golang:1.20.3-bullseye as builder MAINTAINER Heroic Labs @@ -26,8 +26,8 @@ LABEL version=$version LABEL variant=nakama-pluginbuilder LABEL description="A support container to build Go code for Nakama server's runtime." -ENV GOOS linux -ENV GOARCH amd64 +ENV GOOS $TARGETOS +ENV GOARCH $TARGETARCH ENV CGO_ENABLED 1 RUN apt-get update && \ From 0c262773d019adcf3d25fa1ea28a283d418b0066 Mon Sep 17 00:00:00 2001 From: Fernando Takagi Date: Tue, 9 May 2023 21:49:27 -0300 Subject: [PATCH 2/4] Update instructions for multi-platform docker images. --- build/README.md | 51 +++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/build/README.md b/build/README.md index e638503f40..0577a654ff 100644 --- a/build/README.md +++ b/build/README.md @@ -39,8 +39,7 @@ These steps are run for each new release. 3. Execute the cross-compiled build helper. ``` - xgo --targets=darwin/arm64,darwin/amd64,linux/amd64,linux/arm64,windows/amd64 --trimpath --ldflags "-s -w -X main.version=2.1.0 -X main.commitID=$(git rev-parse --short HEAD 2>/dev/null)" -github.com/heroiclabs/nakama + xgo --targets=darwin/arm64,darwin/amd64,linux/amd64,linux/arm64,windows/amd64 --trimpath --ldflags "-s -w -X main.version=2.1.0 -X main.commitID=$(git rev-parse --short HEAD 2>/dev/null)" github.com/heroiclabs/nakama ``` This will build binaries for all target platforms supported officially by Heroic Labs. @@ -57,55 +56,61 @@ github.com/heroiclabs/nakama With the release generated we can create the official container image. -1. Build the container image. +These steps are one off to install the required build utilities. + +1. Ensure you have the Docker Buildx client installed. (https://docs.docker.com/build/architecture/#install-buildx) + +2. Create a new builder instance that supports multi-platform builds, and switch to use it. ``` - cd build - docker build "$PWD" --platform "linux/amd64" --file ./Dockerfile --build-arg commit="$(git rev-parse --short HEAD 2>/dev/null)" --build-arg version=2.1.0 -t heroiclabs/nakama:2.1.0 + docker buildx create --name mybuilder --driver docker-container --bootstrap --use ``` -2. Push the image to the container registry. +These steps are run for each new release. + +1. Use an existing builder that supports multi-platform builds. ``` - docker tag heroiclabs/nakama:latest - docker push heroiclabs/nakama:2.1.0 - docker push heroiclabs/nakama:latest + docker buildx use mybuilder + ``` + +2. Build the container image and push to the container registry. + + ``` + cd build + docker build "$PWD" --platform linux/amd64,linux/arm64 --file ./Dockerfile --build-arg commit="$(git rev-parse --short HEAD 2>/dev/null)" --build-arg version=2.1.0 -t heroiclabs/nakama:2.1.0 -t heroiclabs/nakama:latest --push ``` ## Build Nakama Image (dSYM) With the release generated we can also create an official container image which includes debug symbols. -1. Build the container image. +1. Use an existing builder that supports multi-platform builds. ``` - cd build - docker build "$PWD" --platform "linux/amd64" --file ./Dockerfile.dsym --build-arg commit="$(git rev-parse --short HEAD 2>/dev/null)" --build-arg version=2.1.0 -t heroiclabs/nakama-dsym:2.1.0 + docker buildx use mybuilder ``` -2. Push the image to the container registry. +2. Build the container image and push to the container registry. ``` - docker tag heroiclabs/nakama-dsym:latest - docker push heroiclabs/nakama-dsym:2.1.0 - docker push heroiclabs/nakama-dsym:latest + cd build + docker build "$PWD" --platform linux/amd64,linux/arm64 --file ./Dockerfile.dsym --build-arg commit="$(git rev-parse --short HEAD 2>/dev/null)" --build-arg version=2.1.0 -t heroiclabs/nakama-dsym:2.1.0 -t heroiclabs/nakama-dsym:latest --push ``` ## Build Plugin Builder Image With the official release image generated we can create a container image to help with Go runtime development. -1. Build the container image. +1. Use an existing builder that supports multi-platform builds. ``` - cd build/pluginbuilder - docker build "$PWD" --platform "linux/amd64" --file ./Dockerfile --build-arg commit="$(git rev-parse --short HEAD 2>/dev/null)" --build-arg version=2.1.0 -t heroiclabs/nakama-pluginbuilder:2.1.0 + docker buildx use mybuilder ``` -2. Push the image to the container registry. +2. Build the container image. ``` - docker tag heroiclabs/nakama-pluginbuilder:latest - docker push heroiclabs/nakama-pluginbuilder:2.1.0 - docker push heroiclabs/nakama-pluginbuilder:latest + cd build/pluginbuilder + docker build "$PWD" --platform linux/amd64,linux/arm64 --file ./Dockerfile --build-arg commit="$(git rev-parse --short HEAD 2>/dev/null)" --build-arg version=2.1.0 -t heroiclabs/nakama-pluginbuilder:2.1.0 -t heroiclabs/nakama-pluginbuilder:latest --push ``` From 60f2a8b02574518451bc7d74b9b2999b40f4dcb3 Mon Sep 17 00:00:00 2001 From: Fernando Takagi Date: Wed, 10 May 2023 11:29:44 -0300 Subject: [PATCH 3/4] Update instructions around emulation support. --- build/README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/build/README.md b/build/README.md index 0577a654ff..6d2f3c3329 100644 --- a/build/README.md +++ b/build/README.md @@ -58,9 +58,19 @@ With the release generated we can create the official container image. These steps are one off to install the required build utilities. -1. Ensure you have the Docker Buildx client installed. (https://docs.docker.com/build/architecture/#install-buildx) +1. Install Docker Desktop. -2. Create a new builder instance that supports multi-platform builds, and switch to use it. +or + +1. Install the Docker buildx client manually. (https://docs.docker.com/build/architecture/#install-buildx) + +2. Install the emulators for foreign architectures. + + ``` + docker run --privileged --rm tonistiigi/binfmt --install all + ``` + +3. Create a new builder instance that supports multi-platform builds, and switch to use it. ``` docker buildx create --name mybuilder --driver docker-container --bootstrap --use From 956256a4dccfca2e736359fc2ce6fe7f2dac6f73 Mon Sep 17 00:00:00 2001 From: Fernando Takagi Date: Wed, 10 May 2023 11:38:48 -0300 Subject: [PATCH 4/4] Fix command. --- build/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/README.md b/build/README.md index 6d2f3c3329..62f6d9b35e 100644 --- a/build/README.md +++ b/build/README.md @@ -88,7 +88,7 @@ These steps are run for each new release. ``` cd build - docker build "$PWD" --platform linux/amd64,linux/arm64 --file ./Dockerfile --build-arg commit="$(git rev-parse --short HEAD 2>/dev/null)" --build-arg version=2.1.0 -t heroiclabs/nakama:2.1.0 -t heroiclabs/nakama:latest --push + docker buildx build "$PWD" --platform linux/amd64,linux/arm64 --file ./Dockerfile --build-arg commit="$(git rev-parse --short HEAD 2>/dev/null)" --build-arg version=2.1.0 -t heroiclabs/nakama:2.1.0 -t heroiclabs/nakama:latest --push ``` ## Build Nakama Image (dSYM) @@ -105,7 +105,7 @@ With the release generated we can also create an official container image which ``` cd build - docker build "$PWD" --platform linux/amd64,linux/arm64 --file ./Dockerfile.dsym --build-arg commit="$(git rev-parse --short HEAD 2>/dev/null)" --build-arg version=2.1.0 -t heroiclabs/nakama-dsym:2.1.0 -t heroiclabs/nakama-dsym:latest --push + docker buildx build "$PWD" --platform linux/amd64,linux/arm64 --file ./Dockerfile.dsym --build-arg commit="$(git rev-parse --short HEAD 2>/dev/null)" --build-arg version=2.1.0 -t heroiclabs/nakama-dsym:2.1.0 -t heroiclabs/nakama-dsym:latest --push ``` ## Build Plugin Builder Image @@ -122,5 +122,5 @@ With the official release image generated we can create a container image to hel ``` cd build/pluginbuilder - docker build "$PWD" --platform linux/amd64,linux/arm64 --file ./Dockerfile --build-arg commit="$(git rev-parse --short HEAD 2>/dev/null)" --build-arg version=2.1.0 -t heroiclabs/nakama-pluginbuilder:2.1.0 -t heroiclabs/nakama-pluginbuilder:latest --push + docker buildx build "$PWD" --platform linux/amd64,linux/arm64 --file ./Dockerfile --build-arg commit="$(git rev-parse --short HEAD 2>/dev/null)" --build-arg version=2.1.0 -t heroiclabs/nakama-pluginbuilder:2.1.0 -t heroiclabs/nakama-pluginbuilder:latest --push ```