xref: /cloud-hypervisor/resources/Dockerfile (revision 7d7bfb2034001d4cb15df2ddc56d2d350c8da30f)
1# When changing this file don't forget to update the tag name in the
2# .github/workflows/docker-image.yaml file if doing multiple per day
3
4FROM ubuntu:20.04 as dev
5
6ARG TARGETARCH
7ARG RUST_TOOLCHAIN="1.59.0"
8ARG CLH_SRC_DIR="/cloud-hypervisor"
9ARG CLH_BUILD_DIR="$CLH_SRC_DIR/build"
10ARG CARGO_REGISTRY_DIR="$CLH_BUILD_DIR/cargo_registry"
11ARG CARGO_GIT_REGISTRY_DIR="$CLH_BUILD_DIR/cargo_git_registry"
12
13ENV CARGO_HOME=/usr/local/rust
14ENV RUSTUP_HOME=$CARGO_HOME
15ENV PATH="$PATH:$CARGO_HOME/bin"
16
17# Install all CI dependencies
18RUN apt-get update \
19	&& apt-get -yq upgrade \
20	&& DEBIAN_FRONTEND=noninteractive apt-get install -yq \
21	build-essential \
22	bc \
23	curl \
24	wget \
25	sudo \
26	mtools \
27	musl-tools \
28	libssl-dev \
29	pkg-config \
30	flex \
31	bison \
32	libelf-dev \
33	qemu-utils \
34	libglib2.0-dev \
35	libpixman-1-dev \
36	libseccomp-dev \
37	libcap-ng-dev \
38	socat \
39	dosfstools \
40	cpio \
41	python \
42	python3 \
43	python3-setuptools \
44	ntfs-3g \
45	openvswitch-switch-dpdk \
46	python3-distutils \
47	uuid-dev \
48	iperf3 \
49	zip \
50	git-core \
51	dnsmasq \
52	dmsetup \
53    && apt-get clean \
54    && rm -rf /var/lib/apt/lists/*
55
56RUN update-alternatives --set ovs-vswitchd /usr/lib/openvswitch-switch-dpdk/ovs-vswitchd-dpdk
57
58RUN if [ "$TARGETARCH" = "amd64" ]; then \
59	apt-get update \
60	&& apt-get -yq upgrade \
61	&& DEBIAN_FRONTEND=noninteractive apt-get install -yq gcc-multilib \
62	&& apt-get clean \
63    && rm -rf /var/lib/apt/lists/*;	fi
64
65RUN if [ "$TARGETARCH" = "arm64" ]; then \
66        # On AArch64, `setcap` binary should be installed via `libcap2-bin`.
67        # The `setcap` binary is used in integration tests.
68        # `libguestfs-tools` is used for modifying cloud image kernel, and it requires
69        # kernel (any version) image in `/boot` and modules in `/lib/modules`.
70        apt-get update \
71        && apt-get -yq upgrade \
72        && DEBIAN_FRONTEND=noninteractive apt-get install -yq \
73        libcap2-bin \
74        libguestfs-tools \
75        linux-image-generic \
76        autotools-dev \
77        autoconf \
78        automake \
79        perl \
80        texinfo \
81        && apt-get clean \
82        && rm -rf /var/lib/apt/lists/*;	fi
83
84# Fix the libssl-dev install
85RUN export ARCH="$(uname -m)" \
86    && cp /usr/include/$ARCH-linux-gnu/openssl/opensslconf.h /usr/include/openssl/
87ENV X86_64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu/
88ENV X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu/
89ENV AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR=/usr/lib/aarch64-linux-gnu/
90ENV AARCH64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR=/usr/lib/aarch64-linux-gnu/
91ENV OPENSSL_INCLUDE_DIR=/usr/include/
92
93# Install the rust toolchain
94RUN export ARCH="$(uname -m)" \
95    && nohup curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain "$RUST_TOOLCHAIN" \
96    && rustup target add $ARCH-unknown-linux-musl --toolchain "$RUST_TOOLCHAIN" \
97    && if [ "$TARGETARCH" = "amd64" ]; then rustup toolchain add --profile minimal $RUST_TOOLCHAIN-x86_64-unknown-linux-musl; fi \
98    && if [ "$TARGETARCH" = "amd64" ]; then rustup component add rustfmt; fi \
99    && if [ "$TARGETARCH" = "amd64" ]; then rustup component add clippy; fi \
100    && rm -rf "$CARGO_HOME/registry" \
101    && ln -s "$CARGO_REGISTRY_DIR" "$CARGO_HOME/registry" \
102    && rm -rf "$CARGO_HOME/git" \
103    && ln -s "$CARGO_GIT_REGISTRY_DIR" "$CARGO_HOME/git"
104
105# Set the rust environment
106RUN echo 'source $CARGO_HOME/env' >> $HOME/.bashrc \
107    && mkdir $HOME/.cargo \
108    && ln -s $CARGO_HOME/env $HOME/.cargo/env
109
110# install SPDK NVMe
111# only for 'x86_64' platform images as 'docker buildx' can't build 'spdk'
112RUN if [ "$TARGETARCH" = "amd64" ]; then \
113       git clone https://github.com/spdk/spdk \
114       && cd spdk \
115       && git checkout 6301f8915de32baed10dba1eebed556a6749211a \
116       && git submodule update --init \
117       && apt-get update \
118       && ./scripts/pkgdep.sh \
119       && apt-get clean \
120       && ./configure --with-vfio-user \
121       && make -j `nproc` \
122       && mkdir /usr/local/bin/spdk-nvme \
123       && cp ./build/bin/nvmf_tgt /usr/local/bin/spdk-nvme \
124       && cp ./scripts/rpc.py /usr/local/bin/spdk-nvme \
125       && cp -r ./scripts/rpc /usr/local/bin/spdk-nvme \
126       && cd .. && rm -rf spdk; fi
127
128# install ethr tool for performance tests
129RUN if [ "$TARGETARCH" = "amd64" ]; then \
130    wget https://github.com/microsoft/ethr/releases/latest/download/ethr_linux.zip \
131    && unzip ethr_linux.zip \
132    && cp ethr /usr/local/bin \
133    && rm ethr_linux.zip; fi
134