feat(build): add podman container support for non-arch linux distributions
Add automatic detection and relaunching of build scripts in an Arch Linux container via podman when running on non-Arch distributions (Fedora, Ubuntu, Debian, etc.). Key changes: - Implement host_is_arch() function to detect if running on Arch Linux by checking both pacman availability and /etc/os-release - When non-Arch host is detected, scripts automatically pull docker.io/library/archlinux:latest and relaunch themselves in rootful podman container with --privileged - Mount repository at same absolute path inside container so WORK_DIR and out/ directories work transparently - Set up persistent pacman cache volume (fws-pacman-cache) between runs - Auto-chown output files back to host user after build completes - Update pacman config to disable landlock sandbox in containers (similar to WSL workaround) - Run full pacman -Syu upgrade in container before installing archiso to avoid partial upgrade issues - Add comprehensive documentation in README about Fedora/non-Arch setup - Update .gitignore to exclude pkgbuilds/ directory - Add environnement.md documentation file
This commit is contained in:
+79
-6
@@ -93,7 +93,72 @@ if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || -n "$WINDIR" ]]; then
|
||||
fi
|
||||
|
||||
# ============================================================
|
||||
# Exécution native (Arch Linux bare-metal OU dans WSL)
|
||||
# Bascule conteneur : hôte non-Arch (Fedora, Ubuntu, …) →
|
||||
# build dans un conteneur Arch via podman.
|
||||
#
|
||||
# mkarchiso exige pacman + des mounts/chroot/loop privilégiés que
|
||||
# seul un environnement Arch fournit. Sur un hôte non-Arch on relance
|
||||
# CE script à l'identique dans docker.io/library/archlinux:latest, le
|
||||
# dépôt monté au MÊME chemin absolu (→ WORK_DIR et out/ inchangés).
|
||||
# podman ROOTFUL + --privileged obligatoire : rootless ne gère pas les
|
||||
# mounts/chroot de mkarchiso (et --privileged relâche aussi SELinux,
|
||||
# enforcing sur Fedora, sur le bind-mount sans avoir besoin de :Z).
|
||||
# ============================================================
|
||||
host_is_arch() {
|
||||
# Fedora empaquette aussi « pacman » → sa seule présence ne suffit pas ;
|
||||
# on exige en plus un ID/ID_LIKE « arch » dans /etc/os-release.
|
||||
command -v pacman >/dev/null 2>&1 \
|
||||
&& grep -qiE '^ID(_LIKE)?=.*arch' /etc/os-release 2>/dev/null
|
||||
}
|
||||
|
||||
if [ -z "$FWS_IN_CONTAINER" ] && ! host_is_arch; then
|
||||
echo -e "\e[36mHôte non-Arch détecté — build officiel dans un conteneur Arch (podman)...\e[0m"
|
||||
|
||||
command -v podman >/dev/null 2>&1 || {
|
||||
echo -e "\e[31mpodman introuvable.\e[0m" >&2
|
||||
echo " Fedora : sudo dnf install -y podman" >&2
|
||||
echo " Debian/Ubuntu : sudo apt install -y podman" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Rootful : préfixe sudo si on n'est pas déjà root.
|
||||
SUDO=(); [ "$EUID" -eq 0 ] || SUDO=(sudo)
|
||||
# -it seulement si on est dans un terminal (sinon podman casse en CI).
|
||||
TTY=(); [ -t 0 ] && TTY=(-it)
|
||||
|
||||
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SELF="$(basename "${BASH_SOURCE[0]}")"
|
||||
IMAGE="docker.io/library/archlinux:latest"
|
||||
|
||||
# pull explicite : « run » ne re-résout jamais le tag « latest » une fois
|
||||
# l'image en cache → sans ça on build indéfiniment sur une image qui
|
||||
# vieillit (puis partial upgrades pacman). Le -Syu côté conteneur (plus
|
||||
# bas) complète la parade.
|
||||
echo "==> Pull de l'image $IMAGE..."
|
||||
"${SUDO[@]}" podman pull "$IMAGE"
|
||||
|
||||
echo "==> Relance dans le conteneur ($SELF)..."
|
||||
"${SUDO[@]}" podman run --rm "${TTY[@]}" --privileged \
|
||||
-e FWS_IN_CONTAINER=1 \
|
||||
-v "$REPO_DIR":"$REPO_DIR" \
|
||||
-v fws-pacman-cache:/var/cache/pacman/pkg \
|
||||
-w "$REPO_DIR" \
|
||||
"$IMAGE" \
|
||||
bash "$REPO_DIR/$SELF"
|
||||
|
||||
# podman rootful → les fichiers produits (out/) appartiennent à root.
|
||||
# On les rend au propriétaire du dépôt pour confort côté hôte.
|
||||
OWNER="$(stat -c '%u:%g' "$REPO_DIR" 2>/dev/null || true)"
|
||||
if [ -n "$OWNER" ]; then
|
||||
for d in out local-repo; do
|
||||
[ -e "$REPO_DIR/$d" ] && "${SUDO[@]}" chown -R "$OWNER" "$REPO_DIR/$d" 2>/dev/null || true
|
||||
done
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ============================================================
|
||||
# Exécution native (Arch Linux bare-metal, WSL, OU conteneur Arch)
|
||||
# ============================================================
|
||||
command -v pacman >/dev/null \
|
||||
|| { echo -e "\e[31mpacman introuvable — lance ce script depuis Arch / WSL.\e[0m"; exit 1; }
|
||||
@@ -147,17 +212,25 @@ echo "==> Version officielle : ${MAJOR}.${MINOR}.${BUILD}"
|
||||
echo "==> Dossier de sortie : $OUT_DIR"
|
||||
echo "==> ISO finale : FWS-${ISO_VERSION}-x86_64.iso"
|
||||
|
||||
# pacman ≥ 7 sandboxe les ops FS via landlock, non supporté par le
|
||||
# kernel WSL → désactivation. Idempotent, sans effet sur Arch natif.
|
||||
if [ "$IS_WSL" -eq 1 ] && ! grep -qE '^[[:space:]]*DisableSandbox' /etc/pacman.conf; then
|
||||
# pacman ≥ 7 sandboxe les ops FS via landlock, non supporté par le kernel
|
||||
# WSL ni (selon le noyau) par le conteneur → désactivation. Idempotent,
|
||||
# sans effet sur Arch natif.
|
||||
if { [ "$IS_WSL" -eq 1 ] || [ -n "$FWS_IN_CONTAINER" ]; } \
|
||||
&& ! grep -qE '^[[:space:]]*DisableSandbox' /etc/pacman.conf; then
|
||||
sed -i '/^\[options\]/a DisableSandbox' /etc/pacman.conf
|
||||
echo "==> WSL détecté → DisableSandbox ajouté à /etc/pacman.conf"
|
||||
echo "==> WSL/conteneur détecté → DisableSandbox ajouté à /etc/pacman.conf"
|
||||
fi
|
||||
|
||||
echo "==> Mise à jour des miroirs et installation de archiso..."
|
||||
pacman -Sy --noconfirm reflector || true
|
||||
reflector --verbose --latest 10 --sort rate --save /etc/pacman.d/mirrorlist || true
|
||||
pacman -Sy --noconfirm archiso
|
||||
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
|
||||
else
|
||||
pacman -Sy --noconfirm archiso
|
||||
fi
|
||||
|
||||
echo "==> Préparation de l'environnement de build..."
|
||||
rm -rf /tmp/fws-build
|
||||
|
||||
Reference in New Issue
Block a user