Debian Codegraph @

Dockerfile

raw
1 # Copyright The containerd 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 CONTAINERD_VERSION=v1.7.0-rc.2
16 ARG RUNC_VERSION=v1.1.4
17 ARG CNI_PLUGINS_VERSION=v1.1.1
18 ARG NERDCTL_VERSION=1.1.0
19
20 ARG PODMAN_VERSION=v4.3.1
21 ARG CRIO_VERSION=v1.26.1
22 ARG CONMON_VERSION=v2.1.5
23 ARG COMMON_VERSION=v0.49.2
24 ARG CRIO_TEST_PAUSE_IMAGE_NAME=registry.k8s.io/pause:3.6
25
26 ARG CONTAINERIZED_SYSTEMD_VERSION=v0.1.1
27 ARG SLIRP4NETNS_VERSION=v1.1.12
28
29 # Used in CI
30 ARG CRI_TOOLS_VERSION=v1.26.0
31
32 # Legacy builder that doesn't support TARGETARCH should set this explicitly using --build-arg.
33 # If TARGETARCH isn't supported by the builder, the default value is "amd64".
34
35 FROM golang:1.20.1-bullseye AS golang-base
36
37 # Build containerd
38 FROM golang-base AS containerd-dev
39 ARG CONTAINERD_VERSION
40 RUN apt-get update -y && apt-get install -y libbtrfs-dev libseccomp-dev && \
41 git clone -b ${CONTAINERD_VERSION} --depth 1 \
42 https://github.com/containerd/containerd $GOPATH/src/github.com/containerd/containerd && \
43 cd $GOPATH/src/github.com/containerd/containerd && \
44 make && DESTDIR=/out/ PREFIX= make install
45
46 # Build containerd with builtin stargz snapshotter
47 FROM golang-base AS containerd-snapshotter-dev
48 ARG CONTAINERD_VERSION
49 COPY . $GOPATH/src/github.com/containerd/stargz-snapshotter
50 RUN apt-get update -y && apt-get install -y libbtrfs-dev libseccomp-dev && \
51 git clone -b ${CONTAINERD_VERSION} --depth 1 \
52 https://github.com/containerd/containerd $GOPATH/src/github.com/containerd/containerd && \
53 cd $GOPATH/src/github.com/containerd/containerd && \
54 echo 'require github.com/containerd/stargz-snapshotter v0.0.0' >> go.mod && \
55 echo 'replace github.com/containerd/stargz-snapshotter => '$GOPATH'/src/github.com/containerd/stargz-snapshotter' >> go.mod && \
56 echo 'replace github.com/containerd/stargz-snapshotter/estargz => '$GOPATH'/src/github.com/containerd/stargz-snapshotter/estargz' >> go.mod && \
57 # recent containerd requires to update api/go.mod and integration/client/go.mod as well.
58 if [ -f api/go.mod ] ; then \
59 echo 'replace github.com/containerd/stargz-snapshotter => '$GOPATH'/src/github.com/containerd/stargz-snapshotter' >> api/go.mod && \
60 echo 'replace github.com/containerd/stargz-snapshotter/estargz => '$GOPATH'/src/github.com/containerd/stargz-snapshotter/estargz' >> api/go.mod ; \
61 fi && \
62 if [ -f integration/client/go.mod ] ; then \
63 echo 'replace github.com/containerd/stargz-snapshotter => '$GOPATH'/src/github.com/containerd/stargz-snapshotter' >> integration/client/go.mod && \
64 echo 'replace github.com/containerd/stargz-snapshotter/estargz => '$GOPATH'/src/github.com/containerd/stargz-snapshotter/estargz' >> integration/client/go.mod ; \
65 fi && \
66 echo 'package main \nimport _ "github.com/containerd/stargz-snapshotter/service/plugin"' > cmd/containerd/builtins_stargz_snapshotter.go && \
67 make vendor && make && DESTDIR=/out/ PREFIX= make install
68
69 # Build runc
70 FROM golang-base AS runc-dev
71 ARG RUNC_VERSION
72 RUN apt-get update -y && apt-get install -y libseccomp-dev && \
73 git clone -b ${RUNC_VERSION} --depth 1 \
74 https://github.com/opencontainers/runc $GOPATH/src/github.com/opencontainers/runc && \
75 cd $GOPATH/src/github.com/opencontainers/runc && \
76 make && make install PREFIX=/out/
77
78 # Build stargz snapshotter
79 FROM golang-base AS snapshotter-dev
80 ARG TARGETARCH
81 ARG GOARM
82 ARG SNAPSHOTTER_BUILD_FLAGS
83 ARG CTR_REMOTE_BUILD_FLAGS
84 COPY . $GOPATH/src/github.com/containerd/stargz-snapshotter
85 RUN cd $GOPATH/src/github.com/containerd/stargz-snapshotter && \
86 PREFIX=/out/ GOARCH=${TARGETARCH:-amd64} GO_BUILD_FLAGS=${SNAPSHOTTER_BUILD_FLAGS} make containerd-stargz-grpc && \
87 PREFIX=/out/ GOARCH=${TARGETARCH:-amd64} GO_BUILD_FLAGS=${CTR_REMOTE_BUILD_FLAGS} make ctr-remote
88
89 # Build stargz store
90 FROM golang-base AS stargz-store-dev
91 ARG TARGETARCH
92 ARG GOARM
93 ARG SNAPSHOTTER_BUILD_FLAGS
94 ARG CTR_REMOTE_BUILD_FLAGS
95 COPY . $GOPATH/src/github.com/containerd/stargz-snapshotter
96 RUN cd $GOPATH/src/github.com/containerd/stargz-snapshotter && \
97 PREFIX=/out/ GOARCH=${TARGETARCH:-amd64} GO_BUILD_FLAGS=${SNAPSHOTTER_BUILD_FLAGS} make stargz-store
98
99 # Build podman
100 FROM golang-base AS podman-dev
101 ARG PODMAN_VERSION
102 RUN apt-get update -y && apt-get install -y libseccomp-dev libgpgme-dev && \
103 git clone https://github.com/containers/podman $GOPATH/src/github.com/containers/podman && \
104 cd $GOPATH/src/github.com/containers/podman && \
105 git checkout ${PODMAN_VERSION} && \
106 make && make install PREFIX=/out/
107
108 # Build CRI-O
109 FROM golang-base AS cri-o-dev
110 ARG CRIO_VERSION
111 RUN apt-get update -y && apt-get install -y libseccomp-dev libgpgme-dev && \
112 git clone https://github.com/cri-o/cri-o $GOPATH/src/github.com/cri-o/cri-o && \
113 cd $GOPATH/src/github.com/cri-o/cri-o && \
114 git checkout ${CRIO_VERSION} && \
115 make && make install PREFIX=/out/ && \
116 curl -sSL --output /out/crio.service https://raw.githubusercontent.com/cri-o/cri-o/${CRIO_VERSION}/contrib/systemd/crio.service
117
118 # Build conmon
119 FROM golang-base AS conmon-dev
120 ARG CONMON_VERSION
121 RUN apt-get update -y && apt-get install -y gcc git libc6-dev libglib2.0-dev pkg-config make libseccomp-dev && \
122 git clone -b ${CONMON_VERSION} --depth 1 \
123 https://github.com/containers/conmon $GOPATH/src/github.com/containers/conmon && \
124 cd $GOPATH/src/github.com/containers/conmon && \
125 mkdir /out/ && make && make install PREFIX=/out/
126
127 # Get seccomp.json for Podman/CRI-O
128 FROM golang-base AS containers-common-dev
129 ARG COMMON_VERSION
130 RUN git clone https://github.com/containers/common $GOPATH/src/github.com/containers/common && \
131 cd $GOPATH/src/github.com/containers/common && \
132 git checkout ${COMMON_VERSION} && mkdir /out/ && cp pkg/seccomp/seccomp.json /out/
133
134 # Binaries for release
135 FROM scratch AS release-binaries
136 COPY --from=snapshotter-dev /out/* /
137 COPY --from=stargz-store-dev /out/* /
138
139 # Base image which contains containerd with default snapshotter
140 FROM golang-base AS containerd-base
141 ARG TARGETARCH
142 ARG NERDCTL_VERSION
143 RUN apt-get update -y && apt-get --no-install-recommends install -y fuse3 && \
144 curl -sSL --output /tmp/nerdctl.tgz https://github.com/containerd/nerdctl/releases/download/v${NERDCTL_VERSION}/nerdctl-${NERDCTL_VERSION}-linux-${TARGETARCH:-amd64}.tar.gz && \
145 tar zxvf /tmp/nerdctl.tgz -C /usr/local/bin && \
146 rm -f /tmp/nerdctl.tgz
147 COPY --from=containerd-dev /out/bin/containerd /out/bin/containerd-shim-runc-v2 /usr/local/bin/
148 COPY --from=runc-dev /out/sbin/* /usr/local/sbin/
149
150 # Base image which contains containerd with stargz snapshotter
151 FROM containerd-base AS snapshotter-base
152 COPY --from=snapshotter-dev /out/* /usr/local/bin/
153 RUN ln -s /usr/local/bin/ctr-remote /usr/local/bin/ctr
154
155 # Base image which contains containerd with builtin stargz snapshotter
156 FROM golang-base AS containerd-snapshotter-base
157 ARG TARGETARCH
158 ARG NERDCTL_VERSION
159 RUN apt-get update -y && apt-get --no-install-recommends install -y fuse3 && \
160 curl -sSL --output /tmp/nerdctl.tgz https://github.com/containerd/nerdctl/releases/download/v${NERDCTL_VERSION}/nerdctl-${NERDCTL_VERSION}-linux-${TARGETARCH:-amd64}.tar.gz && \
161 tar zxvf /tmp/nerdctl.tgz -C /usr/local/bin && \
162 rm -f /tmp/nerdctl.tgz
163 COPY --from=containerd-snapshotter-dev /out/bin/containerd /out/bin/containerd-shim-runc-v2 /usr/local/bin/
164 COPY --from=runc-dev /out/sbin/* /usr/local/sbin/
165 COPY --from=snapshotter-dev /out/ctr-remote /usr/local/bin/
166 RUN ln -s /usr/local/bin/ctr-remote /usr/local/bin/ctr
167
168 # Base image which contains podman with stargz-store
169 FROM golang-base AS podman-base
170 ARG TARGETARCH
171 ARG CNI_PLUGINS_VERSION
172 ARG PODMAN_VERSION
173 RUN apt-get update -y && apt-get --no-install-recommends install -y fuse3 libgpgme-dev \
174 iptables libyajl-dev && \
175 # Make CNI plugins manipulate iptables instead of nftables
176 # as this test runs in a Docker container that network is configured with iptables.
177 # c.f. https://github.com/moby/moby/issues/26824
178 update-alternatives --set iptables /usr/sbin/iptables-legacy && \
179 mkdir -p /etc/containers /etc/cni/net.d /opt/cni/bin && \
180 curl -qsSL https://raw.githubusercontent.com/containers/podman/${PODMAN_VERSION}/cni/87-podman-bridge.conflist | tee /etc/cni/net.d/87-podman-bridge.conflist && \
181 curl -Ls https://github.com/containernetworking/plugins/releases/download/${CNI_PLUGINS_VERSION}/cni-plugins-linux-${TARGETARCH:-amd64}-${CNI_PLUGINS_VERSION}.tgz | tar xzv -C /opt/cni/bin
182
183 COPY --from=podman-dev /out/bin/* /usr/local/bin/
184 COPY --from=runc-dev /out/sbin/* /usr/local/sbin/
185 COPY --from=conmon-dev /out/bin/* /usr/local/bin/
186 COPY --from=containers-common-dev /out/seccomp.json /usr/share/containers/
187 COPY --from=stargz-store-dev /out/* /usr/local/bin/
188
189 # Image for testing rootless Podman with Stargz Store.
190 # This takes the same approach as nerdctl CI: https://github.com/containerd/nerdctl/blob/6341c8320984f7148b92dd33472d8eaca6dba756/Dockerfile#L302-L326
191 FROM podman-base AS podman-rootless
192 ARG CONTAINERIZED_SYSTEMD_VERSION
193 ARG SLIRP4NETNS_VERSION
194 RUN apt-get update -y && apt-get install -y \
195 systemd systemd-sysv dbus dbus-user-session \
196 openssh-server openssh-client uidmap
197 RUN curl -o /usr/local/bin/slirp4netns --fail -L https://github.com/rootless-containers/slirp4netns/releases/download/${SLIRP4NETNS_VERSION}/slirp4netns-$(uname -m) && \
198 chmod +x /usr/local/bin/slirp4netns && \
199 curl -L -o /docker-entrypoint.sh https://raw.githubusercontent.com/AkihiroSuda/containerized-systemd/${CONTAINERIZED_SYSTEMD_VERSION}/docker-entrypoint.sh && \
200 chmod +x /docker-entrypoint.sh && \
201 curl -L -o /etc/containers/policy.json https://raw.githubusercontent.com/containers/skopeo/master/default-policy.json
202 # storage.conf plugs Stargz Store into Podman as an Additional Layer Store
203 COPY ./script/podman/config/storage.conf /home/rootless/.config/containers/storage.conf
204 # Stargz Store systemd service for rootless Podman
205 COPY ./script/podman/config/podman-rootless-stargz-store.service /home/rootless/.config/systemd/user/
206 # test-podman-rootless.sh logins to the user via SSH
207 COPY ./script/podman/config/test-podman-rootless.sh /test-podman-rootless.sh
208 RUN ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N '' && \
209 useradd -m -s /bin/bash rootless && \
210 mkdir -p -m 0700 /home/rootless/.ssh && \
211 cp -a /root/.ssh/id_rsa.pub /home/rootless/.ssh/authorized_keys && \
212 mkdir -p /home/rootless/.local/share /home/rootless/.local/share/stargz-store/store && \
213 chown -R rootless:rootless /home/rootless
214 VOLUME /home/rootless/.local/share
215
216 ENTRYPOINT ["/docker-entrypoint.sh", "/test-podman-rootless.sh"]
217 CMD ["/bin/bash", "--login", "-i"]
218
219 # Image which can be used for interactive demo environment
220 FROM containerd-base AS demo
221 ARG CNI_PLUGINS_VERSION
222 ARG TARGETARCH
223 RUN apt-get update && apt-get install -y iptables && \
224 # Make CNI plugins manipulate iptables instead of nftables
225 # as this test runs in a Docker container that network is configured with iptables.
226 # c.f. https://github.com/moby/moby/issues/26824
227 update-alternatives --set iptables /usr/sbin/iptables-legacy && \
228 mkdir -p /opt/cni/bin && \
229 curl -Ls https://github.com/containernetworking/plugins/releases/download/${CNI_PLUGINS_VERSION}/cni-plugins-linux-${TARGETARCH:-amd64}-${CNI_PLUGINS_VERSION}.tgz | tar xzv -C /opt/cni/bin
230
231 # Image which can be used as a node image for KinD (containerd with builtin snapshotter)
232 FROM kindest/node:v1.26.0 AS kind-builtin-snapshotter
233 COPY --from=containerd-snapshotter-dev /out/bin/containerd /out/bin/containerd-shim-runc-v2 /usr/local/bin/
234 COPY --from=snapshotter-dev /out/ctr-remote /usr/local/bin/
235 COPY ./script/config/ /
236 RUN apt-get update -y && apt-get install --no-install-recommends -y fuse3
237 ENTRYPOINT [ "/usr/local/bin/kind-entrypoint.sh", "/usr/local/bin/entrypoint", "/sbin/init" ]
238
239 # Image for testing CRI-O with Stargz Store.
240 # NOTE: This cannot be used for the node image of KinD.
241 FROM ubuntu:23.04 AS crio-stargz-store
242 ARG CNI_PLUGINS_VERSION
243 ARG CRIO_TEST_PAUSE_IMAGE_NAME
244 ENV container docker
245 RUN apt-get update -y && apt-get install --no-install-recommends -y \
246 ca-certificates fuse3 libgpgme-dev libglib2.0-dev curl \
247 iptables conntrack systemd systemd-sysv && \
248 DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y tzdata && \
249 # Make CNI plugins manipulate iptables instead of nftables
250 # as this test runs in a Docker container that network is configured with iptables.
251 # c.f. https://github.com/moby/moby/issues/26824
252 update-alternatives --set iptables /usr/sbin/iptables-legacy && \
253 mkdir -p /opt/cni/bin && \
254 curl -sSL https://github.com/containernetworking/plugins/releases/download/${CNI_PLUGINS_VERSION}/cni-plugins-linux-${TARGETARCH:-amd64}-${CNI_PLUGINS_VERSION}.tgz | tar xzv -C /opt/cni/bin && \
255 echo ${CRIO_TEST_PAUSE_IMAGE_NAME} > /pause_name && \
256 mkdir -p /etc/sysconfig && \
257 echo CRIO_RUNTIME_OPTIONS=--pause-image=${CRIO_TEST_PAUSE_IMAGE_NAME} > /etc/sysconfig/crio && \
258 # Necessary to pass CRI tests: https://github.com/kubernetes-sigs/cri-tools/pull/905
259 mkdir -p /etc/crio/crio.conf.d && \
260 printf '[crio.runtime]\nseccomp_use_default_when_empty = false\n' > /etc/crio/crio.conf.d/02-seccomp.conf
261
262 COPY --from=stargz-store-dev /out/* /usr/local/bin/
263 COPY --from=cri-o-dev /out/bin/* /usr/local/bin/
264 COPY --from=cri-o-dev /out/crio.service /etc/systemd/system/
265 COPY --from=runc-dev /out/sbin/* /usr/local/sbin/
266 COPY --from=conmon-dev /out/bin/* /usr/local/bin/
267 COPY --from=containers-common-dev /out/seccomp.json /usr/share/containers/
268 COPY ./script/config-cri-o/ /
269
270 ENTRYPOINT [ "/usr/local/bin/entrypoint" ]
271
272 # Image which can be used as a node image for KinD
273 FROM kindest/node:v1.26.0
274 COPY --from=containerd-dev /out/bin/containerd /out/bin/containerd-shim-runc-v2 /usr/local/bin/
275 COPY --from=snapshotter-dev /out/* /usr/local/bin/
276 COPY ./script/config/ /
277 RUN apt-get update -y && apt-get install --no-install-recommends -y fuse3 && \
278 systemctl enable stargz-snapshotter
279 ENTRYPOINT [ "/usr/local/bin/kind-entrypoint.sh", "/usr/local/bin/entrypoint", "/sbin/init" ]