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

chore: Adjust Dockerfiles to support multi-platform builds #1782

Open
wants to merge 5 commits into
base: main
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM europe-docker.pkg.dev/kyma-project/prod/external/library/golang:1.23.5-alpine3.21 AS builder
FROM --platform=$BUILDPLATFORM golang:1.23.5-alpine3.21 AS builder

WORKDIR /telemetry-manager-workspace
# Copy the Go Modules manifests
Expand All @@ -17,7 +17,8 @@ COPY internal/ internal/
COPY webhook/ webhook/

# Clean up unused (test) dependencies and build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go mod tidy && go build -a -o manager main.go
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go mod tidy && go build -a -o manager main.go

FROM scratch

Expand Down
30 changes: 24 additions & 6 deletions docs/user/integration/sample-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
FROM golang:1.23 AS builder
RUN mkdir /app
ADD . /app
# Build the app binary
FROM --platform=$BUILDPLATFORM golang:1.23.5 AS builder

# Copy the project
WORKDIR /app
RUN CGO_ENABLED=0 GOOS=linux go build -o main ./...

# 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

# Copy the go source
COPY *.go .

# Clean up unused (test) dependencies and build
RUN go mod tidy
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -a -o main ./...

# Use the scratch image for a minimal image
FROM scratch
LABEL source=git@github.com:kyma-project/telemetry-manager.git
LABEL org.opencontainers.image.source="https://github.com/kyma-project/telemetry-manager"

COPY --from=builder /app .
# Copy the binary, no further dependencies
COPY --from=builder /app/main .
EXPOSE 8080

CMD ["./main"]
Loading