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/README.md b/build/README.md index e638503f40..62f6d9b35e 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,71 @@ 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. Install Docker Desktop. + +or + +1. Install the Docker buildx client manually. (https://docs.docker.com/build/architecture/#install-buildx) + +2. Install the emulators for foreign architectures. ``` - 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 run --privileged --rm tonistiigi/binfmt --install all ``` -2. Push the image to the container registry. +3. Create a new builder instance that supports multi-platform builds, and switch to use it. ``` - docker tag heroiclabs/nakama:latest - docker push heroiclabs/nakama:2.1.0 - docker push heroiclabs/nakama:latest + docker buildx create --name mybuilder --driver docker-container --bootstrap --use + ``` + +These steps are run for each new release. + +1. Use an existing builder that supports multi-platform builds. + + ``` + docker buildx use mybuilder + ``` + +2. Build the container image and push to the container registry. + + ``` + cd build + 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) 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 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 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 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 ``` 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 && \