diff --git a/regression/syscall_test/Makefile b/regression/syscall_test/Makefile index d91d80822..a8198e8de 100644 --- a/regression/syscall_test/Makefile +++ b/regression/syscall_test/Makefile @@ -2,9 +2,13 @@ TESTS ?= open_test read_test statfs_test chmod_test MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) CUR_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH))) -BUILD_DIR := $(CUR_DIR)/../build -SRC_DIR := $(BUILD_DIR)/gvisor_src -BIN_DIR := $(BUILD_DIR)/syscall_test_bins +BUILD_DIR ?= $(CUR_DIR)/../build +ifdef JINUX_PREBUILT_SYSCALL_TEST + BIN_DIR := $(JINUX_PREBUILT_SYSCALL_TEST) +else + BIN_DIR := $(BUILD_DIR)/syscall_test_bins + SRC_DIR := $(BUILD_DIR)/gvisor_src +endif INITRAMFS ?= $(CUR_DIR)/../build/initramfs TARGET_DIR := $(INITRAMFS)/opt/syscall_test RUN_BASH := $(CUR_DIR)/run_syscall_test.sh @@ -14,20 +18,25 @@ BLOCK_LIST := $(CUR_DIR)/blocklists all: $(TESTS) -$(SRC_DIR): +$(TESTS): $(BIN_DIR) $(TARGET_DIR) + @cp -f $ /dev/null; then \ echo "bazel is not installed, please run $(CUR_DIR)/install_bazel.sh with sudo permission to install it."; \ - exit 1 ; \ + exit 1; \ fi - @rm -rf $@ && mkdir -p $@ - @cd $@ && git clone -b 20200921.0 https://github.com/jinzhao-dev/gvisor.git . - -$(BIN_DIR): $(SRC_DIR) @rm -rf $@ && mkdir -p $@ @cd $(SRC_DIR) && bazel build --test_tag_filters=native //test/syscalls/... @cp $(SRC_DIR)/bazel-bin/test/syscalls/linux/*_test $@ -$(TARGET_DIR): $(RUN_BASH) $(BLOCK_LIST) $(BIN_DIR) +$(SRC_DIR): + @rm -rf $@ && mkdir -p $@ + @cd $@ && git clone -b 20200921.0 https://github.com/jinzhao-dev/gvisor.git . +endif + +$(TARGET_DIR): $(RUN_BASH) $(BLOCK_LIST) @rm -rf $@ && mkdir -p $@ @# Prepare tests dir for test binaries @mkdir $@/tests @@ -36,8 +45,5 @@ $(TARGET_DIR): $(RUN_BASH) $(BLOCK_LIST) $(BIN_DIR) @# Copy bash script @cp -f $(RUN_BASH) $@ -$(TESTS): $(TARGET_DIR) - @cp -f $(BIN_DIR)/$@ $(TARGET_DIR)/tests - clean: - @rm -rf $(BIN_DIR) $(TARGET_DIR) + @rm -rf $(TARGET_DIR) \ No newline at end of file diff --git a/tools/docker/.gitignore b/tools/docker/.gitignore new file mode 100644 index 000000000..c4d86dc34 --- /dev/null +++ b/tools/docker/.gitignore @@ -0,0 +1 @@ +bom/ diff --git a/tools/docker/Dockerfile.ubuntu22.04 b/tools/docker/Dockerfile.ubuntu22.04 index ab0f05403..c2f748689 100644 --- a/tools/docker/Dockerfile.ubuntu22.04 +++ b/tools/docker/Dockerfile.ubuntu22.04 @@ -1,27 +1,47 @@ -FROM ubuntu:22.04 +FROM ubuntu:22.04 as ubuntu-22.04-with-bazel SHELL ["/bin/bash", "-c"] ARG DEBIAN_FRONTEND=noninteractive + +# Install all Bazel dependent packages RUN apt update && apt-get install -y --no-install-recommends \ build-essential \ ca-certificates \ + curl \ + git-core \ + gnupg \ + python-is-python3 \ + python3-pip + +# Install bazel, which is required by the system call test suite from Gvisor project +COPY bom/syscall_test/install_bazel.sh /tmp/ +WORKDIR /tmp +RUN ./install_bazel.sh && rm -f /tmp/install_bazel.sh + +FROM ubuntu-22.04-with-bazel as syscall_test + +# Build the syscall test binaries +COPY bom/syscall_test /root/syscall_test +WORKDIR /root/syscall_test +RUN export BUILD_DIR=build && \ + make ${BUILD_DIR}/syscall_test_bins + +FROM ubuntu-22.04-with-bazel + +# Install all Jinux dependent packages +RUN apt update && apt-get install -y --no-install-recommends \ cpio \ cpuid \ - curl \ file \ g++ \ gdb \ - git-core \ - gnupg \ grub-common \ grub-pc \ libssl-dev \ net-tools \ openssh-server \ pkg-config \ - python-is-python3 \ - python3-pip \ qemu-system-x86 \ strace \ sudo \ @@ -31,17 +51,14 @@ RUN apt update && apt-get install -y --no-install-recommends \ xorriso \ zip -# Install bazel, , which is required by the system call test suite from Gvisor project -RUN curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg \ - && mv bazel.gpg /etc/apt/trusted.gpg.d/ \ - && echo 'deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8' | tee /etc/apt/sources.list.d/bazel.list \ - && apt update \ - && apt install bazel=5.4.0 -y - # Clean apt cache RUN apt clean \ && rm -rf /var/lib/apt/lists/* +# Prepare the system call test suite +COPY --from=syscall_test /root/syscall_test/build/syscall_test_bins /root/syscall_test_bins +ENV JINUX_PREBUILT_SYSCALL_TEST=/root/syscall_test_bins + # Install Rust ENV PATH="/root/.cargo/bin:${PATH}" ARG JINUX_RUST_VERSION diff --git a/tools/docker/build_image.sh b/tools/docker/build_image.sh index 1cc10a5b2..8a871aa56 100755 --- a/tools/docker/build_image.sh +++ b/tools/docker/build_image.sh @@ -7,10 +7,19 @@ CARGO_TOML_PATH=${SCRIPT_DIR}/../../Cargo.toml VERSION=$( grep -m1 -o '[0-9]\+\.[0-9]\+\.[0-9]\+' ${CARGO_TOML_PATH} | sed 's/[^0-9\.]//g' ) IMAGE_NAME=jinuxdev/jinux:${VERSION} DOCKER_FILE=${SCRIPT_DIR}/Dockerfile.ubuntu22.04 +BOM_DIR=${SCRIPT_DIR}/bom +TOP_DIR=${SCRIPT_DIR}/../../ ARCH=linux/amd64 RUST_TOOLCHAIN_PATH=${SCRIPT_DIR}/../../rust-toolchain.toml JINUX_RUST_VERSION=$( grep -m1 -o 'nightly-[0-9]\+-[0-9]\+-[0-9]\+' ${RUST_TOOLCHAIN_PATH} ) +# Prpare the BOM (bill of materials) directory to copy files or dirs into the docker image. +# This is because the `docker build` can not access the parent directory of the context. +if [ ! -d ${BOM_DIR} ]; then + mkdir -p ${BOM_DIR} + cp -rf ${TOP_DIR}/regression/syscall_test ${BOM_DIR}/ +fi + # Build docker cd ${SCRIPT_DIR} docker buildx build -f ${DOCKER_FILE} \