mirror of
https://github.com/edera-dev/sprout.git
synced 2025-12-19 15:20:17 +00:00
introduce image data copy polyfill to allow builds on systems without image mounts
This commit is contained in:
@@ -25,9 +25,37 @@ fi
|
|||||||
mkdir -p "${FINAL_DIR}"
|
mkdir -p "${FINAL_DIR}"
|
||||||
|
|
||||||
if [ "${SKIP_KERNEL_BUILD}" != "1" ] || [ "${SKIP_VM_BUILD}" != "1" ] || [ "${SKIP_SPROUT_BUILD}" != "1" ]; then
|
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
|
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
|
if [ "${SKIP_KERNEL_BUILD}" != "1" ]; then
|
||||||
echo "[kernel build] ${TARGET_ARCH} ${RUST_PROFILE}"
|
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
|
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
|
build kernel
|
||||||
fi
|
fi
|
||||||
|
|
||||||
docker run --rm -i \
|
copy_from_image "${DOCKER_PREFIX}/sprout-kernel-${TARGET_ARCH}" "kernel.efi" "${FINAL_DIR}/kernel.efi"
|
||||||
--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"
|
|
||||||
cp hack/configs/kernel.sprout.toml "${FINAL_DIR}/sprout.toml"
|
cp hack/configs/kernel.sprout.toml "${FINAL_DIR}/sprout.toml"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${SKIP_VM_BUILD}" != "1" ]; then
|
if [ "${SKIP_VM_BUILD}" != "1" ]; then
|
||||||
echo "[vm build] ${TARGET_ARCH} ${RUST_PROFILE}"
|
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 build --platform="${DOCKER_TARGET}" -t "${DOCKER_PREFIX}/sprout-ovmf-${TARGET_ARCH}:${DOCKER_TAG}" -f vm/Dockerfile.ovmf "${FINAL_DIR}"
|
||||||
docker run --rm -i \
|
copy_from_image "${DOCKER_PREFIX}/sprout-ovmf-${TARGET_ARCH}" "ovmf.fd" "${FINAL_DIR}/ovmf.fd"
|
||||||
--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"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${SKIP_SPROUT_BUILD}" != "1" ]; then
|
if [ "${SKIP_SPROUT_BUILD}" != "1" ]; then
|
||||||
echo "[sprout build] ${TARGET_ARCH} ${RUST_PROFILE}"
|
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 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 \
|
copy_from_image "${DOCKER_PREFIX}/sprout-${TARGET_ARCH}" "sprout.efi" "${FINAL_DIR}/sprout.efi"
|
||||||
--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"
|
|
||||||
mkdir -p "${FINAL_DIR}/efi/EFI/BOOT"
|
mkdir -p "${FINAL_DIR}/efi/EFI/BOOT"
|
||||||
cp "${FINAL_DIR}/sprout.efi" "${FINAL_DIR}/efi/EFI/BOOT/${EFI_NAME}.EFI"
|
cp "${FINAL_DIR}/sprout.efi" "${FINAL_DIR}/efi/EFI/BOOT/${EFI_NAME}.EFI"
|
||||||
if [ -f "${FINAL_DIR}/kernel.efi" ]; then
|
if [ -f "${FINAL_DIR}/kernel.efi" ]; then
|
||||||
@@ -68,7 +90,5 @@ fi
|
|||||||
if [ "${SKIP_BOOT_BUILD}" != "1" ]; then
|
if [ "${SKIP_BOOT_BUILD}" != "1" ]; then
|
||||||
echo "[boot build] ${TARGET_ARCH} ${RUST_PROFILE}"
|
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 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 \
|
copy_from_image "${DOCKER_PREFIX}/sprout-boot-${TARGET_ARCH}" "sprout.img" "${FINAL_DIR}/sprout.img"
|
||||||
--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"
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -13,8 +13,16 @@ delete_image() {
|
|||||||
cargo clean || true
|
cargo clean || true
|
||||||
|
|
||||||
if command -v docker >/dev/null 2>&1; then
|
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-x86_64 || true
|
||||||
delete_image sprout-aarch64 || 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
|
fi
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
FROM --platform=$BUILDPLATFORM debian:trixie@sha256:fd8f5a1df07b5195613e4b9a0b6a947d3772a151b81975db27d47f093f60c6e6
|
|
||||||
1
hack/utils/Dockerfile.copy-direct
Normal file
1
hack/utils/Dockerfile.copy-direct
Normal file
@@ -0,0 +1 @@
|
|||||||
|
FROM --platform=$BUILDPLATFORM debian:trixie@sha256:b7e663fabda920f28abf26e7fbfe0867145645fdf3e47a42323147242151e066
|
||||||
4
hack/utils/Dockerfile.copy-polyfill
Normal file
4
hack/utils/Dockerfile.copy-polyfill
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user