Skip to content

Commit e9f26eb

Browse files
committed
Dockerfile.test: split dev stage, and optimize order
This makes the following changes: - The containerd/config.toml, and docker-entrypoint.sh only occasionally change, so copy them before copying the source code to allow them to be cached. - The cri-in-userns stage does not need files from proto3, so do not copy them - The dev environment does need the file from the proto3 stage, so copy them there. - Change the order of stages. Our CI uses `podman build` which (I think) does not skips stages that are not used for the specified target (like BuildKit does). So I moved stages that are not used for the `cri-in-userns` after that stage. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 25fada0 commit e9f26eb

1 file changed

Lines changed: 29 additions & 29 deletions

File tree

contrib/Dockerfile.test

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,10 @@
1212

1313
ARG GOLANG_VERSION=1.16.6
1414

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
15+
FROM golang:${GOLANG_VERSION} AS golang
3116

3217
# Install runc
33-
FROM golang-base AS runc
18+
FROM golang AS runc
3419
RUN apt-get update && apt-get install -y \
3520
libseccomp-dev \
3621
--no-install-recommends
@@ -41,38 +26,53 @@ ARG RUNC_VERSION
4126
ARG GOPROXY=direct
4227
RUN ./install-runc
4328

44-
FROM golang-base AS dev
29+
FROM golang AS build-env
4530
RUN apt-get update && apt-get install -y \
4631
libbtrfs-dev \
4732
btrfs-progs \
4833
libseccomp-dev \
4934
xfsprogs \
5035
--no-install-recommends
51-
52-
COPY --from=proto3 /usr/local/bin/protoc /usr/local/bin/protoc
53-
COPY --from=proto3 /usr/local/include/google /usr/local/include/google
54-
COPY --from=runc /usr/local/sbin/runc /usr/local/go/bin/runc
55-
56-
COPY . .
36+
RUN mkdir -p /go/src/github.com/containerd/containerd
37+
WORKDIR /go/src/github.com/containerd/containerd
5738

5839
# cri-in-userns stage is for testing "CRI-in-UserNS", which should be used in conjunction with
5940
# "Kubelet-in-UserNS": https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/2033-kubelet-in-userns-aka-rootless
6041
# This feature is mostly expected to be used for `kind` and `minikube`.
6142
#
6243
# Requires Rootless Docker/Podman/nerdctl with cgroup v2 delegation: https://rootlesscontaine.rs/getting-started/common/cgroup2/
6344
# (Rootless Docker/Podman/nerdctl prepares the UserNS, so we do not need to create UserNS by ourselves)
64-
FROM dev AS cri-in-userns
65-
RUN make BUILDTAGS="no_btrfs no_devmapper" binaries install
45+
FROM build-env AS cri-in-userns
6646
RUN apt-get update && apt-get install -y iptables
47+
COPY contrib/Dockerfile.test.d/cri-in-userns/etc_containerd_config.toml /etc/containerd/config.toml
48+
COPY contrib/Dockerfile.test.d/cri-in-userns/docker-entrypoint.sh /docker-entrypoint.sh
49+
COPY --from=runc /usr/local/sbin/runc /usr/local/go/bin/runc
50+
COPY . .
6751
RUN ./script/setup/install-cni
6852
RUN ./script/setup/install-critools
69-
COPY contrib/Dockerfile.test.d/cri-in-userns/etc_containerd_config.toml /etc/containerd/config.toml
70-
COPY contrib/Dockerfile.test.d/cri-in-userns/docker-entrypoint.sh /docker-entrypoint.sh
53+
RUN make BUILDTAGS="no_btrfs no_devmapper" binaries install
7154
VOLUME /var/lib/containerd
7255
ENTRYPOINT ["/docker-entrypoint.sh"]
7356
# 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`
7457
# 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`
7558
# 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) }]
7659
CMD ["critest", "--ginkgo.skip=should support unsafe sysctls|should support safe sysctls|should allow privilege escalation when false"]
7760

78-
FROM dev AS default
61+
# Install proto3
62+
FROM golang AS proto3
63+
RUN apt-get update && apt-get install -y \
64+
autoconf \
65+
automake \
66+
g++ \
67+
libtool \
68+
unzip \
69+
--no-install-recommends
70+
71+
COPY script/setup/install-protobuf install-protobuf
72+
RUN ./install-protobuf
73+
74+
FROM build-env AS dev
75+
COPY --from=proto3 /usr/local/bin/protoc /usr/local/bin/protoc
76+
COPY --from=proto3 /usr/local/include/google /usr/local/include/google
77+
COPY --from=runc /usr/local/sbin/runc /usr/local/go/bin/runc
78+
COPY . .

0 commit comments

Comments
 (0)