-
Notifications
You must be signed in to change notification settings - Fork 716
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
Distroless image for TF operator #1124
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,17 @@ | ||
FROM golang:1.10 AS build-image | ||
FROM golang:1.13.5 AS build-image | ||
|
||
ADD . /go/src/github.com/kubeflow/tf-operator | ||
|
||
WORKDIR /go/src/github.com/kubeflow/tf-operator | ||
|
||
RUN go build -o tf-operator.v1 ./cmd/tf-operator.v1 | ||
|
||
FROM registry.access.redhat.com/ubi8/ubi:latest | ||
FROM gcr.io/distroless/base-debian10 | ||
|
||
# TODO(jlewi): We should probably change the directory to /opt/kubeflow. | ||
RUN mkdir -p /opt/kubeflow/samples | ||
COPY third_party/library/license.txt /opt/license.txt | ||
|
||
COPY tf_smoke.py /opt/kubeflow/samples/ | ||
RUN chmod a+x /opt/kubeflow/samples/* | ||
COPY vendor /opt/ | ||
|
||
COPY --from=build-image /go/src/github.com/kubeflow/tf-operator/tf-operator.v1 /opt/kubeflow | ||
COPY --from=build-image /go/src/github.com/kubeflow/tf-operator/tf-operator.v1 /opt/ | ||
|
||
COPY third_party/library/license.txt /opt/kubeflow/license.txt | ||
|
||
RUN mkdir -p /opt/kubeflow/vendor | ||
COPY vendor /opt/kubeflow/vendor/ | ||
|
||
RUN chmod a+x /opt/kubeflow/tf-operator.v1 | ||
|
||
ENTRYPOINT ["/opt/kubeflow/tf-operator.v1"] | ||
ENTRYPOINT ["/opt/tf-operator.v1"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probable permission issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. Here's the pattern for moving binaries to a distroless image given by the example: The idea here is to keep the distroless image with just the essentials for golang and its binaries. That leaves this system with just the user who's running this binary. So I guess setting permissions isn't necessary as advocated by the example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why base-debian as opposed to base?
https://github.com/GoogleContainerTools/distroless/blob/5a460b2310a3e2e3c0590835614860747d6e8769/examples/go/Dockerfile#L10-L12
Which one is slimmer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jlewi This is a good point.
The sizes are:
base
: 60301780base-debian10
: 62581637I observed that the CVE counts with
base
image are a little higher: 16 Low priorityShould we stick to a lower CVE count rather than opting for lesser size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jlewi Do you have other questions about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the guidance here:
https://github.com/GoogleContainerTools/distroless/tree/master/base
Unless we need glibc, libssl, or openssl we should be able to use the static image.
The "-debian" suffix is explained here.
https://github.com/GoogleContainerTools/distroless#base-operating-system
So IIUC it looks like base = "base-debian9" which likely has more CVE's then "debian10" probably because it is newer.
So I think we want to use "static-debian10" ?
I checked and it looks like the static images are an order of magnitude smaller than the non static images.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jlewi it seems the go binary which we are using requires C runtime for imports like 'net' packages.
If we build and run on 'static-debian10' we run into this problem:
Since go starts looking for C runtime packages which we are building against.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to build with
CGO_ENABLED=0
.Could you try this?
CGO_ENABLED=0 GOOS=linux go build -o tf-operator.v1 -ldflags "-w" -a ./cmd/tf-operator.v1