Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Allow multi-arch builds (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
jontg authored Feb 28, 2022
1 parent af69ad3 commit 1e6849a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Build image
FROM golang:1.17 as build
FROM --platform=$BUILDPLATFORM golang:1.17 as build
ARG BUILDPLATFORM
ARG TARGETPLATFORM
# https://github.com/docker/buildx/issues/510#issuecomment-768432329
ENV BUILDPLATFORM=${BUILDPLATFORM:-linux/amd64}
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}

WORKDIR /go/src

Expand All @@ -14,7 +19,7 @@ ADD . /go/src
ARG VERSION

# Build the server inside the container
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo \
RUN CGO_ENABLED=0 GOOS=${TARGETPLATFORM%/*} GOARCH=${TARGETPLATFORM#*/} go build -a -installsuffix cgo \
-ldflags "-w -s -X main.Version=$VERSION" -o /gubernator /go/src/cmd/gubernator/main.go

# Create our deploy image
Expand Down
9 changes: 7 additions & 2 deletions Dockerfile-cli
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Build image
FROM golang:1.17 as build
FROM --platform=$BUILDPLATFORM golang:1.17 as build
ARG BUILDPLATFORM
ARG TARGETPLATFORM
# https://github.com/docker/buildx/issues/510#issuecomment-768432329
ENV BUILDPLATFORM=${BUILDPLATFORM:-linux/amd64}
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}

WORKDIR /go/src

Expand All @@ -14,7 +19,7 @@ ADD . /go/src
ARG VERSION

# Build the server inside the container
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo \
RUN CGO_ENABLED=0 GOOS=${TARGETPLATFORM%/*} GOARCH=${TARGETPLATFORM#*/} go build -a -installsuffix cgo \
-ldflags "-w -s -X main.Version=$VERSION" -o /gubernator-cli /go/src/cmd/gubernator-cli/main.go

# Create our deploy image
Expand Down

0 comments on commit 1e6849a

Please sign in to comment.