Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to build ZFSBootManager in containerized Debian environment #612

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions releng/docker/Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -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" ]
41 changes: 31 additions & 10 deletions releng/docker/build-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ Usage: $0 [options]
(Default: \${BUILDROOT}/build)

-p <package>
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 <package manager>
Specify a different package manager backend.
Supported backends: xbps, apt
(Default: xbps)

-t <tag>
Specify specific tag or commit hash to fetch
Expand Down Expand Up @@ -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=()
Expand All @@ -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}"
Expand All @@ -107,6 +119,9 @@ while getopts "hb:o:t:e:p:uV" opt; do
p)
PACKAGES+=( "${OPTARG}" )
;;
m)
PACKAGE_MANAGER="${OPTARG}"
;;
e)
CONFIGEVALS+=( "${OPTARG}" )
;;
Expand Down Expand Up @@ -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
Expand Down