Skip to content

Commit 8b1ec24

Browse files
committed
change to distroless base image
1 parent a7055c9 commit 8b1ec24

File tree

3 files changed

+90
-25
lines changed

3 files changed

+90
-25
lines changed

Dockerfile

+36-24
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
1615
ARG BUILDPLATFORM
1716

1817
FROM --platform=$BUILDPLATFORM golang:1.17.2 as builder
@@ -24,30 +23,43 @@ WORKDIR /go/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver
2423
ADD . .
2524
RUN GOARCH=$(echo $TARGETPLATFORM | cut -f2 -d '/') GCE_PD_CSI_STAGING_VERSION=$STAGINGVERSION make gce-pd-driver
2625

27-
# MAD HACKS: Build a version first so we can take the scsi_id bin and put it somewhere else in our real build
28-
FROM k8s.gcr.io/build-image/debian-base:buster-v1.9.0 as mad-hack
29-
RUN clean-install udev
30-
31-
# Start from Kubernetes Debian base
26+
# Start from Kubernetes Debian base.
3227
FROM k8s.gcr.io/build-image/debian-base:buster-v1.9.0 as debian
33-
COPY --from=builder /go/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/bin/gce-pd-csi-driver /gce-pd-csi-driver
34-
35-
3628
# Install necessary dependencies
3729
RUN clean-install util-linux e2fsprogs mount ca-certificates udev xfsprogs
38-
39-
FROM gcr.io/distroless/base
30+
# Since we're leveraging apt to pull in dependencies, we use `gcr.io/distroless/base` because it includes glibc.
31+
FROM gcr.io/distroless/base-debian11
32+
# Copy necessary dependencies into distroless base.
4033
COPY --from=builder /go/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/bin/gce-pd-csi-driver /gce-pd-csi-driver
41-
COPY --from=mad-hack /lib/udev/scsi_id /lib/udev_containerized/scsi_id
42-
# COPY --from=debian /lib/xfsprogs/ /lib/xfsprogs_containerized/
43-
# COPY --from=debian /lib/util-linux/ /lib/util-linux_containerized/
44-
45-
46-
47-
ENTRYPOINT ["/gce-pd-csi-driver"]
48-
49-
# Since you're leveraging apt to pull in dependencies, you'd want to use `gcr.io/distroless/base` as the ultimate base because it includes glibc
50-
51-
52-
# COPY --from=builder /lib/x86_64-linux-gnu/libpthread.so.0 /lib/x86_64-linux-gnu/]
53-
# RUN ["/busybox/sh", "-c", "clean-install util-linux e2fsprogs mount ca-certificates udev xfsprogs"]
34+
COPY --from=debian /lib/udev/scsi_id /lib/udev_containerized/scsi_id
35+
COPY --from=debian /bin/mount /bin/mount
36+
COPY --from=debian /bin/umount /bin/umount
37+
COPY --from=debian /sbin/blkid /sbin/blkidp
38+
COPY --from=debian /sbin/blockdev /sbin/blockdev
39+
COPY --from=debian /sbin/dumpe2fs /sbin/dumpe2fs
40+
COPY --from=debian /sbin/e* /sbin/
41+
COPY --from=debian /sbin/e2fsck /sbin/e2fsck
42+
COPY --from=debian /sbin/fsck /sbin/fsck
43+
COPY --from=debian /sbin/fsck* /sbin/
44+
COPY --from=debian /sbin/fsck.xfs /sbin/fsck.xfs
45+
COPY --from=debian /sbin/mke2fs /sbin/mke2fs
46+
COPY --from=debian /sbin/mkfs* /sbin/
47+
COPY --from=debian /sbin/resize2fs /sbin/resize2fs
48+
COPY --from=debian /sbin/xfs_repair /sbin/xfs_repair
49+
COPY --from=debian /usr/include/xfs /usr/include/xfs
50+
COPY --from=debian /usr/lib/xfsprogs/xfs* /usr/lib/xfsprogs/
51+
COPY --from=debian /usr/sbin/xfs* /usr/sbin/
52+
53+
# Copy x86 shared libraries into distroless base.
54+
COPY --from=debian /lib/x86_64-linux-gnu/libblkid.so.1 /lib/x86_64-linux-gnu/libblkid.so.1
55+
COPY --from=debian /lib/x86_64-linux-gnu/libcom_err.so.2 /lib/x86_64-linux-gnu/libcom_err.so.2
56+
COPY --from=debian /lib/x86_64-linux-gnu/libext2fs.so.2 /lib/x86_64-linux-gnu/libext2fs.so.2
57+
COPY --from=debian /lib/x86_64-linux-gnu/libe2p.so.2 /lib/x86_64-linux-gnu/libe2p.so.2
58+
COPY --from=debian /lib/x86_64-linux-gnu/libmount.so.1 /lib/x86_64-linux-gnu/libmount.so.1
59+
COPY --from=debian /lib/x86_64-linux-gnu/libpcre.so.3 /lib/x86_64-linux-gnu/libpcre.so.3
60+
COPY --from=debian /lib/x86_64-linux-gnu/libreadline.so.5 /lib/x86_64-linux-gnu/libreadline.so.5
61+
COPY --from=debian /lib/x86_64-linux-gnu/libselinux.so.1 /lib/x86_64-linux-gnu/libselinux.so.1
62+
COPY --from=debian /lib/x86_64-linux-gnu/libtinfo.so.6 /lib/x86_64-linux-gnu/libtinfo.so.6
63+
COPY --from=debian /lib/x86_64-linux-gnu/libuuid.so.1 /lib/x86_64-linux-gnu/libuuid.so.1
64+
65+
ENTRYPOINT ["/gce-pd-csi-driver"]

