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.77.0" 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 swtpm \ 73 && apt-get clean \ 74 && rm -rf /var/lib/apt/lists/* /var/log/*log /var/log/apt/* /var/lib/dpkg/*-old /var/cache/debconf/*-old; fi 75 76# hadolint ignore=DL3008 77RUN if [ "$TARGETARCH" = "arm64" ]; then \ 78 # On AArch64, `setcap` binary should be installed via `libcap2-bin`. 79 # The `setcap` binary is used in integration tests. 80 # `libguestfs-tools` is used for modifying cloud image kernel, and it requires 81 # kernel (any version) image in `/boot` and modules in `/lib/modules`. 82 apt-get update \ 83 && apt-get -yq upgrade \ 84 && apt-get install --no-install-recommends -yq \ 85 libcap2-bin \ 86 libguestfs-tools \ 87 linux-image-generic \ 88 autotools-dev \ 89 autoconf \ 90 automake \ 91 perl \ 92 texinfo \ 93 && apt-get clean \ 94 && rm -rf /var/lib/apt/lists/* /var/log/*log /var/log/apt/* /var/lib/dpkg/*-old /var/cache/debconf/*-old; fi 95 96# Fix the libssl-dev install 97# hadolint ignore=SC2155 98RUN export ARCH="$(uname -m)" \ 99 && cp /usr/include/"$ARCH"-linux-gnu/openssl/opensslconf.h /usr/include/openssl/ 100ENV X86_64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu/ 101ENV X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu/ 102ENV AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR=/usr/lib/aarch64-linux-gnu/ 103ENV AARCH64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR=/usr/lib/aarch64-linux-gnu/ 104ENV OPENSSL_INCLUDE_DIR=/usr/include/ 105 106# Install the rust toolchain 107# hadolint ignore=DL4006,SC2155 108RUN export ARCH="$(uname -m)" \ 109 && nohup curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain "$RUST_TOOLCHAIN" \ 110 && rustup target add "$ARCH"-unknown-linux-musl --toolchain "$RUST_TOOLCHAIN" \ 111 && if [ "$TARGETARCH" = "amd64" ]; then rustup toolchain add --profile minimal $RUST_TOOLCHAIN-x86_64-unknown-linux-musl; fi \ 112 && if [ "$TARGETARCH" = "amd64" ]; then rustup component add rustfmt; fi \ 113 && if [ "$TARGETARCH" = "amd64" ]; then rustup component add clippy; fi \ 114 && rm -rf "$CARGO_HOME/registry" \ 115 && ln -s "$CARGO_REGISTRY_DIR" "$CARGO_HOME/registry" \ 116 && rm -rf "$CARGO_HOME/git" \ 117 && ln -s "$CARGO_GIT_REGISTRY_DIR" "$CARGO_HOME/git" 118 119# Set the rust environment 120# hadolint ignore=SC2016 121RUN echo 'source $CARGO_HOME/env' >> "$HOME"/.bashrc \ 122 && mkdir "$HOME"/.cargo \ 123 && ln -s $CARGO_HOME/env "$HOME"/.cargo/env 124 125# install SPDK NVMe 126# only for 'x86_64' platform images as 'docker buildx' can't build 'spdk' 127# hadolint ignore=DL3003,SC2046 128RUN if [ "$TARGETARCH" = "amd64" ]; then \ 129 git clone https://github.com/spdk/spdk \ 130 && cd spdk \ 131 && git checkout ef8bcce58f3f02b79c0619a297e4f17e81e62b24 \ 132 && git submodule update --init \ 133 && apt-get update \ 134 && ./scripts/pkgdep.sh \ 135 && apt-get clean \ 136 && ./configure --with-vfio-user \ 137 && make -j $(nproc) TARGET_ARCHITECTURE=skylake \ 138 && rm -rf /usr/local/bin/spdk-nvme \ 139 && mkdir /usr/local/bin/spdk-nvme \ 140 && cp -f ./build/bin/nvmf_tgt /usr/local/bin/spdk-nvme \ 141 && cp -f ./scripts/rpc.py /usr/local/bin/spdk-nvme \ 142 && cp -rf ./python /usr/local/bin \ 143 && cd .. && rm -rf spdk; fi 144 145# install ethr tool for performance tests 146RUN if [ "$TARGETARCH" = "amd64" ]; then \ 147 wget -nv https://github.com/microsoft/ethr/releases/latest/download/ethr_linux.zip \ 148 && unzip ethr_linux.zip \ 149 && cp ethr /usr/local/bin \ 150 && rm ethr_linux.zip; fi 151