From e5cf58e518ce2c1157941dde7ea7bab87bef7ee7 Mon Sep 17 00:00:00 2001 From: Bohdan Tkachenko Date: Mon, 1 Apr 2024 19:08:05 -0400 Subject: [PATCH] Allow to build zbm in containerized Debian env Added Dockerfile.debian so it does not conflict with the main Dockerfile. Also adjusted build-init.sh to support apt. --- releng/docker/Dockerfile.debian | 86 +++++++++++++++++++++++++++++++++ releng/docker/build-init.sh | 41 ++++++++++++---- 2 files changed, 117 insertions(+), 10 deletions(-) create mode 100644 releng/docker/Dockerfile.debian diff --git a/releng/docker/Dockerfile.debian b/releng/docker/Dockerfile.debian new file mode 100644 index 000000000..7249fb6f5 --- /dev/null +++ b/releng/docker/Dockerfile.debian @@ -0,0 +1,86 @@ +# syntax=docker/dockerfile:1.4 +# +# This Dockerfile creates a container that will create an EFI executable and +# separate kernel/initramfs components from a ZFSBootMenu repository. The +# container will pre-populate its /zbm directory with a clone of the master +# branch of the upstream ZFSBootMenu branch and build the images from that. +# +# To use a different ZFSBootMenu repository or version, bind-mound the +# repository you want on /zbm inside the container. +# +# Note - this Dockerfile depends on Docker >= 23 and the docker buildx plugin. + +# Use the official Debian container. Allow to customize tag,so different Debian +# version could be used. +ARG DEBIAN_TAG=bookworm-slim +FROM debian:$DEBIAN_TAG +LABEL org.opencontainers.image.authors="ZFSBootMenu Team, https://zfsbootmenu.org" + +ARG DEBIAN_FRONTEND=noninteractive +RUN --mount=type=cache,target=/var/lib/apt/lists \ + set -eux; \ + sed -i 's/Components: main/Components: main contrib non-free/' /etc/apt/sources.list.d/debian.sources && \ + apt-get update && \ + apt-get install --no-install-recommends -y \ + bash \ + ca-certificates \ + cryptsetup \ + curl \ + dosfstools \ + dracut \ + dracut-network \ + e2fsprogs \ + efibootmgr \ + fzf \ + gdisk \ + iproute2 \ + iputils-arping \ + iputils-clockdiff \ + iputils-ping \ + iputils-tracepath \ + kbd \ + kexec-tools \ + kpartx \ + less \ + libboolean-perl \ + libsort-versions-perl \ + libyaml-pp-perl \ + linux-headers-amd64 \ + linux-image-amd64 \ + mbuffer \ + ncurses-base \ + openssh-server \ + parted \ + pigz \ + procps \ + systemd-boot-efi \ + util-linux \ + zfs-dracut \ + zfsutils-linux \ + zstd \ + && \ + curl -L -o /usr/bin/yq-go https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 && \ + chmod +x /usr/bin/yq-go + +ARG ZFSBOOTMENU_VERSION="2.3.0" + +# ZFSBootMenu commit hash, tag or branch name used by +# default to build ZFSBootMenu images (default: master) +ARG ZBM_COMMIT_HASH= +# Record a commit hash if one was provided +RUN [ -z "${ZBM_COMMIT_HASH}" ] || echo "${ZBM_COMMIT_HASH}" > /etc/zbm-commit-hash + +# Include the specified Debian package in the image +# (multiple entries must be seperated by spaces) +ARG PACKAGES= +# Run ${PACKAGES} install in seperate layer so that the zfs dkms packages +# are not rebuilt when ${PACKAGES} change. reuse. +# Install ZFSBootMenu dependencies and components necessary to build images +RUN --mount=type=cache,target=/var/lib/apt/lists \ + [ -z "${PACKAGES}" ] || apt-get update && apt-get install -y ${PACKAGES} + +RUN rm -rf /var/lib/apt/lists/* + +COPY --chmod=755 build-init.sh / +# Run the build script with no arguments by default +ENTRYPOINT [ "/build-init.sh", "-m", "apt" ] diff --git a/releng/docker/build-init.sh b/releng/docker/build-init.sh index f81436fac..7e92550d1 100755 --- a/releng/docker/build-init.sh +++ b/releng/docker/build-init.sh @@ -29,9 +29,14 @@ Usage: $0 [options] (Default: \${BUILDROOT}/build) -p - Install the named Void Linux package in the container - before building. May be specified more than once to - install more than one package. + Install the named package in the container before building. + May be specified more than once to install more than one + package. + + -m + Specify a different package manager backend. + Supported backends: xbps, apt + (Default: xbps) -t Specify specific tag or commit hash to fetch @@ -79,11 +84,18 @@ update_packages() { *) hold_kern_zfs ;; esac - # Attempt to update xbps first - xbps-install -Syu xbps || return 1 + if [ "${PACKAGE_MANAGER}" == "xbps" ]; then + # Attempt to update xbps first + xbps-install -Syu xbps || return 1 - # Update all other packages - xbps-install -Syu || return 1 + # Update all other packages + xbps-install -Syu || return 1 + elif [ "${PACKAGE_MANAGER}" == "apt" ]; then + apt-get update + apt-get upgrade + else + error "unsupported package manager backend: ${PACKAGE_MANAGER}" + fi } PACKAGES=() @@ -93,7 +105,7 @@ GENARGS=() UPDATE= SKIP_VERSIONING= -while getopts "hb:o:t:e:p:uV" opt; do +while getopts "hb:o:t:e:p:m:uV" opt; do case "${opt}" in b) BUILDROOT="${OPTARG}" @@ -107,6 +119,9 @@ while getopts "hb:o:t:e:p:uV" opt; do p) PACKAGES+=( "${OPTARG}" ) ;; + m) + PACKAGE_MANAGER="${OPTARG}" + ;; e) CONFIGEVALS+=( "${OPTARG}" ) ;; @@ -155,9 +170,15 @@ if [ -n "${UPDATE}" ]; then update_packages "${UPDATE}" || error "failed to update packages" fi +# Install all requested packages if [ "${#PACKAGES[@]}" -gt 0 ]; then - # Install all requested packages - xbps-install -Sy "${PACKAGES[@]}" || error "failed to install requested packages" + if [ "${PACKAGE_MANAGER}" == "xbps" ]; then + xbps-install -Sy "${PACKAGES[@]}" || error "failed to install requested packages" + elif [ "${PACKAGE_MANAGER}" == "apt" ]; then + apt-get update && apt-get install -y "${PACKAGES[@]}" || error "failed to install requested packages" + else + error "unsupported package manager backend: ${PACKAGE_MANAGER}" + fi fi # If a custom rc.pre.d exists, run every executable file therein