Debian Codegraph @

Dockerfile

raw
1 ARG GO_VERSION=1.22
2 ARG UBUNTU_VERSION=22.04
3 ARG SHADOW_VERSION=4.13
4 ARG SLIRP4NETNS_VERSION=v1.2.0
5 ARG VPNKIT_VERSION=0.5.0
6 ARG PASST_VERSION=2023_12_30.f091893
7 ARG DOCKER_VERSION=25.0.2
8 ARG DOCKER_CHANNEL=stable
9
10 FROM golang:${GO_VERSION}-alpine AS build
11 RUN apk add --no-cache file git make
12 ADD . /go/src/github.com/rootless-containers/rootlesskit
13 WORKDIR /go/src/github.com/rootless-containers/rootlesskit
14
15 FROM build AS rootlesskit
16 RUN CGO_ENABLED=0 make && file /bin/* | grep -v dynamic
17
18 FROM scratch AS artifact
19 COPY --from=rootlesskit /go/src/github.com/rootless-containers/rootlesskit/bin/* /
20
21 FROM build AS cross
22 RUN make cross
23
24 FROM scratch AS cross-artifact
25 COPY --from=cross /go/src/github.com/rootless-containers/rootlesskit/_artifact/* /
26
27 # `go test -race` requires non-Alpine
28 FROM golang:${GO_VERSION} AS test-unit
29 RUN apt-get update && apt-get install -y git iproute2 netcat-openbsd
30 ADD . /go/src/github.com/rootless-containers/rootlesskit
31 WORKDIR /go/src/github.com/rootless-containers/rootlesskit
32 RUN go mod verify && go vet ./...
33 CMD ["go","test","-v","-race","github.com/rootless-containers/rootlesskit/..."]
34
35 # idmap runnable without --privileged (but still requires seccomp=unconfined apparmor=unconfined)
36 FROM ubuntu:${UBUNTU_VERSION} AS idmap
37 ENV DEBIAN_FRONTEND=noninteractive
38 RUN apt-get update && apt-get install -y automake autopoint bison gettext git gcc libcap-dev libtool make
39 RUN git clone https://github.com/shadow-maint/shadow.git /shadow
40 WORKDIR /shadow
41 ARG SHADOW_VERSION
42 RUN git pull && git checkout $SHADOW_VERSION
43 RUN ./autogen.sh --disable-nls --disable-man --without-audit --without-selinux --without-acl --without-attr --without-tcb --without-nscd && \
44 make && \
45 cp src/newuidmap src/newgidmap /usr/bin
46
47 FROM djs55/vpnkit:${VPNKIT_VERSION} AS vpnkit
48
49 FROM ubuntu:${UBUNTU_VERSION} AS passt
50 ENV DEBIAN_FRONTEND=noninteractive
51 RUN apt-get update && apt-get install -y git gcc libtool make
52 RUN git clone https://passt.top/passt
53 WORKDIR /passt
54 ARG PASST_VERSION
55 RUN git pull && git checkout $PASST_VERSION
56 RUN make && make install
57
58 FROM ubuntu:${UBUNTU_VERSION} AS test-integration
59 # iproute2: for `ip` command that rootlesskit needs to exec
60 # liblxc-common and lxc-utils: for `lxc-user-nic` binary required for --net=lxc-user-nic
61 # iperf3: only for benchmark purpose
62 # busybox: only for debugging purpose
63 # sudo: only for lxc-user-nic benchmark and rootful veth benchmark (for comparison)
64 # libcap2-bin and curl: used by the RUN instructions in this Dockerfile.
65 # bind9-dnsutils: for `nslookup` command used by integration-net.sh
66 RUN apt-get update && apt-get install -y iproute2 liblxc-common lxc-utils iperf3 busybox sudo libcap2-bin curl bind9-dnsutils
67 COPY --from=idmap /usr/bin/newuidmap /usr/bin/newuidmap
68 COPY --from=idmap /usr/bin/newgidmap /usr/bin/newgidmap
69 RUN /sbin/setcap cap_setuid+eip /usr/bin/newuidmap && \
70 /sbin/setcap cap_setgid+eip /usr/bin/newgidmap && \
71 useradd --create-home --home-dir /home/user --uid 1000 user && \
72 mkdir -p /run/user/1000 /etc/lxc && \
73 echo "user veth lxcbr0 32" > /etc/lxc/lxc-usernet && \
74 echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/user
75 COPY --from=artifact /rootlesskit /home/user/bin/
76 COPY --from=artifact /rootlessctl /home/user/bin/
77 ARG SLIRP4NETNS_VERSION
78 RUN curl -sSL -o /home/user/bin/slirp4netns https://github.com/rootless-containers/slirp4netns/releases/download/${SLIRP4NETNS_VERSION}/slirp4netns-x86_64 && \
79 chmod +x /home/user/bin/slirp4netns
80 COPY --from=vpnkit /vpnkit /home/user/bin/vpnkit
81 COPY --from=passt /usr/local /usr/local
82 ADD ./hack /home/user/hack
83 RUN chown -R user:user /run/user/1000 /home/user
84 USER user
85 ENV HOME /home/user
86 ENV USER user
87 ENV XDG_RUNTIME_DIR=/run/user/1000
88 ENV PATH /home/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
89 ENV LD_LIBRARY_PATH=/home/user/lib
90 WORKDIR /home/user/hack
91
92 FROM test-integration AS test-integration-docker
93 COPY --from=artifact /rootlesskit-docker-proxy /home/user/bin/
94 ARG DOCKER_VERSION
95 ARG DOCKER_CHANNEL
96 RUN curl -fsSL https://download.docker.com/linux/static/${DOCKER_CHANNEL}/x86_64/docker-${DOCKER_VERSION}.tgz | tar xz --strip-components=1 -C /home/user/bin/
97 RUN curl -fsSL -o /home/user/bin/dockerd-rootless.sh https://raw.githubusercontent.com/moby/moby/v${DOCKER_VERSION}/contrib/dockerd-rootless.sh && \
98 chmod +x /home/user/bin/dockerd-rootless.sh
99 ENV DOCKERD_ROOTLESS_ROOTLESSKIT_NET=slirp4netns
100 ENV DOCKERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER=builtin
101 ENV DOCKER_HOST=unix:///run/user/1000/docker.sock
102 RUN mkdir -p /home/user/.local
103 VOLUME /home/user/.local
104 CMD ["dockerd-rootless.sh"]