Skip to content

Commit

Permalink
Feature/enhance multi platform build (#66)
Browse files Browse the repository at this point in the history
Signed-off-by: Batuhan Apaydın <[email protected]>
Co-authored-by: Furkan Turkal <[email protected]>
  • Loading branch information
developer-guy and Dentrax authored Jan 25, 2024
1 parent 06ff0d6 commit 588b0b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/create-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Create images
on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: write
Expand Down Expand Up @@ -62,6 +63,8 @@ jobs:
push: true
tags: |
${{ env.REGISTRY }}/${{ matrix.apps }}:${{ env.IMG_TAG }}
build-args: |
GO_VERSION=${{ env.GO_VERSION }}
labels: |
org.opencontainers.image.source=${{ github.repositoryUrl }}
Expand Down
22 changes: 13 additions & 9 deletions docker/exporter/Dockerfile
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"]

0 comments on commit 588b0b0

Please sign in to comment.