Dockerfile.arm64

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2021 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
ARG BUILDPLATFORM
16+
17+
FROM --platform=$BUILDPLATFORM golang:1.17.2 as builder
18+
19+
ARG STAGINGVERSION
20+
ARG TARGETPLATFORM
21+
22+
WORKDIR /go/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver
23+
ADD . .
24+
RUN GOARCH=$(echo $TARGETPLATFORM | cut -f2 -d '/') GCE_PD_CSI_STAGING_VERSION=$STAGINGVERSION make gce-pd-driver
25+
26+
# Start from Kubernetes Debian base.
27+
FROM k8s.gcr.io/build-image/debian-base:buster-v1.9.0 as debian
28+
# Install necessary dependencies
29+
RUN clean-install util-linux e2fsprogs mount ca-certificates udev xfsprogs
30+
# Since we're leveraging apt to pull in dependencies, we use `gcr.io/distroless/base` because it includes glibc.
31+
FROM gcr.io/distroless/base-debian11
32+
# Copy necessary dependencies into distroless base.
33+
COPY --from=builder /go/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/bin/gce-pd-csi-driver /gce-pd-csi-driver
34+
COPY --from=debian /lib/udev/scsi_id /lib/udev_containerized/scsi_id
35+
COPY --from=debian /bin/mount /bin/mount
36+
COPY --from=debian /bin/umount /bin/umount
37+
COPY --from=debian /sbin/blkid /sbin/blkidp
38+
COPY --from=debian /sbin/blockdev /sbin/blockdev
39+
COPY --from=debian /sbin/dumpe2fs /sbin/dumpe2fs
40+
COPY --from=debian /sbin/e* /sbin/
41+
COPY --from=debian /sbin/e2fsck /sbin/e2fsck
42+
COPY --from=debian /sbin/fsck /sbin/fsck
43+
COPY --from=debian /sbin/fsck* /sbin/
44+
COPY --from=debian /sbin/fsck.xfs /sbin/fsck.xfs
45+
COPY --from=debian /sbin/mke2fs /sbin/mke2fs
46+
COPY --from=debian /sbin/mkfs* /sbin/
47+
COPY --from=debian /sbin/resize2fs /sbin/resize2fs
48+
COPY --from=debian /sbin/xfs_repair /sbin/xfs_repair
49+
COPY --from=debian /usr/include/xfs /usr/include/xfs
50+
COPY --from=debian /usr/lib/xfsprogs/xfs* /usr/lib/xfsprogs/
51+
COPY --from=debian /usr/sbin/xfs* /usr/sbin/
52+
53+
ENTRYPOINT ["/gce-pd-csi-driver"]

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ build-and-push-container-linux-amd64: require-GCE_PD_CSI_STAGING_IMAGE init-buil
9696
--build-arg STAGINGVERSION=$(STAGINGVERSION) --push .
9797

9898
build-and-push-container-linux-arm64: require-GCE_PD_CSI_STAGING_IMAGE init-buildx
99-
$(DOCKER) buildx build --platform=linux/arm64 \
99+
$(DOCKER) buildx build --file=Dockerfile.arm64 --platform=linux/arm64 \
100100
-t $(STAGINGIMAGE):$(STAGINGVERSION)_linux_arm64 \
101101
--build-arg BUILDPLATFORM=linux \
102102
--build-arg STAGINGVERSION=$(STAGINGVERSION) --push .

0 commit comments

Comments
 (0)