Skip to content

Commit

Permalink
releng/docker/image-build.sh: support custom XBPS repositories
Browse files Browse the repository at this point in the history
- Allow mounting of one or more host directories into buildah container
  to use as custom repositories when creating the build image

- Allow specification of one or more custom remote repositories that
  will take precedence over the XBPS default repository

- Fixup: prune headers for all default-installed kernels
  • Loading branch information
ahesford committed Aug 3, 2023
1 parent 6602a18 commit 3682393
Showing 1 changed file with 55 additions and 17 deletions.
72 changes: 55 additions & 17 deletions releng/docker/image-build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#!/bin/sh
#!/bin/bash
# vim: softtabstop=2 shiftwidth=2 expandtab

usage() {
cat <<-EOF
USAGE: $0 [-h] [-p <pkg>] <tag> [zbm-commit-like]
USAGE: $0 [-h] [-r <path>] [-R <repo>] [-p <pkg>] <tag> [zbm-commit-like]
Create a container image for building ZFSBootMenu
-h: Display this message and exit
-r <path>:
Mount the specified path into the build container when installing
packages and configure XBPS to use the path as a package repository
(One path per argument; may be repeated as needed)
-R <repo>:
Configure XBPS to use the specified Void Linux package repository
(One repository per argument; may be repeated as needed)
-p <pkg>:
Include the specified Void Linux package in the image
(One package per argument; may be repeated as needed)
Expand All @@ -23,11 +33,35 @@ usage() {

set -o errexit

extra_pkgs=""
while getopts "hp:" opt; do
extra_pkgs=()

host_mounts=()
host_repos=()

web_repos=()

while getopts "hp:r:R:" opt; do
case "${opt}" in
p)
extra_pkgs="${extra_pkgs} ${OPTARG}"
extra_pkgs+=( "${OPTARG}" )
;;
r)
target="/pkgs/${#host_repos[@]}"
host_repos+=( "${target}" )
host_mounts+=( --mount "type=bind,src=${OPTARG},dst=${target},ro" )
;;
R)
# Sanitize repo arguments
case "${OPTARG}" in
/*|http://*|https://*)
;;
*)
echo "ERROR: '${OPTARG}' does not appear to be a valid repository"
exit 1
;;
esac

web_repos+=( "${OPTARG}" )
;;
h)
usage
Expand Down Expand Up @@ -72,20 +106,22 @@ container="$(buildah from ghcr.io/void-linux/void-linux:latest-full-x86_64)"

buildah config --label author="${maintainer}" "${container}"

# Use servercentral.com by default
buildah run "${container}" sh -c "cat > /etc/xbps.d/00-repository-main.conf" <<-EOF
repository=https://mirrors.servercentral.com/voidlinux/current
EOF
# Favor custom repositories
for repo in "${host_repos[@]}" "${web_repos[@]}"; do
buildah run "${container}" sh -c "cat >> /etc/xbps.d/00-custom-repos.conf" <<-EOF
repository=${repo}
EOF
done

# Make sure image is up to date
buildah run "${container}" xbps-install -Syu xbps
buildah run "${container}" xbps-install -Syu
buildah run "${host_mounts[@]}" "${container}" xbps-install -Syu xbps
buildah run "${host_mounts[@]}" "${container}" xbps-install -Syu

# Add extra packages, as desired
if [ -n "${extra_pkgs}" ]; then
echo "INFO: adding extra Void packages: ${extra_pkgs}"
if [ "${#extra_pkgs[@]}" -gt 0 ]; then
echo "INFO: adding extra Void packages: ${extra_pkgs[*]}"
# shellcheck disable=SC2086
buildah run "${container}" xbps-install -y ${extra_pkgs}
buildah run "${host_mounts[@]}" "${container}" xbps-install -y "${extra_pkgs[@]}"
fi

# Prefer an LTS version over whatever Void thinks is current
Expand All @@ -101,9 +137,10 @@ buildah run "${container}" sh -c "cat > /etc/xbps.d/15-noinitramfs.conf" <<-EOF
EOF

# Install ZFSBootMenu dependencies and components necessary to build images
buildah run "${container}" \
buildah run "${host_mounts[@]}" "${container}" \
sh -c 'xbps-query -Rp run_depends zfsbootmenu | xargs xbps-install -y'
buildah run "${container}" xbps-install -y linux5.10 linux5.10-headers \
buildah run "${host_mounts[@]}" "${container}" \
xbps-install -y linux5.10 linux5.10-headers \
linux5.15 linux5.15-headers linux6.1 linux6.1-headers zstd \
gummiboot-efistub curl yq-go bash kbd terminus-font \
dracut mkinitcpio dracut-network gptfdisk iproute2 iputils parted curl \
Expand All @@ -112,7 +149,8 @@ buildah run "${container}" xbps-install -y linux5.10 linux5.10-headers \
# Remove headers and development toolchain, but keep binutils for objcopy
buildah run "${container}" sh -c 'echo "ignorepkg=dkms" > /etc/xbps.d/10-nodkms.conf'
buildah run "${container}" xbps-pkgdb -m manual binutils
buildah run "${container}" xbps-remove -Roy linux5.10-headers dkms
buildah run "${container}" \
xbps-remove -Roy linux5.10-headers linux5.15-headers linux6.1-headers dkms
buildah run "${container}" sh -c 'rm -f /var/cache/xbps/*'

# Record a commit hash if one is available
Expand Down

0 comments on commit 3682393

Please sign in to comment.