Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build): setup multiarch build for arm64 #1161

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 31 additions & 8 deletions build/Dockerfile
Expand Up @@ -12,29 +12,52 @@
## See the License for the specific language governing permissions and
## limitations under the License.

# 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)"
#############################
# docker build "$PWD" \
# --build-arg repo="https://github.com/heroiclabs/nakama.git"
# --build-arg commit="$(git rev-parse --short HEAD)" \
# --build-arg version="$(git tag -l --sort=-creatordate | head -n 1)" \
# -t heroiclabs/nakama:${"$(git tag -l --sort=-creatordate | head -n 1)":1}
#############################
# OR for a multiarch build:
# ###########################
# ./multiarch_build

FROM golang:1.21.5-bookworm as builder
FROM --platform=$BUILDPLATFORM golang:1.21.5-bookworm as builder

ARG TARGETARCH
ARG commit
ARG version
ARG repo=https://github.com/heroiclabs/nakama.git

ENV GOOS linux
ENV GOARCH amd64
ENV GOARCH=$TARGETARCH
ENV CGO_ENABLED 1

RUN apt-get update && \
RUN dpkg --add-architecture $TARGETARCH && \
apt-get update && \
apt-get -y upgrade && \
apt-get install -y --no-install-recommends ca-certificates gcc libc6-dev git && \
apt-get install -y --no-install-recommends ca-certificates git && \
if [ "${TARGETARCH}" = "amd64" ]; then \
apt-get install -y --no-install-recommends g++-x86-64-linux-gnu libc6-dev-amd64-cross; \
elif [ "${TARGETARCH}" = "arm64" ]; then \
apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu libc6-dev-arm64-cross; \
fi && \
git config --global advice.detachedHead false && \
git clone --quiet --no-checkout https://github.com/heroiclabs/nakama /go/build/nakama
git clone --quiet --no-checkout $repo /go/build/nakama

WORKDIR /go/build/nakama
RUN git checkout --quiet "$commit" && \
if [ "${TARGETARCH}" = "amd64" ]; then \
export CC=x86_64-linux-gnu-gcc && \
export CXX=x86_64-linux-gnu-g++; \
elif [ "${TARGETARCH}" = "arm64" ]; then \
export CC=aarch64-linux-gnu-gcc && \
export CXX=aarch64-linux-gnu-g++; \
fi && \
go build -o /go/build-out/nakama -trimpath -mod=vendor -gcflags "-trimpath $PWD" -asmflags "-trimpath $PWD" -ldflags "-s -w -X main.version=$version -X main.commitID=$commit"

FROM debian:bookworm-slim
FROM --platform=$BUILDPLATFORM debian:bookworm-slim

MAINTAINER Heroic Labs <support@heroiclabs.com>

Expand Down
61 changes: 0 additions & 61 deletions build/Dockerfile.arm64

This file was deleted.

41 changes: 33 additions & 8 deletions build/Dockerfile.dsym
Expand Up @@ -12,29 +12,54 @@
## See the License for the specific language governing permissions and
## limitations under the License.

# docker build "$PWD" --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version=v3.19.0 -t heroiclabs/nakama:3.19.0
# docker build "$PWD" --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version="v3.19.0-$(git rev-parse --short HEAD)" -t heroiclabs/nakama-prerelease:"3.19.0-$(git rev-parse --short HEAD)"
#############################
# docker build "$PWD" \
# --build-arg repo="https://github.com/heroiclabs/nakama.git"
# --build-arg commit="$(git rev-parse --short HEAD)" \
# --build-arg version="$(git tag -l --sort=-creatordate | head -n 1)" \
# -t heroiclabs/nakama:${"$(git tag -l --sort=-creatordate | head -n 1)":1}
#############################
# OR for a multiarch build:
# ###########################
# ./multiarch_build

FROM golang:1.21.5-bookworm as builder
FROM --platform=$BUILDPLATFORM golang:1.21.5-bookworm as builder

ARG TARGETARCH
ARG commit
ARG version
ARG repo=https://github.com/heroiclabs/nakama.git

ENV GOOS linux
ENV GOARCH amd64
ENV GOARCH=$TARGETARCH
ENV CGO_ENABLED 1

RUN apt-get update && \
RUN if [ "${TARGETARCH}" = "amd64" ]; then \
dpkg --add-architecture amd64; \
fi && \
apt-get update && \
apt-get -y upgrade && \
apt-get install -y --no-install-recommends ca-certificates gcc libc6-dev git && \
apt-get install -y --no-install-recommends ca-certificates git && \
if [ "${TARGETARCH}" = "amd64" ]; then \
apt-get install -y --no-install-recommends g++-x86-64-linux-gnu libc6-dev-amd64-cross; \
elif [ "${TARGETARCH}" = "arm64" ]; then \
apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu libc6-dev-arm64-cross; \
fi && \
git config --global advice.detachedHead false && \
git clone --quiet --no-checkout https://github.com/heroiclabs/nakama /go/build/nakama
git clone --quiet --no-checkout $repo /go/build/nakama

WORKDIR /go/build/nakama
RUN git checkout --quiet "$commit" && \
if [ "${TARGETARCH}" = "amd64" ]; then \
export CC=x86_64-linux-gnu-gcc && \
export CXX=x86_64-linux-gnu-g++; \
elif [ "${TARGETARCH}" = "arm64" ]; then \
export CC=aarch64-linux-gnu-gcc && \
export CXX=aarch64-linux-gnu-g++; \
fi && \
go build -o /go/build-out/nakama -trimpath -mod=vendor -gcflags "all=-N -l" -ldflags "-X main.version=$version -X main.commitID=$commit"

FROM debian:bookworm-slim
FROM --platform=$BUILDPLATFORM debian:bookworm-slim

MAINTAINER Heroic Labs <support@heroiclabs.com>

Expand Down
61 changes: 0 additions & 61 deletions build/Dockerfile.dsym.arm64

This file was deleted.

56 changes: 0 additions & 56 deletions build/Dockerfile.local

This file was deleted.