2023-06-17 20:24:22 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
# Author: Nils Freydank <nils.freydank@posteo.de>
|
|
|
|
PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
|
|
|
set -uxa
|
|
|
|
|
|
|
|
GPG_SIGNING_KEY="${GPG_SIGNING_KEY:-0x0F1DEAB2D36AD112}"
|
|
|
|
|
2023-07-29 17:30:39 +02:00
|
|
|
REGISTRY="${REGISTRY:-git.holgersson.xyz/gentoo-related/gentoo-binpkg-builder}"
|
|
|
|
VERSION="${VERSION:-$(date --utc +%Y%m%d_%H%M%S)}"
|
2023-07-02 10:43:36 +02:00
|
|
|
IMAGE_TAG="${REGISTRY}:${VERSION}"
|
|
|
|
|
2023-06-17 20:24:22 +02:00
|
|
|
REPOS="${REPOS:-/var/db/repos}"
|
|
|
|
DISTFILES="${DISTFILES:-/var/cache/distfiles-podman-1}"
|
2023-10-22 11:17:18 +02:00
|
|
|
DISTFILES_STAGE3="${DISTFILES_STAGE3:-distfiles}"
|
2023-06-17 20:24:22 +02:00
|
|
|
BINPKG="${BINPKG:-/var/cache/packages-podman-1}"
|
2023-08-31 21:46:08 +02:00
|
|
|
LOGDIR="${LOGDIR:-$(pwd)/log}"
|
2023-06-17 20:24:22 +02:00
|
|
|
DOCKER_FILE="${DOCKER_FILE:-$(pwd)/Dockerfile}"
|
|
|
|
|
2023-10-01 19:29:48 +02:00
|
|
|
ARCH="${ARCH:-amd64}"
|
|
|
|
MICROARCH="${MICROARCH:-amd64}"
|
|
|
|
OCI_ARCH="${OCI_ARCH:-linux/amd64}"
|
|
|
|
|
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-06-17 20:24:22 +02:00
|
|
|
# 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-06-17 20:24:22 +02:00
|
|
|
--shm-size=2G
|
|
|
|
# Share the gentoo repo, overlays etc.
|
|
|
|
-v "${REPOS}:/var/db/repos:ro"
|
|
|
|
# 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"
|
|
|
|
# Use the given OCI file/Dockerfile.
|
|
|
|
-f "${DOCKER_FILE}"
|
2023-10-01 19:29:48 +02:00
|
|
|
# Add details about the architecture.
|
|
|
|
--build-arg ARCH="${ARCH}"
|
|
|
|
--build-arg MICROARCH="${MICROARCH}"
|
|
|
|
--platform "${OCI_ARCH}"
|
2023-06-17 20:24:22 +02:00
|
|
|
# Tag the generated image.
|
|
|
|
-t "${IMAGE_TAG}"
|
2023-10-18 20:39:06 +02:00
|
|
|
-t "${REGISTRY}:latest"
|
2023-06-17 20:24:22 +02:00
|
|
|
# Label the image.
|
|
|
|
--label="gentoo-nfr-${IMAGE_TAG}"
|
2023-10-01 21:10:07 +02:00
|
|
|
# sign the image.
|
2023-06-17 20:24:22 +02:00
|
|
|
#--sign-by="${GPG_SIGNING_KEY}"
|
2023-06-17 23:29:18 +02:00
|
|
|
# Rebuild everything w/o cache.
|
2023-06-17 20:24:22 +02:00
|
|
|
--no-cache
|
|
|
|
)
|
|
|
|
|
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 ${@}."
|
|
|
|
}
|
|
|
|
|
2023-10-01 19:34:43 +02:00
|
|
|
# === Prepare all directories.
|
2023-10-01 18:50:24 +02:00
|
|
|
_mkdir "${REPOS}"
|
|
|
|
_mkdir "${DISTFILES}"
|
2023-10-22 11:17:18 +02:00
|
|
|
_mkdir "${DISTFILES_STAGE3}"
|
2023-10-01 18:50:24 +02:00
|
|
|
_mkdir "${BINPKG}"
|
|
|
|
_mkdir "${LOGDIR}"
|
2023-06-17 20:24:22 +02:00
|
|
|
|
2023-10-01 21:10:07 +02:00
|
|
|
# === Fetch the stage3 file (and verify it).
|
2023-10-22 11:17:18 +02:00
|
|
|
# Note: This uses some nasty string manipulation assuming a certain structure.
|
|
|
|
# If upstream changes the format, things will break here, again.
|
2023-10-01 21:10:07 +02:00
|
|
|
SERVER="https://ftp-osl.osuosl.org/pub/gentoo/releases/${ARCH}/autobuilds"
|
|
|
|
MY_STAGE3="latest-stage3-amd64-nomultilib-systemd-mergedusr.txt"
|
2023-10-22 11:17:18 +02:00
|
|
|
|
|
|
|
# Fetch the stage3 archive and its signature.
|
2023-10-22 11:17:18 +02:00
|
|
|
curl -sLC- -O --output-dir "${DISTFILES_STAGE3}" "${SERVER}/${MY_STAGE3}" \
|
2023-10-22 11:17:18 +02:00
|
|
|
|| exit_err "Could not download the pointer file for the stage3 archive."
|
2023-10-22 11:17:18 +02:00
|
|
|
gpg --verify "${DISTFILES_STAGE3}/${MY_STAGE3}" \
|
2023-10-22 11:17:18 +02:00
|
|
|
|| exit_err "Could not verify the download pointer file."
|
|
|
|
|
2023-10-22 11:17:18 +02:00
|
|
|
LATEST_ARCHIVE="$(grep $(echo ${MY_STAGE3} | sed 's/latest-//;s/.txt//') ${DISTFILES_STAGE3}/${MY_STAGE3} | cut -f1 -d' ')"
|
2023-10-01 21:10:07 +02:00
|
|
|
ARCHIVE_FILE_NAME="$(echo ${LATEST_ARCHIVE} | cut -f2 -d'/')"
|
|
|
|
|
2023-10-22 11:17:18 +02:00
|
|
|
curl -sLC- -O --output-dir "${DISTFILES_STAGE3}" "${SERVER}/${LATEST_ARCHIVE}" \
|
2023-10-01 21:10:07 +02:00
|
|
|
|| exit_err "Could not download the stage3 archive."
|
2023-10-22 11:17:18 +02:00
|
|
|
curl -sLC- -O --output-dir "${DISTFILES_STAGE3}" "${SERVER}/${LATEST_ARCHIVE}.asc" \
|
2023-10-01 21:10:07 +02:00
|
|
|
|| exit_err "Could not download the stage3 archive signature."
|
|
|
|
|
|
|
|
# Verify the signature.
|
2023-10-22 11:17:18 +02:00
|
|
|
gpg --verify "${DISTFILES_STAGE3}/${ARCHIVE_FILE_NAME}"{.asc,} \
|
2023-10-01 21:10:07 +02:00
|
|
|
|| exit_err "Could not verify the stage3 archive."
|
2023-10-01 19:34:43 +02:00
|
|
|
|
|
|
|
# === Remove the old tag 'latest'.
|
2023-10-01 18:50:24 +02:00
|
|
|
podman tag rm "${REGISTRY}:latest" # Do not exit_err here. At least on first run
|
|
|
|
# there is no latest tag to delete.
|
2023-10-01 19:34:43 +02:00
|
|
|
|
2023-10-01 19:35:23 +02:00
|
|
|
# === Build the new image.
|
2023-10-22 11:17:18 +02:00
|
|
|
podman build --build-arg=ROOTFS_FILENAME="${DISTFILES_STAGE3}/${ARCHIVE_FILE_NAME}" \
|
2023-10-22 11:17:17 +02:00
|
|
|
"${PODMAN_BUILD_ARGS[@]}" || exit_err "Build failed."
|
2023-07-02 10:43:36 +02:00
|
|
|
|
2023-06-17 20:24:22 +02:00
|
|
|
# vim:fileencoding=utf-8:ts=4:syntax=bash:expandtab
|