xref: /cloud-hypervisor/resources/Dockerfile (revision f6cd3bd86ded632da437b6dd6077f4237d2f71fe)
1# Copyright © 2024 Intel Corporation
2#
3# SPDX-License-Identifier: Apache-2.0
4#
5# When changing this file don't forget to update the tag name in the
6# .github/workflows/docker-image.yaml file if doing multiple per day
7
8FROM ubuntu:22.04 as dev
9
10ARG TARGETARCH
11ARG RUST_TOOLCHAIN="1.74.1"
12ARG CLH_SRC_DIR="/cloud-hypervisor"
13ARG CLH_BUILD_DIR="$CLH_SRC_DIR/build"
14ARG CARGO_REGISTRY_DIR="$CLH_BUILD_DIR/cargo_registry"
15ARG CARGO_GIT_REGISTRY_DIR="$CLH_BUILD_DIR/cargo_git_registry"
16
17ENV CARGO_HOME=/usr/local/rust
18ENV RUSTUP_HOME=$CARGO_HOME
19ENV PATH="$PATH:$CARGO_HOME/bin"
20ENV DEBIAN_FRONTEND=noninteractive
21
22# Install all CI dependencies
23# DL3015 ignored cause not installing openvswitch-switch-dpdk recommended packages breaks ovs_dpdk test
24# hadolint ignore=DL3008,DL3015
25RUN apt-get update \
26        && apt-get -yq upgrade \
27        && apt-get install --no-install-recommends -yq \
28        build-essential \
29        bc \
30        curl \
31        wget \
32        sudo \
33        mtools \
34        musl-tools \
35        libssl-dev \
36        pkg-config \
37        flex \
38        bison \
39        libelf-dev \
40        qemu-utils \
41        libglib2.0-dev \
42        libpixman-1-dev \
43        libseccomp-dev \
44        libcap-ng-dev \
45        socat \
46        dosfstools \
47        cpio \
48        python3 \
49        python3-setuptools \
50        ntfs-3g \
51        python3-distutils \
52        uuid-dev \
53        iperf3 \
54        zip \
55        git-core \
56        dnsmasq \
57        dmsetup \
58        ca-certificates \
59        unzip \
60        iproute2 \
61        dbus \
62    && apt-get install openvswitch-switch-dpdk -yq \
63    && apt-get clean \
64    && rm -rf /var/lib/apt/lists/* /var/log/*log  /var/log/apt/* /var/lib/dpkg/*-old /var/cache/debconf/*-old
65
66RUN update-alternatives --set ovs-vswitchd /usr/lib/openvswitch-switch-dpdk/ovs-vswitchd-dpdk
67
68# hadolint ignore=DL3008
69RUN if [ "$TARGETARCH" = "amd64" ]; then \
70        apt-get update \
71        && apt-get -yq upgrade \
72        && apt-get install --no-install-recommends -yq gcc-multilib gawk \
73        libtool expect gnutls-dev gnutls-bin libfuse-dev \
74        libjson-glib-dev libgmp-dev libtasn1-dev python3-twisted \
75        net-tools softhsm2 \
76        && apt-get clean \
77        && rm -rf /var/lib/apt/lists/* /var/log/*log  /var/log/apt/* /var/lib/dpkg/*-old /var/cache/debconf/*-old; fi
78
79# hadolint ignore=DL3008
80RUN if [ "$TARGETARCH" = "arm64" ]; then \
81        # On AArch64, `setcap` binary should be installed via `libcap2-bin`.
82        # The `setcap` binary is used in integration tests.
83        # `libguestfs-tools` is used for modifying cloud image kernel, and it requires
84        # kernel (any version) image in `/boot` and modules in `/lib/modules`.
85        apt-get update \
86        && apt-get -yq upgrade \
87        && apt-get install --no-install-recommends -yq \
88        libcap2-bin \
89        libguestfs-tools \
90        linux-image-generic \
91        autotools-dev \
92        autoconf \
93        automake \
94        perl \
95        texinfo \
96        && apt-get clean \
97        && rm -rf /var/lib/apt/lists/* /var/log/*log  /var/log/apt/* /var/lib/dpkg/*-old /var/cache/debconf/*-old; fi
98
99# Fix the libssl-dev install
100# hadolint ignore=SC2155
101RUN export ARCH="$(uname -m)" \
102    && cp /usr/include/"$ARCH"-linux-gnu/openssl/opensslconf.h /usr/include/openssl/
103ENV X86_64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu/
104ENV X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu/
105ENV AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR=/usr/lib/aarch64-linux-gnu/
106ENV AARCH64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR=/usr/lib/aarch64-linux-gnu/
107ENV OPENSSL_INCLUDE_DIR=/usr/include/
108
109# Install the rust toolchain
110# hadolint ignore=DL4006,SC2155
111RUN export ARCH="$(uname -m)" \
112    && nohup curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain "$RUST_TOOLCHAIN" \
113    && rustup target add "$ARCH"-unknown-linux-musl --toolchain "$RUST_TOOLCHAIN" \
114    && if [ "$TARGETARCH" = "amd64" ]; then rustup toolchain add --profile minimal $RUST_TOOLCHAIN-x86_64-unknown-linux-musl; fi \
115    && if [ "$TARGETARCH" = "amd64" ]; then rustup component add rustfmt; fi \
116    && if [ "$TARGETARCH" = "amd64" ]; then rustup component add clippy; fi \
117    && rm -rf "$CARGO_HOME/registry" \
118    && ln -s "$CARGO_REGISTRY_DIR" "$CARGO_HOME/registry" \
119    && rm -rf "$CARGO_HOME/git" \
120    && ln -s "$CARGO_GIT_REGISTRY_DIR" "$CARGO_HOME/git"
121
122# Set the rust environment
123# hadolint ignore=SC2016
124RUN echo 'source $CARGO_HOME/env' >> "$HOME"/.bashrc \
125    && mkdir "$HOME"/.cargo \
126    && ln -s $CARGO_HOME/env "$HOME"/.cargo/env
127
128# install SPDK NVMe
129# only for 'x86_64' platform images as 'docker buildx' can't build 'spdk'
130# hadolint ignore=DL3003,SC2046
131RUN if [ "$TARGETARCH" = "amd64" ]; then \
132       git clone https://github.com/spdk/spdk \
133       && cd spdk \
134       && git checkout ef8bcce58f3f02b79c0619a297e4f17e81e62b24 \
135       && git submodule update --init \
136       && apt-get update \
137       && ./scripts/pkgdep.sh \
138       && apt-get clean \
139       && ./configure --with-vfio-user \
140       && make -j $(nproc) TARGET_ARCHITECTURE=skylake \
141       && rm -rf /usr/local/bin/spdk-nvme \
142       && mkdir /usr/local/bin/spdk-nvme \
143       && cp -f ./build/bin/nvmf_tgt /usr/local/bin/spdk-nvme \
144       && cp -f ./scripts/rpc.py /usr/local/bin/spdk-nvme \
145       && cp -rf ./python /usr/local/bin \
146       && cd .. && rm -rf spdk; fi
147
148# install swtpm only for x86_64 arch
149# hadolint ignore=DL3003
150RUN if [ "$TARGETARCH" = "amd64" ]; then \
151    git clone https://github.com/stefanberger/libtpms libtpms_build \
152    && cd libtpms_build \
153    && git checkout v0.8.8 \
154    && ./autogen.sh \
155    && make \
156    && make install \
157    && cd .. \
158    && git clone  https://github.com/stefanberger/swtpm swtpm_build \
159    && cd swtpm_build \
160    && git checkout v0.8.0 \
161    && ./autogen.sh \
162    && make \
163    && make install \
164    && cd .. \
165    && ldconfig \
166    && rm -rf swtpm_build libtpms_build; fi
167
168# install ethr tool for performance tests
169RUN if [ "$TARGETARCH" = "amd64" ]; then \
170    wget -nv https://github.com/microsoft/ethr/releases/latest/download/ethr_linux.zip \
171    && unzip ethr_linux.zip \
172    && cp ethr /usr/local/bin \
173    && rm ethr_linux.zip; fi
174