Skip to content

Commit d4c68d1

Browse files
authored
Merge pull request #985 from pwschuurman/add-verify-deps-script
Add Makefile target that validates the Dockerfile images contain the correct shared library dependencies
2 parents fda5a33 + 46d7e4a commit d4c68d1

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed

Dockerfile

+13-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ENV LIB_DIR_PREFIX x86_64
4040
FROM distroless-base AS distroless-arm64
4141
ENV LIB_DIR_PREFIX aarch64
4242

43-
FROM distroless-$TARGETARCH
43+
FROM distroless-$TARGETARCH as output-image
4444

4545
# Copy necessary dependencies into distroless base.
4646
COPY --from=builder /go/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/bin/gce-pd-csi-driver /gce-pd-csi-driver
@@ -98,4 +98,16 @@ COPY --from=debian /usr/lib/${LIB_DIR_PREFIX}-linux-gnu/libacl.so.1 \
9898
# Copy NVME support required script and rules into distroless base.
9999
COPY deploy/kubernetes/udev/google_nvme_id /lib/udev_containerized/google_nvme_id
100100

101+
# Build stage used for validation of the output-image
102+
# See validate-container-linux-* targets in Makefile
103+
FROM output-image as validation-image
104+
105+
COPY --from=debian /usr/bin/ldd /usr/bin/find /usr/bin/xargs /usr/bin/
106+
COPY --from=builder /go/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/hack/print-missing-deps.sh /print-missing-deps.sh
107+
SHELL ["/bin/bash", "-c"]
108+
RUN /print-missing-deps.sh
109+
110+
# Final build stage, create the real Docker image with ENTRYPOINT
111+
FROM output-image
112+
101113
ENTRYPOINT ["/gce-pd-csi-driver"]

Makefile

+16
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ build-and-push-multi-arch-debug: build-and-push-container-linux-debug build-and-
7979

8080
push-container: build-container
8181

82+
# Used by hack/verify-docker-deps.sh, not used for building artifacts
83+
validate-container-linux-amd64: init-buildx
84+
$(DOCKER) buildx build --platform=linux/amd64 \
85+
-t validation_linux_amd64 \
86+
--target validation-image \
87+
--build-arg BUILDPLATFORM=linux \
88+
--build-arg STAGINGVERSION=$(STAGINGVERSION) .
89+
90+
# Used by hack/verify-docker-deps.sh, not used for building artifacts
91+
validate-container-linux-arm64: init-buildx
92+
$(DOCKER) buildx build --platform=linux/arm64 \
93+
-t validation_linux_arm64 \
94+
--target validation-image \
95+
--build-arg BUILDPLATFORM=linux \
96+
--build-arg STAGINGVERSION=$(STAGINGVERSION) .
97+
8298
build-and-push-container-linux-amd64: require-GCE_PD_CSI_STAGING_IMAGE init-buildx
8399
$(DOCKER) buildx build --platform=linux/amd64 \
84100
-t $(STAGINGIMAGE):$(STAGINGVERSION)_linux_amd64 \

hack/print-missing-deps.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Copyright 2022 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
echo "Verifying Docker Executables have appropriate dependencies"
22+
23+
printMissingDep() {
24+
if /usr/bin/ldd "$@" | grep "not found"; then
25+
echo "!!! Missing deps for $@ !!!"
26+
exit 1
27+
fi
28+
}
29+
30+
export -f printMissingDep
31+
32+
/usr/bin/find / -type f -executable -print | /usr/bin/xargs -I {} /bin/bash -c 'printMissingDep "{}"'

hack/verify-docker-deps.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
# Copyright 2018 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
echo "Verifying Docker Image Dependencies"
22+
23+
PKG_ROOT=$(git rev-parse --show-toplevel)
24+
25+
make -C "${PKG_ROOT}" validate-container-linux-amd64 validate-container-linux-arm64

0 commit comments

Comments
 (0)