mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-21 07:21:15 +00:00
In order to support both amd64 and arm64, we rely on the TARGETARCH variable that is passed from the docker buildx command, based on the platform used to build the container image. There is no way to rely directly on $(uname -m) to assign a variable with the correct x86_64 or aarch64 values we're looking for. Both ENV and ARG don't evaluate the command, which means they see it as a simple string. Using RUN is the only way to evaluate a command. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
91 lines
3.1 KiB
Docker
91 lines
3.1 KiB
Docker
FROM ubuntu:18.04 as dev
|
|
|
|
ARG TARGETARCH
|
|
ARG RUST_TOOLCHAIN="1.43.0"
|
|
ARG CLH_SRC_DIR="/cloud-hypervisor"
|
|
ARG CLH_BUILD_DIR="$CLH_SRC_DIR/build"
|
|
ARG CARGO_REGISTRY_DIR="$CLH_BUILD_DIR/cargo_registry"
|
|
ARG CARGO_GIT_REGISTRY_DIR="$CLH_BUILD_DIR/cargo_git_registry"
|
|
|
|
ENV CARGO_HOME=/usr/local/rust
|
|
ENV RUSTUP_HOME=$CARGO_HOME
|
|
ENV PATH="$PATH:$CARGO_HOME/bin"
|
|
|
|
# Install all CI dependencies
|
|
RUN apt-get update \
|
|
&& apt-get -yq upgrade \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq \
|
|
build-essential \
|
|
bc \
|
|
docker.io \
|
|
curl \
|
|
wget \
|
|
sudo \
|
|
mtools \
|
|
musl-tools \
|
|
libssl-dev \
|
|
pkg-config \
|
|
flex \
|
|
bison \
|
|
libelf-dev \
|
|
qemu-utils \
|
|
qemu-system \
|
|
libglib2.0-dev \
|
|
libpixman-1-dev \
|
|
libseccomp-dev \
|
|
libcap-ng-dev \
|
|
socat \
|
|
dosfstools \
|
|
cpio \
|
|
bsdtar \
|
|
libfdt-dev \
|
|
python3-setuptools \
|
|
&& apt-get clean \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
RUN if [ "$TARGETARCH" = "amd64" ]; then \
|
|
apt-get update \
|
|
&& apt-get -yq upgrade \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq gcc-multilib \
|
|
&& apt-get clean \
|
|
&& rm -rf /var/lib/apt/lists/*; fi
|
|
|
|
RUN if [ "$TARGETARCH" = "arm64" ]; then \
|
|
# On AArch64, `setcap` binary should be installed via `libcap2-bin`.
|
|
# The `setcap` binary is used in integration tests.
|
|
apt-get update \
|
|
&& apt-get -yq upgrade \
|
|
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq libcap2-bin \
|
|
&& apt-get clean \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
# Build and install the musl-gcc version of libfdt. This is to ensure
|
|
# the cloud-hypervisor binary can be built and linked using musl toolchain.
|
|
&& git clone https://github.com/dgibson/dtc.git && cd dtc \
|
|
&& sed -i 's/$(LIBFDT_archive) $(LIBFDT_lib)/$(LIBFDT_archive)/g' Makefile \
|
|
&& export CC=musl-gcc && make libfdt \
|
|
&& cp libfdt/libfdt.a /usr/lib/aarch64-linux-musl \
|
|
&& rm -rf /dtc; fi
|
|
|
|
# Fix the libssl-dev install
|
|
RUN cp /usr/include/"$(uname -m)"-linux-gnu/openssl/opensslconf.h /usr/include/openssl/
|
|
RUN echo 'export OPENSSL_DIR=/usr/lib/"$(uname -m)"-linux-gnu/' >> $HOME/.bashrc
|
|
RUN echo 'export OPENSSL_LIB_DIR=/usr/lib/"$(uname -m)"-linux-gnu/' >> $HOME/.bashrc
|
|
ENV OPENSSL_INCLUDE_DIR=/usr/include/
|
|
|
|
# Install the rust toolchain
|
|
RUN nohup curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain "$RUST_TOOLCHAIN" \
|
|
&& rustup target add "$(uname -m)"-unknown-linux-musl --toolchain "$RUST_TOOLCHAIN" \
|
|
&& if [ "$TARGETARCH" = "amd64" ]; then rustup toolchain add $RUST_TOOLCHAIN-x86_64-unknown-linux-musl; fi \
|
|
&& if [ "$TARGETARCH" = "amd64" ]; then rustup component add rustfmt; fi \
|
|
&& if [ "$TARGETARCH" = "amd64" ]; then rustup component add clippy; fi \
|
|
&& cargo install cargo-audit \
|
|
&& rm -rf "$CARGO_HOME/registry" \
|
|
&& ln -s "$CARGO_REGISTRY_DIR" "$CARGO_HOME/registry" \
|
|
&& rm -rf "$CARGO_HOME/git" \
|
|
&& ln -s "$CARGO_GIT_REGISTRY_DIR" "$CARGO_HOME/git"
|
|
|
|
# Set the rust environment
|
|
RUN echo 'source $CARGO_HOME/env' >> $HOME/.bashrc \
|
|
&& mkdir $HOME/.cargo \
|
|
&& ln -s $CARGO_HOME/env $HOME/.cargo/env
|