Skip to content

Commit

Permalink
Fix arm64 cross-compilation/multi-platform build.
Browse files Browse the repository at this point in the history
  • Loading branch information
walkline committed Mar 3, 2024
1 parent 641e089 commit 2105e7b
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 12 deletions.
5 changes: 4 additions & 1 deletion apps/authserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
FROM --platform=${BUILDPLATFORM} golang:1.21-alpine AS build

ARG TARGETOS
ARG TARGETARCH

# runs from project directory
WORKDIR /

COPY . .

RUN go mod download

RUN go build /apps/authserver/cmd/authserver/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" /apps/authserver/cmd/authserver/main.go

FROM alpine:3.19

Expand Down
5 changes: 4 additions & 1 deletion apps/charserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
FROM --platform=${BUILDPLATFORM} golang:1.21-alpine AS build

ARG TARGETOS
ARG TARGETARCH

# runs from project directory
WORKDIR /

COPY . .

RUN go mod download
RUN go build /apps/charserver/cmd/charserver/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" /apps/charserver/cmd/charserver/main.go

FROM alpine:3.19

Expand Down
5 changes: 4 additions & 1 deletion apps/chatserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
FROM --platform=${BUILDPLATFORM} golang:1.21-alpine AS build

ARG TARGETOS
ARG TARGETARCH

# runs from project directory
WORKDIR /

COPY . .

RUN go mod download
RUN go build /apps/chatserver/cmd/chatserver/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" /apps/chatserver/cmd/chatserver/main.go

FROM alpine:3.19

Expand Down
5 changes: 4 additions & 1 deletion apps/game-load-balancer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# syntax = docker/dockerfile:1-experimental
FROM --platform=${BUILDPLATFORM} golang:1.21-alpine AS build

ARG TARGETOS
ARG TARGETARCH

# runs from project directory
WORKDIR /

Expand All @@ -9,7 +12,7 @@ RUN go mod download

COPY . .

RUN go build /apps/game-load-balancer/cmd/game-load-balancer/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" /apps/game-load-balancer/cmd/game-load-balancer/main.go

FROM alpine:3.19

Expand Down
5 changes: 4 additions & 1 deletion apps/groupserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
FROM --platform=${BUILDPLATFORM} golang:1.21-alpine AS build

ARG TARGETOS
ARG TARGETARCH

# runs from project directory
WORKDIR /

COPY . .

RUN go mod download
RUN go build /apps/groupserver/cmd/groupserver/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" /apps/groupserver/cmd/groupserver/main.go

FROM alpine:3.19

Expand Down
5 changes: 4 additions & 1 deletion apps/guidserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
FROM --platform=${BUILDPLATFORM} golang:1.21-alpine AS build

ARG TARGETOS
ARG TARGETARCH

# runs from project directory
WORKDIR /

COPY . .

RUN go mod download
RUN go build /apps/guidserver/cmd/guidserver/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" /apps/guidserver/cmd/guidserver/main.go

FROM alpine:3.19

Expand Down
5 changes: 4 additions & 1 deletion apps/guildserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
FROM --platform=${BUILDPLATFORM} golang:1.21-alpine AS build

ARG TARGETOS
ARG TARGETARCH

# runs from project directory
WORKDIR /

COPY . .

RUN go mod download
RUN go build /apps/guildserver/cmd/guildserver/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" /apps/guildserver/cmd/guildserver/main.go

FROM alpine:3.19

Expand Down
5 changes: 4 additions & 1 deletion apps/mailserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
FROM --platform=${BUILDPLATFORM} golang:1.21-alpine AS build

ARG TARGETOS
ARG TARGETARCH

# runs from project directory
WORKDIR /

COPY . .

RUN go mod download
RUN go build /apps/mailserver/cmd/mailserver/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" /apps/mailserver/cmd/mailserver/main.go

FROM alpine:3.19

Expand Down
5 changes: 4 additions & 1 deletion apps/servers-registry/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# syntax = docker/dockerfile:1-experimental
FROM --platform=${BUILDPLATFORM} golang:1.21-alpine AS build

ARG TARGETOS
ARG TARGETARCH

# runs from project directory
WORKDIR /

Expand All @@ -9,7 +12,7 @@ RUN go mod download

COPY . .

RUN go build /apps/servers-registry/cmd/servers-registry/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" /apps/servers-registry/cmd/servers-registry/main.go

FROM alpine:3.19

Expand Down
6 changes: 3 additions & 3 deletions game-server/azerothcore/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=${BUILDPLATFORM} golang:1.21 AS build-sidecar
FROM golang:1.21 AS build-sidecar

# runs from project directory
WORKDIR $GOPATH/src/github.com/walkline/ToCloud9
Expand All @@ -9,7 +9,7 @@ RUN go mod download

RUN go build -o libsidecar.so -buildmode=c-shared ./game-server/libsidecar/

FROM --platform=${BUILDPLATFORM} ubuntu:22.04 AS build-core
FROM ubuntu:22.04 AS build-core

ENV DEBIAN_FRONTEND=noninteractive

Expand Down Expand Up @@ -58,7 +58,7 @@ WORKDIR /repo/bin
RUN cmake --build . --config "RelWithDebInfo" -j $(($(nproc) + 1))
RUN cmake --install . --config "RelWithDebInfo"

FROM --platform=${BUILDPLATFORM} ubuntu:22.04
FROM ubuntu:22.04

RUN apt-get update && \
apt-get install -y --no-install-recommends \
Expand Down

0 comments on commit 2105e7b

Please sign in to comment.