From b8e1d11bed65942a60abdd4f5fd8168a93cc4416 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Wed, 1 Oct 2025 21:51:58 -0700 Subject: [PATCH] introduce image data copy polyfill to allow builds on systems without image mounts --- hack/build.sh | 46 +++++++++++++++++++++-------- hack/clean.sh | 12 ++++++-- hack/utils/Dockerfile.copy | 1 - hack/utils/Dockerfile.copy-direct | 1 + hack/utils/Dockerfile.copy-polyfill | 4 +++ 5 files changed, 48 insertions(+), 16 deletions(-) delete mode 100644 hack/utils/Dockerfile.copy create mode 100644 hack/utils/Dockerfile.copy-direct create mode 100644 hack/utils/Dockerfile.copy-polyfill diff --git a/hack/build.sh b/hack/build.sh index 9b2652b..7004e45 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -25,9 +25,37 @@ fi mkdir -p "${FINAL_DIR}" if [ "${SKIP_KERNEL_BUILD}" != "1" ] || [ "${SKIP_VM_BUILD}" != "1" ] || [ "${SKIP_SPROUT_BUILD}" != "1" ]; then - docker build -t "${DOCKER_PREFIX}/sprout-utils-copy:${DOCKER_TAG}" -f hack/utils/Dockerfile.copy hack + docker build -t "${DOCKER_PREFIX}/sprout-utils-copy-direct:${DOCKER_TAG}" -f hack/utils/Dockerfile.copy-direct hack fi +copy_from_image_direct() { + IMAGE="${1}" + SOURCE="${2}" + TARGET="${3}" + + docker run --rm -i \ + --mount="type=image,source=${IMAGE},target=/image" \ + "${DOCKER_PREFIX}/sprout-utils-copy-direct:${DOCKER_TAG}" cat "/image/${SOURCE}" >"${TARGET}" 2>/dev/null +} + +copy_from_image_polyfill() { + IMAGE="${1}" + SOURCE="${2}" + TARGET="${3}" + + docker build -t "${IMAGE}-copy-polyfill:${DOCKER_TAG}" --build-arg "TARGET_IMAGE=${IMAGE}:${DOCKER_TAG}" \ + -f hack/utils/Dockerfile.copy-polyfill hack + # note: the -w '//' is a workaround for Git Bash where / is magically rewritten. + docker run --rm -i -w '//' "${IMAGE}-copy-polyfill:${DOCKER_TAG}" cat "image/${SOURCE}" >"${TARGET}" +} + +copy_from_image() { + if ! copy_from_image_direct "${@}" 2>/dev/null; then + echo "[warn] image mounts not supported, falling back to polyfill" + copy_from_image_polyfill "${@}" + fi +} + if [ "${SKIP_KERNEL_BUILD}" != "1" ]; then echo "[kernel build] ${TARGET_ARCH} ${RUST_PROFILE}" docker build --platform="${DOCKER_TARGET}" -t "${DOCKER_PREFIX}/sprout-kernel-${TARGET_ARCH}:${DOCKER_TAG}" -f kernel/Dockerfile kernel @@ -37,26 +65,20 @@ if [ "${SKIP_KERNEL_BUILD}" != "1" ]; then build kernel fi - docker run --rm -i \ - --mount="type=image,source=${DOCKER_PREFIX}/sprout-kernel-${TARGET_ARCH}:${DOCKER_TAG},target=/image" \ - "${DOCKER_PREFIX}/sprout-utils-copy:${DOCKER_TAG}" cat /image/kernel.efi >"${FINAL_DIR}/kernel.efi" + copy_from_image "${DOCKER_PREFIX}/sprout-kernel-${TARGET_ARCH}" "kernel.efi" "${FINAL_DIR}/kernel.efi" cp hack/configs/kernel.sprout.toml "${FINAL_DIR}/sprout.toml" fi if [ "${SKIP_VM_BUILD}" != "1" ]; then echo "[vm build] ${TARGET_ARCH} ${RUST_PROFILE}" docker build --platform="${DOCKER_TARGET}" -t "${DOCKER_PREFIX}/sprout-ovmf-${TARGET_ARCH}:${DOCKER_TAG}" -f vm/Dockerfile.ovmf "${FINAL_DIR}" - docker run --rm -i \ - --mount="type=image,source=${DOCKER_PREFIX}/sprout-ovmf-${TARGET_ARCH}:${DOCKER_TAG},target=/image" \ - "${DOCKER_PREFIX}/sprout-utils-copy:${DOCKER_TAG}" cat /image/ovmf.fd >"${FINAL_DIR}/ovmf.fd" + copy_from_image "${DOCKER_PREFIX}/sprout-ovmf-${TARGET_ARCH}" "ovmf.fd" "${FINAL_DIR}/ovmf.fd" fi if [ "${SKIP_SPROUT_BUILD}" != "1" ]; then echo "[sprout build] ${TARGET_ARCH} ${RUST_PROFILE}" docker build --platform="${DOCKER_TARGET}" -t "${DOCKER_PREFIX}/sprout-${TARGET_ARCH}:${DOCKER_TAG}" --build-arg="RUST_TARGET_SUBDIR=${RUST_TARGET_SUBDIR}" -f Dockerfile . - docker run --rm -i \ - --mount="type=image,source=${DOCKER_PREFIX}/sprout-${TARGET_ARCH}:${DOCKER_TAG},target=/image" \ - "${DOCKER_PREFIX}/sprout-utils-copy:${DOCKER_TAG}" cat /image/sprout.efi >"${FINAL_DIR}/sprout.efi" + copy_from_image "${DOCKER_PREFIX}/sprout-${TARGET_ARCH}" "sprout.efi" "${FINAL_DIR}/sprout.efi" mkdir -p "${FINAL_DIR}/efi/EFI/BOOT" cp "${FINAL_DIR}/sprout.efi" "${FINAL_DIR}/efi/EFI/BOOT/${EFI_NAME}.EFI" if [ -f "${FINAL_DIR}/kernel.efi" ]; then @@ -68,7 +90,5 @@ fi if [ "${SKIP_BOOT_BUILD}" != "1" ]; then echo "[boot build] ${TARGET_ARCH} ${RUST_PROFILE}" docker build --platform="${DOCKER_TARGET}" -t "${DOCKER_PREFIX}/sprout-boot-${TARGET_ARCH}:${DOCKER_TAG}" --build-arg "EFI_NAME=${EFI_NAME}" -f boot/Dockerfile "${FINAL_DIR}" - docker run --rm -i \ - --mount="type=image,source=${DOCKER_PREFIX}/sprout-boot-${TARGET_ARCH}:${DOCKER_TAG},target=/image" \ - "${DOCKER_PREFIX}/sprout-utils-copy:${DOCKER_TAG}" cat /image/sprout.img >"${FINAL_DIR}/sprout.img" + copy_from_image "${DOCKER_PREFIX}/sprout-boot-${TARGET_ARCH}" "sprout.img" "${FINAL_DIR}/sprout.img" fi diff --git a/hack/clean.sh b/hack/clean.sh index ae9a858..44d2f78 100755 --- a/hack/clean.sh +++ b/hack/clean.sh @@ -13,8 +13,16 @@ delete_image() { cargo clean || true if command -v docker >/dev/null 2>&1; then - delete_image sprout-utils-copy || true - delete_image sprout-ovmf || true delete_image sprout-x86_64 || true delete_image sprout-aarch64 || true + delete_image sprout-utils-copy-direct || true + delete_image sprout-utils-copy-polyfill || true + delete_image sprout-ovmf-x86_64 || true + delete_image sprout-ovmf-aarch64 || true + delete_image sprout-kernel-x86_64 || true + delete_image sprout-kernel-aarch64 || true + delete_image sprout-kernel-build-x86_64 || true + delete_image sprout-kernel-build-aarch64 || true + delete_image sprout-boot-x86_64 || true + delete_image sprout-boot-aarch64 || true fi diff --git a/hack/utils/Dockerfile.copy b/hack/utils/Dockerfile.copy deleted file mode 100644 index 6b2bdbe..0000000 --- a/hack/utils/Dockerfile.copy +++ /dev/null @@ -1 +0,0 @@ -FROM --platform=$BUILDPLATFORM debian:trixie@sha256:fd8f5a1df07b5195613e4b9a0b6a947d3772a151b81975db27d47f093f60c6e6 diff --git a/hack/utils/Dockerfile.copy-direct b/hack/utils/Dockerfile.copy-direct new file mode 100644 index 0000000..545d8a9 --- /dev/null +++ b/hack/utils/Dockerfile.copy-direct @@ -0,0 +1 @@ +FROM --platform=$BUILDPLATFORM debian:trixie@sha256:b7e663fabda920f28abf26e7fbfe0867145645fdf3e47a42323147242151e066 diff --git a/hack/utils/Dockerfile.copy-polyfill b/hack/utils/Dockerfile.copy-polyfill new file mode 100644 index 0000000..5061850 --- /dev/null +++ b/hack/utils/Dockerfile.copy-polyfill @@ -0,0 +1,4 @@ +ARG TARGET_IMAGE=scratch +FROM ${TARGET_IMAGE} AS image +FROM --platform=$BUILDPLATFORM debian:trixie@sha256:b7e663fabda920f28abf26e7fbfe0867145645fdf3e47a42323147242151e066 AS final +COPY --from=image / /image