Skip to content

Commit

Permalink
Fix Architecture metadata in Dockerfiles for distroless base image re…
Browse files Browse the repository at this point in the history
…ferences
  • Loading branch information
chrischdi committed Aug 17, 2022
1 parent 275670a commit f3ef2ab
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# Run this with docker build --build-arg builder_image=<golang:x.y.z>
ARG builder_image

# Build architecture
ARG ARCH

# Ignore Hadolint rule "Always tag the version of an image explicitly."
# It's an invalid finding since the image is explicitly set in the Makefile.
# https://github.com/hadolint/hadolint/wiki/DL3006
Expand Down Expand Up @@ -60,7 +63,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
5 changes: 4 additions & 1 deletion cmd/clusterctl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# Run this with docker build --build-arg builder_image=<golang:x.y.z>
ARG builder_image

# Build architecture
ARG ARCH

# Ignore Hadolint rule "Always tag the version of an image explicitly."
# It's an invalid finding since the image is explicitly set in the Makefile.
# https://github.com/hadolint/hadolint/wiki/DL3006
Expand Down Expand Up @@ -60,7 +63,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
5 changes: 4 additions & 1 deletion test/extension/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# Run this with docker build --build-arg builder_image=<golang:x.y.z>
ARG builder_image

# Build architecture
ARG ARCH

# Ignore Hadolint rule "Always tag the version of an image explicitly."
# It's an invalid finding since the image is explicitly set in the Makefile.
# https://github.com/hadolint/hadolint/wiki/DL3006
Expand Down Expand Up @@ -63,7 +66,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
8 changes: 7 additions & 1 deletion test/infrastructure/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# Run this with docker build --build-arg builder_image=<golang:x.y.z>
ARG builder_image

# Build architecture
ARG ARCH

# Ignore Hadolint rule "Always tag the version of an image explicitly."
# It's an invalid finding since the image is explicitly set in the Makefile.
# https://github.com/hadolint/hadolint/wiki/DL3006
Expand Down Expand Up @@ -57,6 +60,9 @@ 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 \
Expand All @@ -67,7 +73,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
# Ignore Hadolint rule "Using latest is prone to errors if the image will ever update. Pin the version explicitly to a release tag."
# https://github.com/hadolint/hadolint/wiki/DL3007
# hadolint ignore=DL3007
FROM gcr.io/distroless/static:latest
FROM --platform=${ARCH} gcr.io/distroless/static:latest

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

0 comments on commit f3ef2ab

Please sign in to comment.