-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/enhance multi platform build (#66)
Signed-off-by: Batuhan Apaydın <[email protected]> Co-authored-by: Furkan Turkal <[email protected]>
- Loading branch information
1 parent
06ff0d6
commit 588b0b0
Showing
2 changed files
with
16 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
# Build the manager binary | ||
FROM golang:1.19 as builder | ||
ARG GO_VERSION=1.19 | ||
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} as builder | ||
|
||
WORKDIR /workspace | ||
# Copy the Go Modules manifests | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
# cache deps before building and copying source so that we don't need to re-download as much | ||
# and so that source changes don't invalidate our downloaded layer | ||
RUN go mod download | ||
RUN --mount=type=cache,target=/go/pkg/mod/ \ | ||
--mount=type=bind,source=go.sum,target=go.sum \ | ||
--mount=type=bind,source=go.mod,target=go.mod \ | ||
go mod download -x | ||
|
||
# Copy the go source | ||
COPY cmd/exporter/ cmd/exporter/ | ||
COPY pkg/ pkg/ | ||
|
||
# Build | ||
ARG TARGETARCH | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} GO111MODULE=on go build -o exporter cmd/exporter/main.go | ||
ARG TARGETOS TARGETARCH | ||
RUN --mount=type=cache,target=/go/pkg/mod/ \ | ||
--mount=type=bind,target=. \ | ||
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -o /bin/exporter cmd/exporter/main.go | ||
|
||
# Use distroless as minimal base image to package the exporter binary | ||
# Refer to https://github.com/GoogleContainerTools/distroless for more details | ||
FROM --platform=${TARGETPLATFORM:-linux/amd64} gcr.io/distroless/static:nonroot | ||
WORKDIR / | ||
COPY --from=builder /workspace/exporter . | ||
COPY --from=builder /bin/exporter . | ||
|
||
ENTRYPOINT ["/exporter"] |