Skip to content
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
13 changes: 6 additions & 7 deletions components/tensorboard-controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
#
# ${PATH_TO_KUBEFLOW/KUBEFLOW repo}/components
#
FROM golang:1.17 as builder
FROM golang:1.24 as builder

WORKDIR /workspace
WORKDIR /workspace/tensorboard-controller
# Copy the Go Modules manifests
COPY tensorboard-controller /workspace/tensorboard-controller
# 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 cd /workspace/tensorboard-controller && go mod download

WORKDIR /workspace/tensorboard-controller
COPY tensorboard-controller/go.mod tensorboard-controller/go.sum ./
RUN go mod download

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can copy go.mod and go.sum first, then run go mod download, and only after that copy the rest of the source
This preserves Docker layer caching: dependencies are downloaded only when the module files change, not every time source code changes. It significantly speeds up builds.

# Copy only Go module files first for better layer caching
COPY tensorboard-controller/go.mod tensorboard-controller/go.sum ./
# Download dependencies based on mod files
RUN go mod download
# Now copy the full source
COPY tensorboard-controller/ ./


# Build
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux go build -a -o /manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/tensorboard-controller/manager .
USER 65532:65532
COPY --from=builder /manager /manager

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the copy of the compiled binary should be before switching to the non-root user
This aligns with standard Docker conventions and avoids permission or ownership ambiguity in the final image.

Suggested change
COPY --from=builder /manager /manager
COPY --from=builder /manager /manager
USER 65532:65532


ENTRYPOINT ["/manager"]
2 changes: 1 addition & 1 deletion components/tensorboard-controller/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/kubeflow/kubeflow/components/tensorboard-controller

go 1.17
go 1.24

require (
github.com/go-logr/logr v1.2.0
Expand Down