diff --git a/Makefile b/Makefile index 3d7b0d79c..2f567a9aa 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,11 @@ export PACKAGE := sysbox-ce export HOST_UID ?= $(shell id -u) export HOST_GID ?= $(shell id -g) +# Set default distro-release for scenarios in which this can't be easily determined (e.g., 'lsb_release' +# isn't available -- OSX). +DEFAULT_DISTRO := ubuntu +DEFAULT_DISTRO_RELEASE := jammy + # Obtain the current system architecture. UNAME_M := $(shell uname -m) ifeq ($(UNAME_M),x86_64) @@ -42,6 +47,8 @@ else ifeq ($(UNAME_M),arm) SYS_ARCH := armhf else ifeq ($(UNAME_M),armel) SYS_ARCH := armel +else + SYS_ARCH := $(UNAME_M) endif # Set target architecture if not explicitly defined by user. @@ -80,7 +87,12 @@ else INSTALL_DIR := ${DESTDIR} endif -IMAGE_BASE_DISTRO := $(shell cat /etc/os-release | grep "^ID=" | cut -d "=" -f2 | tr -d '"') +# Assume the default distro if /etc/os-release is not present. +ifeq ($(wildcard /etc/os-release),) + IMAGE_BASE_DISTRO := $(DEFAULT_DISTRO) +else + IMAGE_BASE_DISTRO := $(shell cat /etc/os-release | grep "^ID=" | cut -d "=" -f2 | tr -d '"') +endif # Host kernel info KERNEL_REL := $(shell uname -r) @@ -92,7 +104,7 @@ export KERNEL_REL ifeq ($(IMAGE_BASE_DISTRO),$(filter $(IMAGE_BASE_DISTRO),centos fedora redhat almalinux rocky amzn)) IMAGE_BASE_RELEASE := $(shell cat /etc/os-release | grep "^VERSION_ID" | cut -d "=" -f2 | tr -d '"' | cut -d "." -f1) KERNEL_HEADERS := kernels/$(KERNEL_REL) -else +else ifdef $(shell command -v lsb_release 2>/dev/null) IMAGE_BASE_RELEASE := $(shell cat /etc/os-release | grep "^VERSION_CODENAME" | cut -d "=" -f2) ifeq ($(IMAGE_BASE_DISTRO),linuxmint) IMAGE_BASE_DISTRO := ubuntu @@ -105,8 +117,12 @@ else endif KERNEL_HEADERS := linux-headers-$(KERNEL_REL) KERNEL_HEADERS_BASE := $(shell find /usr/src/$(KERNEL_HEADERS) -maxdepth 1 -type l -exec readlink {} \; | cut -d"/" -f2 | egrep -v "^\.\." | head -1) +else + # If lsb-release isn't available, then assume the default-distro-release. + IMAGE_BASE_RELEASE := $(DEFAULT_DISTRO_RELEASE) endif + TEST_DIR := $(CURDIR)/tests TEST_IMAGE := sysbox-test-$(TARGET_ARCH) TEST_IMAGE_FLATCAR := sysbox-test-flatcar-$(TARGET_ARCH):$(FLATCAR_VERSION) @@ -117,16 +133,26 @@ TEST_SYSTEMD_DOCKERFILE := Dockerfile.systemd.$(IMAGE_BASE_DISTRO) TEST_FILES := $(shell find tests -type f | egrep "\.bats") TEST_SCR := $(shell grep -rwl -e '\#!/bin/bash' -e '\#!/bin/sh' tests/*) -ifeq ($(KERNEL_HEADERS_BASE), ) - KERNEL_HEADERS_MOUNTS := -v /usr/src/$(KERNEL_HEADERS):/usr/src/$(KERNEL_HEADERS):ro -else - KERNEL_HEADERS_MOUNTS := -v /usr/src/$(KERNEL_HEADERS):/usr/src/$(KERNEL_HEADERS):ro \ - -v /usr/src/$(KERNEL_HEADERS_BASE):/usr/src/$(KERNEL_HEADERS_BASE):ro +# Set the kernel-header mounts for the test container. +KERNEL_HEADERS_PRESENT := $(shell stat /usr/src/$(KERNEL_HEADERS) >/dev/null 2>&1; echo $$?) +ifeq ($(KERNEL_HEADERS_PRESENT),0) + ifeq ($(KERNEL_HEADERS_BASE), ) + KERNEL_HEADERS_MOUNTS := -v /usr/src/$(KERNEL_HEADERS):/usr/src/$(KERNEL_HEADERS):ro + else + KERNEL_HEADERS_MOUNTS := -v /usr/src/$(KERNEL_HEADERS):/usr/src/$(KERNEL_HEADERS):ro \ + -v /usr/src/$(KERNEL_HEADERS_BASE):/usr/src/$(KERNEL_HEADERS_BASE):ro + endif endif - export KERNEL_HEADERS export KERNEL_HEADERS_MOUNTS +# Set the lib-modules mounts for the test container. +LIBMODULES_PRESENT := $(shell stat /lib/modules/$(KERNEL_REL)/kernel >/dev/null 2>&1; echo $$?) +ifeq ($(LIBMODULES_PRESENT),0) + LIBMODULES_MOUNTS := -v /lib/modules/$(KERNEL_REL):/lib/modules/$(KERNEL_REL):ro +endif + +# Set the sysbox package file path and name. PACKAGE_FILE_PATH ?= sysbox-pkgr/deb/build/$(TARGET_ARCH)/$(IMAGE_BASE_DISTRO)-$(IMAGE_BASE_RELEASE) PACKAGE_FILE_NAME := $(PACKAGE)_$(VERSION).linux_$(TARGET_ARCH).deb @@ -146,8 +172,26 @@ export TEST_VOL3 # In scenarios where the egress-interface's mtu is lower than expected (1500 bytes), # we must explicitly configure dockerd with such a value. -EGRESS_IFACE := $(shell ip route show | awk '/default via/ {print $$5}') -EGRESS_IFACE_MTU := $(shell ip link show dev $(EGRESS_IFACE) | awk '/mtu/ {print $$5}') +IP_CMD_PRESENT := $(shell command -v ip >/dev/null 2>&1; echo $$?) +ifeq ($(IP_CMD_PRESENT),0) + EGRESS_IFACE := $(shell ip route show | awk '/default via/ {print $$5}') + EGRESS_IFACE_MTU := $(shell ip link show dev $(EGRESS_IFACE) | awk '/mtu/ {print $$5}') +endif + +# libseccomp (used by Sysbox components) +LIBSECCOMP := sysbox-libs/libseccomp/src/.libs/libseccomp.a +LIBSECCOMP_DIR := sysbox-libs/libseccomp +FIND_CMD_PRESENT := $(shell command -v find >/dev/null 2>&1; echo $$?) +ifeq ($(FIND_CMD_PRESENT),0) + LIBSECCOMP_SRC := $(shell find $(LIBSECCOMP_DIR)/src 2>&1 | grep -E '.*\.(c|h)') + LIBSECCOMP_SRC += $(shell find $(LIBSECCOMP_DIR)/include 2>&1 | grep -E '.*\.h') +endif +STAT_CMD_PRESENT := $(shell command -v stat 2> /dev/null; echo $$?) +ifeq ($(STAT_CMD_PRESENT),0) + LIBSECCOMP_UID := $(shell stat -c %u ./sysbox-libs/libseccomp/README.md) + LIBSECCOMP_GID := $(shell stat -c %g ./sysbox-libs/libseccomp/README.md) +endif + # Ensure that a gitconfig file is always present. $(shell touch $(HOME)/.gitconfig) @@ -174,7 +218,7 @@ DOCKER_SYSBOX_BLD := docker run --privileged --rm --runtime=runc \ -v $(CURDIR):$(PROJECT) \ -v $(GOPATH)/pkg/mod:/go/pkg/mod \ -v $(HOME)/.gitconfig:/root/.gitconfig \ - -v /lib/modules/$(KERNEL_REL):/lib/modules/$(KERNEL_REL):ro \ + $(LIBMODULES_MOUNTS) \ $(KERNEL_HEADERS_MOUNTS) \ $(TEST_IMAGE) @@ -293,13 +337,13 @@ DOCKER_RUN := docker run --privileged --rm --runtime=runc \ -v $(TEST_VOL2):/mnt/scratch \ -v $(TEST_VOL3):/var/run \ -v $(GOPATH)/pkg/mod:/go/pkg/mod \ - -v /lib/modules/$(KERNEL_REL):/lib/modules/$(KERNEL_REL):ro \ -v $(HOME)/.gitconfig:/root/.gitconfig \ - $(KERNEL_HEADERS_MOUNTS) \ + $(LIBMODULES_MOUNTS) \ + $(KERNEL_HEADERS_MOUNTS) \ $(TEST_IMAGE) # For interactive targets -DOCKER_RUN_TTY := docker run -it --privileged --rm --runtime=runc \ +DOCKER_RUN_TTY := docker run -it --privileged --rm --runtime=runc \ --hostname sysbox-test \ --name sysbox-test \ -e HOST_UID=$(HOST_UID) \ @@ -309,9 +353,9 @@ DOCKER_RUN_TTY := docker run -it --privileged --rm --runtime=runc \ -v $(TEST_VOL2):/mnt/scratch \ -v $(TEST_VOL3):/var/run \ -v $(GOPATH)/pkg/mod:/go/pkg/mod \ - -v /lib/modules/$(KERNEL_REL):/lib/modules/$(KERNEL_REL):ro \ -v $(HOME)/.gitconfig:/root/.gitconfig \ - $(KERNEL_HEADERS_MOUNTS) \ + $(LIBMODULES_MOUNTS) \ + $(KERNEL_HEADERS_MOUNTS) \ $(TEST_IMAGE) # Must use "--cgroups private" as otherwise the inner Docker may get confused diff --git a/tests/Dockerfile.ubuntu-jammy b/tests/Dockerfile.ubuntu-jammy index 495a307e2..832c49578 100644 --- a/tests/Dockerfile.ubuntu-jammy +++ b/tests/Dockerfile.ubuntu-jammy @@ -35,6 +35,8 @@ ARG sys_arch ENV SYS_ARCH=${sys_arch} ARG target_arch ENV TARGET_ARCH=${target_arch} +ARG ENABLE_CRIO=0 +ARG ENABLE_PACK=0 ENV DEBIAN_FRONTEND=noninteractive @@ -99,6 +101,8 @@ RUN apt-get update && apt-get install -y \ attr \ tree \ strace \ + gpg \ + software-properties-common \ --no-install-recommends \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ @@ -107,8 +111,8 @@ RUN apt-get update && apt-get install -y \ && echo " StrictHostKeyChecking accept-new" >> /etc/ssh/ssh_config # Install Golang -RUN wget https://go.dev/dl/go1.22.6.linux-${sys_arch}.tar.gz && \ - tar -C /usr/local -xzf go1.22.6.linux-${sys_arch}.tar.gz && \ +RUN wget https://go.dev/dl/go1.23.0.linux-${sys_arch}.tar.gz && \ + tar -C /usr/local -xzf go1.23.0.linux-${sys_arch}.tar.gz && \ /usr/local/go/bin/go env -w GONOSUMDB=/root/nestybox ENV GOPATH=/go @@ -129,15 +133,9 @@ RUN cd /tmp \ && ./install.sh /usr/local \ && rm -rf /tmp/bats -# install protoc compiler for gRPC -RUN if [ "$sys_arch" = "amd64" ] ; then arch_str="x86_64"; \ - elif [ "$sys_arch" = "arm64" ]; then arch_str="aarch_64"; \ - else echo "Unsupported platform: ${sys_arch}"; exit; fi \ - && curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v3.15.8/protoc-3.15.8-linux-${arch_str}.zip \ - && unzip protoc-3.15.8-linux-${arch_str}.zip -d $HOME/.local \ - && export PATH="$PATH:$HOME/.local/bin" \ - && go install github.com/golang/protobuf/protoc-gen-go@latest \ - && export PATH="$PATH:$(go env GOPATH)/bin" +# install Go protoc plugins for gRPC (use apt-installed protoc) +RUN GOBIN=/usr/local/bin go install google.golang.org/protobuf/cmd/protoc-gen-go@latest \ + && GOBIN=/usr/local/bin go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest # Install Docker RUN curl -fsSL https://get.docker.com -o get-docker.sh \ @@ -159,25 +157,30 @@ RUN cd /tmp && curl -LO "https://dl.k8s.io/release/${k8s_version_full}/bin/linux # works with Sysbox. # # Instructions: https://cri-o.io/ -RUN apt-get update && apt-get install -y gpg software-properties-common -RUN curl -fsSL https://download.opensuse.org/repositories/isv:/cri-o:/stable:/${crio_version}/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/cri-o-apt-keyring.gpg \ - && echo "deb [signed-by=/etc/apt/keyrings/cri-o-apt-keyring.gpg] https://download.opensuse.org/repositories/isv:/cri-o:/stable:/${crio_version}/deb/ /" | tee /etc/apt/sources.list.d/cri-o.list \ - && apt-get update \ - && apt-get install -y cri-o +RUN if [ "$ENABLE_CRIO" = "1" ]; then \ + apt-get update && apt-get install -y gpg software-properties-common && \ + curl -fsSL https://download.opensuse.org/repositories/isv:/cri-o:/stable:/${crio_version}/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/cri-o-apt-keyring.gpg && \ + echo "deb [signed-by=/etc/apt/keyrings/cri-o-apt-keyring.gpg] https://download.opensuse.org/repositories/isv:/cri-o:/stable:/${crio_version}/deb/ /" | tee /etc/apt/sources.list.d/cri-o.list && \ + apt-get update && apt-get install -y cri-o; \ + fi # Build and install the Nestybox CRI-O (for testing deployment of pods with sysbox (aka "sysbox pods")) -RUN apt-get update && apt-get install -y --no-install-recommends libgpgme-dev \ - && mkdir -p /tmp/crio-build \ - && git clone https://github.com/nestybox/cri-o.git /tmp/crio-build/cri-o \ - && git -C /tmp/crio-build/cri-o checkout -b ${crio_version}-sysbox origin/${crio_version}-sysbox \ - && cd /tmp/crio-build/cri-o && make binaries \ - && mv /usr/bin/crio /usr/bin/crio.orig \ - && cp /tmp/crio-build/cri-o/bin/crio-static /usr/bin/crio \ - && rm -rf /tmp/crio-build - -RUN wget https://github.com/kubernetes-sigs/cri-tools/releases/download/${crictl_version}/crictl-${crictl_version}-linux-${sys_arch}.tar.gz \ - && sudo tar zxvf crictl-${crictl_version}-linux-${sys_arch}.tar.gz -C /usr/local/bin \ - && rm -f crictl-${crictl_version}-linux-${sys_arch}.tar.gz +RUN if [ "$ENABLE_CRIO" = "1" ]; then \ + apt-get update && apt-get install -y --no-install-recommends libgpgme-dev && \ + mkdir -p /tmp/crio-build && \ + git clone https://github.com/nestybox/cri-o.git /tmp/crio-build/cri-o && \ + git -C /tmp/crio-build/cri-o checkout -b ${crio_version}-sysbox origin/${crio_version}-sysbox && \ + cd /tmp/crio-build/cri-o && make binaries && \ + mv /usr/bin/crio /usr/bin/crio.orig && \ + cp /tmp/crio-build/cri-o/bin/crio-static /usr/bin/crio && \ + rm -rf /tmp/crio-build; \ + fi + +RUN if [ "$ENABLE_CRIO" = "1" ]; then \ + wget https://github.com/kubernetes-sigs/cri-tools/releases/download/${crictl_version}/crictl-${crictl_version}-linux-${sys_arch}.tar.gz && \ + sudo tar zxvf crictl-${crictl_version}-linux-${sys_arch}.tar.gz -C /usr/local/bin && \ + rm -f crictl-${crictl_version}-linux-${sys_arch}.tar.gz; \ + fi # Container CNIs (needed by CRI-O) RUN curl -fsSL https://pkgs.k8s.io/core:/stable:/${k8s_version}/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg \ @@ -213,10 +216,12 @@ RUN go install sigs.k8s.io/kind@v0.24.0 # kernels. RUN sed -i 's/^#define SECCOMP_IOCTL_NOTIF_ID_VALID[ \t]*SECCOMP_IOW(2, __u64)/#define SECCOMP_IOCTL_NOTIF_ID_VALID SECCOMP_IOR(2, __u64)/g' /usr/include/linux/seccomp.h -# Paketo buildpacks -RUN add-apt-repository ppa:cncf-buildpacks/pack-cli \ - && apt-get update \ - && apt-get install -y pack-cli +# Paketo buildpacks (optional) +RUN if [ "$ENABLE_PACK" = "1" ]; then \ + add-apt-repository ppa:cncf-buildpacks/pack-cli && \ + apt-get update && \ + apt-get install -y pack-cli; \ + fi # sysbox env RUN useradd sysbox \ @@ -230,4 +235,4 @@ COPY bin/userns_child_exec_${sys_arch} /usr/bin RUN mkdir -p /root/nestybox WORKDIR /root/nestybox/sysbox -CMD /bin/bash +CMD ["/bin/bash"]