fix(ci): build the ISO in a privileged container via the host Docker socket

This commit is contained in:
BlackAngelTV committed 2026-12-04 15:33:56 +01:00
1 parent c704a72d3e
commit c233440b77
2 files changed
+80 -27

No files matched your search

+24 -25
View File
@@ -38,8 +38,9 @@ concurrency:
jobs:
release:
# Organisation runners: labels arch-host, ubuntu-latest, debian, alpine.
# mkarchiso needs an Arch environment, root, loop devices and mount, so the
# job must run privileged (act_runner: container.privileged = true).
# Jobs run in an unprivileged Arch container (mount denied, no user
# namespaces), so build-offi.sh builds in a privileged archlinux container
# through the host's Docker socket.
runs-on: arch-host
timeout-minutes: 180
@@ -69,39 +70,37 @@ jobs:
./release.sh --check
fi
- name: Outils du runner (docker)
if: steps.check.outputs.publish == 'true' || inputs.build_only
run: |
# The job runs in an unprivileged container: mount() is denied and
# user namespaces are off. build-offi.sh detects that and runs
# mkarchiso in a privileged archlinux container through the host
# Docker socket, so only the Docker CLI is needed here.
SUDO=(); [ "$(id -u)" -eq 0 ] || SUDO=(sudo)
"${SUDO[@]}" pacman -S --needed --noconfirm --quiet docker
- name: Pré-vol du runner
if: steps.check.outputs.publish == 'true' || inputs.build_only
run: |
for c in bash curl jq git pacman; do
for c in bash curl jq git pacman docker; do
command -v "${c}" >/dev/null 2>&1 \
|| { echo "::error::${c} absent du runner"; exit 1; }
done
# mkarchiso needs root: either the job already runs as root, or the
# runner allows passwordless sudo.
# build-offi.sh elevates itself once, to install packages and drive
# Docker; the build itself runs as root in the privileged container.
[ "$(id -u)" -eq 0 ] || sudo -n true 2>/dev/null \
|| { echo "::error::mkarchiso exige root (job root ou sudo sans mot de passe)"; exit 1; }
|| { echo "::error::sudo sans mot de passe requis (installation des paquets) "; exit 1; }
# mkarchiso bind-mounts /proc and /dev inside the chroot and loops the
# squashfs. In a non-privileged container mount() is denied even as
# root, and the build only dies at pacstrap minutes later: check now.
SUDO=(); [ "$(id -u)" -eq 0 ] || SUDO=(sudo)
MP="$(mktemp -d)"
if ! MOUNT_ERR="$("${SUDO[@]}" mount -t tmpfs tmpfs "${MP}" 2>&1)"; then
rmdir "${MP}" 2>/dev/null || true
echo "::error::le runner refuse mount() : ${MOUNT_ERR}"
echo "::error::mkarchiso a besoin de CAP_SYS_ADMIN + des loop devices. Config act_runner : container.privileged: true puis redémarrer le daemon, ou enregistrer le label arch-host en mode host."
# The privileged container is the only place where mount() works:
# prove the socket and a mount now, not after 20 minutes of build.
[ -S /var/run/docker.sock ] \
|| { echo "::error::/var/run/docker.sock absent : impossible de lancer le conteneur de build"; exit 1; }
if ! MOUNT_ERR="$(docker run --rm --privileged archlinux:latest \
sh -c 'mount -t tmpfs tmpfs /mnt && umount /mnt' 2>&1)"; then
echo "::error::le conteneur de build ne peut pas monter : ${MOUNT_ERR}"
exit 1
fi
"${SUDO[@]}" umount "${MP}" && rmdir "${MP}"
- name: Dépendances de l'hôte (mkarchiso)
if: steps.check.outputs.publish == 'true' || inputs.build_only
run: |
# mkarchiso validates the host tools of every boot mode of the
# profile and aborts otherwise: grub-install (uefi.grub), mkfs.fat
# (dosfstools) and mcopy (mtools). --needed: no-op once present.
SUDO=(); [ "$(id -u)" -eq 0 ] || SUDO=(sudo)
"${SUDO[@]}" pacman -S --needed --noconfirm --quiet grub dosfstools mtools
- name: Build officiel et publication
if: steps.check.outputs.publish == 'true' || inputs.build_only
+56 -2
View File
@@ -227,6 +227,60 @@ if [ "$EUID" -ne 0 ]; then
fi
fi
# ── Conteneur sans CAP_SYS_ADMIN : builder via le Docker de l'hôte ──────────
# A Gitea runner runs jobs in an unprivileged container: mount() is denied and
# user namespaces are off, so mkarchiso cannot build in place. The host Docker
# socket is mounted though: re-run the build in a privileged archlinux
# container, streaming the tree in and the ISO out. A bind mount would not do:
# the runner workspace is not a path on the Docker host.
can_mount() {
local mp
mp="$(mktemp -d)" || return 1
if mount -t tmpfs tmpfs "$mp" 2>/dev/null; then
umount "$mp" 2>/dev/null
rmdir "$mp" 2>/dev/null
return 0
fi
rmdir "$mp" 2>/dev/null
return 1
}
if [ -z "$FWS_IN_CONTAINER" ] && ! can_mount; then
command -v docker >/dev/null 2>&1 \
|| { echo -e "\e[31mmount() refusé et docker absent : ce conteneur ne peut pas builder.\e[0m" >&2
echo " Installe docker (pacman -S docker) ou rends le runner privilégié." >&2
exit 1; }
[ -S /var/run/docker.sock ] \
|| { echo -e "\e[31mmount() refusé et /var/run/docker.sock absent : aucun moteur Docker joignable.\e[0m" >&2; exit 1; }
docker info >/dev/null 2>&1 \
|| { echo -e "\e[31mmount() refusé et démon Docker injoignable.\e[0m" >&2; exit 1; }
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
IMAGE="docker.io/library/archlinux:latest"
echo -e "\e[36mmount() refusé : build dans un conteneur Arch privilégié (docker)...\e[0m"
docker pull "$IMAGE" || exit 1
CID="$(docker create --privileged --network=host \
-e FWS_IN_CONTAINER=1 \
-e FWS_ISO_VERSION -e FWS_ISO_TAG \
-v fws-pacman-cache:/var/cache/pacman/pkg \
-w /tmp "$IMAGE" bash /tmp/build-offi.sh)" || exit 1
# docker cp from stdin needs an existing destination directory: /tmp is
# one, and it keeps the copied tree out of the container's root.
tar -C "$REPO_DIR" --exclude=./.git --exclude=./out -cf - . \
| docker cp - "$CID:/tmp" \
|| { docker rm -f "$CID" >/dev/null 2>&1; exit 1; }
if docker start -a "$CID"; then rc=0; else rc=$?; fi
if [ "$rc" -eq 0 ]; then
mkdir -p "$REPO_DIR/out"
docker cp "$CID:/tmp/out/." "$REPO_DIR/out/" || rc=$?
fi
docker rm -f "$CID" >/dev/null 2>&1 || true
OWNER="$(stat -c '%u:%g' "$REPO_DIR" 2>/dev/null || true)"
[ -z "$OWNER" ] || chown -R "$OWNER" "$REPO_DIR/out" 2>/dev/null || true
exit "$rc"
fi
if grep -qi 'microsoft\|wsl' /proc/version 2>/dev/null; then
echo -e "\e[36mBuild officiel dans WSL ($DISTRO_NAME) en tant que root...\e[0m"
IS_WSL=1
@@ -309,9 +363,9 @@ reflector --verbose --latest 10 --sort rate --save /etc/pacman.d/mirrorlist || t
if [ -n "$FWS_IN_CONTAINER" ]; then
# Image de base qui vieillit → upgrade complet AVANT d'ajouter archiso,
# sinon partial upgrade (archiso tire des deps plus récentes que la base).
pacman -Syu --noconfirm archiso
pacman -Syu --noconfirm archiso grub
else
pacman -Sy --noconfirm archiso
pacman -Sy --noconfirm archiso grub
fi
echo "==> Préparation de l'environnement de build..."