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

[release-1.2] 🐛 Fix Architecture metadata in Dockerfiles for distroless base image references #7077

Merged
Merged
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
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
# Build the manager binary
# Run this with docker build --build-arg builder_image=<golang:x.y.z>
ARG builder_image

# Build architecture
ARG ARCH

FROM ${builder_image} as builder
WORKDIR /workspace

Expand Down Expand Up @@ -55,7 +59,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
-o manager ${package}

# Production image
FROM gcr.io/distroless/static:nonroot
FROM --platform=${ARCH} gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
# Use uid of nonroot user (65532) because kubernetes expects numeric user when applying pod security policies
Expand Down
6 changes: 5 additions & 1 deletion cmd/clusterctl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
# Build the clusterctl binary
# Run this with docker build --build-arg builder_image=<golang:x.y.z>
ARG builder_image

# Build architecture
ARG ARCH

FROM ${builder_image} as builder
WORKDIR /workspace

Expand Down Expand Up @@ -55,7 +59,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
-o clusterctl ${package}

# Production image
FROM gcr.io/distroless/static:nonroot
FROM --platform=${ARCH} gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/clusterctl .
# Use uid of nonroot user (65532) because kubernetes expects numeric user when applying pod security policies
Expand Down
6 changes: 5 additions & 1 deletion test/extension/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
# Build the extension binary
# Run this with docker build --build-arg builder_image=<golang:x.y.z>
ARG builder_image

# Build architecture
ARG ARCH

FROM ${builder_image} as builder
WORKDIR /workspace

Expand Down Expand Up @@ -58,7 +62,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
-o /workspace/extension ${package}

# Production image
FROM gcr.io/distroless/static:nonroot
FROM --platform=${ARCH} gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/extension .
# Use uid of nonroot user (65532) because kubernetes expects numeric user when applying pod security policies
Expand Down
9 changes: 8 additions & 1 deletion test/infrastructure/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

# Run this with docker build --build-arg builder_image=<golang:x.y.z>
ARG builder_image

# Build architecture
ARG ARCH

FROM ${builder_image} as builder

# Run this with docker build --build-arg goproxy=$(go env GOPROXY) to override the goproxy
Expand Down Expand Up @@ -52,13 +56,16 @@ COPY . .
# Essentially, change directories into CAPD
WORKDIR /workspace/test/infrastructure/docker

# Build
ARG ARCH

# Build the CAPD manager using the compiler cache folder
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -trimpath -a -o /workspace/manager main.go

# NOTE: CAPD can't use non-root because docker requires access to the docker socket
FROM gcr.io/distroless/static:latest
FROM --platform=${ARCH} gcr.io/distroless/static:latest

WORKDIR /
COPY --from=builder /workspace/manager .
Expand Down