Skip to content

Commit b809212

Browse files
authored
Merge pull request #5750 from thaJeztah/cleanup_test_dockerfile
Refactor / optimize contrib/Dockerfile.test
2 parents 1292c50 + 9537bc2 commit b809212

2 files changed

Lines changed: 54 additions & 36 deletions

File tree

contrib/Dockerfile.test

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,72 +11,89 @@
1111
# docker build -t containerd-test --build-arg RUNC_VERSION=v1.0.0-rc94 -f Dockerfile.test ../
1212

1313
ARG GOLANG_VERSION=1.16.6
14+
ARG GOLANG_IMAGE=golang
1415

15-
FROM golang:${GOLANG_VERSION} AS golang-base
16-
RUN mkdir -p /go/src/github.com/containerd/containerd
17-
WORKDIR /go/src/github.com/containerd/containerd
18-
19-
# Install proto3
20-
FROM golang-base AS proto3
21-
RUN apt-get update && apt-get install -y \
22-
autoconf \
23-
automake \
24-
g++ \
25-
libtool \
26-
unzip \
27-
--no-install-recommends
28-
29-
COPY script/setup/install-protobuf install-protobuf
30-
RUN ./install-protobuf
16+
FROM ${GOLANG_IMAGE}:${GOLANG_VERSION} AS golang
3117

3218
# Install runc
33-
FROM golang-base AS runc
34-
RUN apt-get update && apt-get install -y \
35-
curl \
19+
FROM golang AS runc
20+
RUN apt-get update && apt-get install -y --no-install-recommends \
3621
libseccomp-dev \
37-
--no-install-recommends
22+
&& rm -rf /var/lib/apt/lists/*
3823

3924
COPY script/setup/runc-version script/setup/install-runc ./
4025
# Allow overriding the version of runc to install through build-args
4126
ARG RUNC_VERSION
4227
ARG GOPROXY=direct
28+
ARG DESTDIR=/build
4329
RUN ./install-runc
4430

45-
FROM golang-base AS dev
46-
RUN apt-get update && apt-get install -y \
31+
FROM golang AS build-env
32+
RUN apt-get update && apt-get install -y --no-install-recommends \
4733
libbtrfs-dev \
4834
btrfs-progs \
49-
gcc \
50-
git \
5135
libseccomp-dev \
52-
make \
5336
xfsprogs \
54-
--no-install-recommends
37+
&& rm -rf /var/lib/apt/lists/*
38+
RUN mkdir -p /go/src/github.com/containerd/containerd
39+
WORKDIR /go/src/github.com/containerd/containerd
5540

56-
COPY --from=proto3 /usr/local/bin/protoc /usr/local/bin/protoc
57-
COPY --from=proto3 /usr/local/include/google /usr/local/include/google
58-
COPY --from=runc /usr/local/sbin/runc /usr/local/go/bin/runc
41+
FROM golang AS cni
42+
ENV DESTDIR=/build
43+
COPY script/setup/install-cni ./
44+
COPY go.mod /go/src/github.com/containerd/containerd/go.mod
45+
RUN ./install-cni
5946

47+
FROM golang AS critools
48+
ARG DESTDIR=/build
49+
COPY script/setup/install-critools script/setup/critools-version ./
50+
RUN GOBIN=$DESTDIR/usr/local/bin ./install-critools
51+
52+
FROM build-env AS containerd
53+
ARG DESTDIR=/build
6054
COPY . .
55+
RUN make BUILDTAGS="no_btrfs no_devmapper" binaries install
6156

6257
# cri-in-userns stage is for testing "CRI-in-UserNS", which should be used in conjunction with
6358
# "Kubelet-in-UserNS": https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/2033-kubelet-in-userns-aka-rootless
6459
# This feature is mostly expected to be used for `kind` and `minikube`.
6560
#
6661
# Requires Rootless Docker/Podman/nerdctl with cgroup v2 delegation: https://rootlesscontaine.rs/getting-started/common/cgroup2/
6762
# (Rootless Docker/Podman/nerdctl prepares the UserNS, so we do not need to create UserNS by ourselves)
68-
FROM dev AS cri-in-userns
69-
RUN make BUILDTAGS="no_btrfs no_devmapper" binaries install
70-
RUN apt-get update && apt-get install -y iptables
71-
RUN ./script/setup/install-cni
72-
RUN ./script/setup/install-critools
63+
FROM build-env AS cri-in-userns
64+
RUN apt-get update && apt-get install -y --no-install-recommends \
65+
iptables \
66+
&& rm -rf /var/lib/apt/lists/*
7367
COPY contrib/Dockerfile.test.d/cri-in-userns/etc_containerd_config.toml /etc/containerd/config.toml
74-
COPY contrib/Dockerfile.test.d/cri-in-userns/docker-entrypoint.sh /docker-entrypoint.sh
68+
COPY contrib/Dockerfile.test.d/cri-in-userns/docker-entrypoint.sh /docker-entrypoint.sh
69+
COPY --from=runc /build/ /
70+
COPY --from=cni /build/ /
71+
COPY --from=critools /build/ /
72+
COPY --from=containerd /build/ /
7573
VOLUME /var/lib/containerd
7674
ENTRYPOINT ["/docker-entrypoint.sh"]
7775
# Skip "runtime should support unsafe sysctls": `container init caused: write sysctl key fs.mqueue.msg_max: open /proc/sys/fs/mqueue/msg_max: permission denied`
7876
# Skip "runtime should support safe sysctls": `container init caused: write sysctl key kernel.shm_rmid_forced: open /proc/sys/kernel/shm_rmid_forced: permission denied`
7977
# Skip "should allow privilege escalation when (NoNewPrivis is) false": expected log "Effective uid: 0\n" (stream="stdout") not found in logs [{timestamp:{wall:974487519 ext:63761339984 loc:<nil>} stream:stdout log:Effective uid: 1000) }]
8078
CMD ["critest", "--ginkgo.skip=should support unsafe sysctls|should support safe sysctls|should allow privilege escalation when false"]
8179

82-
FROM dev AS default
80+
# Install proto3
81+
FROM golang AS proto3
82+
ARG DESTDIR=/build
83+
RUN apt-get update && apt-get install -y --no-install-recommends \
84+
autoconf \
85+
automake \
86+
g++ \
87+
libtool \
88+
unzip \
89+
&& rm -rf /var/lib/apt/lists/*
90+
91+
COPY script/setup/install-protobuf install-protobuf
92+
RUN ./install-protobuf \
93+
&& mv /usr/local/bin/protoc $DESTDIR/usr/local/bin/protoc \
94+
&& mv /usr/local/include/google $DESTDIR/usr/local/include/google
95+
96+
FROM build-env AS dev
97+
COPY --from=proto3 /build/ /
98+
COPY --from=runc /build/ /
99+
COPY . .

script/setup/install-critools

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ git checkout "$CRITEST_COMMIT"
3434
make
3535
make install -e DESTDIR=${DESTDIR:=''} BINDIR=/usr/local/bin
3636

37+
mkdir -p ${DESTDIR:=''}/etc/
3738
cat << EOF | tee ${DESTDIR:=''}/etc/crictl.yaml
3839
runtime-endpoint: unix:///run/containerd/containerd.sock
3940
EOF

0 commit comments

Comments
 (0)