2023-07-02 11:32:24 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
# Author: Nils Freydank <nils.freydank@posteo.de>
|
|
|
|
PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
|
|
|
set -uxa
|
|
|
|
|
2023-07-29 17:16:58 +02:00
|
|
|
REGISTRY="${REGISTRY:-git.holgersson.xyz/gentoo-related/gentoo-binpkg-builder}"
|
|
|
|
VERSION="${VERSION:-latest}"
|
2023-07-02 11:32:24 +02:00
|
|
|
|
|
|
|
REPOS="${REPOS:-/var/db/repos}"
|
|
|
|
DISTFILES="${DISTFILES:-/var/cache/distfiles-podman-1}"
|
|
|
|
BINPKG="${BINPKG:-/var/cache/packages-podman-1}"
|
2023-08-31 21:46:08 +02:00
|
|
|
LOGDIR="${LOGDIR:-$(pwd)/log}"
|
2023-07-02 11:32:24 +02:00
|
|
|
PACKAGE_USE="${PACKAGE_USE:-$(pwd)/package.use}"
|
|
|
|
|
2023-10-01 18:50:23 +02:00
|
|
|
PODMAN_BUILD_ARGS=(
|
2023-08-06 21:34:30 +02:00
|
|
|
# Do not leak the host's /etc/host into the container.
|
|
|
|
--no-hosts
|
2023-07-02 11:32:24 +02:00
|
|
|
# Remove the container after usage.
|
|
|
|
--rm
|
|
|
|
# Allow interactive questsions by portage
|
|
|
|
-ti
|
|
|
|
# Limit the memory to be used.
|
|
|
|
--memory=20G
|
2023-10-01 19:12:12 +02:00
|
|
|
# memory-swap is the sum of RAM and swap.
|
|
|
|
--memory-swap=21G
|
2023-07-02 11:32:24 +02:00
|
|
|
--shm-size=2G
|
|
|
|
# Share the portage configuration.
|
|
|
|
-v "${PACKAGE_USE}:/etc/portage/package.use:ro"
|
|
|
|
# Share the gentoo repo, overlays etc.
|
|
|
|
-v "${REPOS}:/var/db/repos:ro"
|
2023-08-26 19:05:52 +02:00
|
|
|
# Share the world file, too.
|
|
|
|
-v "./world:/var/lib/portage/world:ro"
|
2023-07-02 11:32:24 +02:00
|
|
|
# Share the distfiles, i.e. typically source archives.
|
|
|
|
-v "${DISTFILES}:/var/cache/distfiles:rw,U"
|
|
|
|
# Share the binpkgs r/w cache.
|
|
|
|
-v "${BINPKG}:/var/cache/packages:rw,U"
|
|
|
|
# Keep the logs out of the container.
|
|
|
|
-v "${LOGDIR}:/var/log:rw,U"
|
|
|
|
)
|
|
|
|
|
2023-10-01 18:50:24 +02:00
|
|
|
exit_err()
|
|
|
|
{
|
|
|
|
echo "${@}"
|
2023-10-01 19:01:31 +02:00
|
|
|
exit 1
|
2023-10-01 18:50:24 +02:00
|
|
|
}
|
|
|
|
|
2023-10-01 18:50:24 +02:00
|
|
|
_mkdir()
|
|
|
|
{
|
|
|
|
mkdir -p "${@}" || exit_err "Could not create dir ${@}."
|
|
|
|
}
|
|
|
|
|
|
|
|
_mkdir "${REPOS}"
|
|
|
|
_mkdir "${DISTFILES}"
|
|
|
|
_mkdir "${BINPKG}"
|
|
|
|
_mkdir "${LOGDIR}"
|
2023-07-02 11:32:24 +02:00
|
|
|
|
2023-10-01 18:50:23 +02:00
|
|
|
podman run "${PODMAN_BUILD_ARGS[@]}" "${REGISTRY}:${VERSION}" \
|
2023-08-26 19:05:52 +02:00
|
|
|
bash -c "emerge --usepkg --newuse --keep-going --oneshot --deep --update @world \
|
|
|
|
&& emerge @golang-rebuild @rust-rebuild \
|
2023-10-01 18:50:24 +02:00
|
|
|
&& eclean-pkg --deep" \
|
|
|
|
|| exit_err "Could not build packages."
|
2023-07-02 11:32:24 +02:00
|
|
|
|
2023-10-01 18:50:24 +02:00
|
|
|
podman unshare chown -R "0:0" "${LOGDIR}" || exit_err "Could not fix access right post build."
|
2023-08-26 19:07:52 +02:00
|
|
|
|
2023-07-02 11:32:24 +02:00
|
|
|
# vim:fileencoding=utf-8:ts=4:syntax=bash:expandtab
|