From 38818e508aac55d99a79a722d863b3afac957ba3 Mon Sep 17 00:00:00 2001 From: Martchus Date: Fri, 3 Feb 2023 22:49:19 +0100 Subject: [PATCH] Improve investigation of containerized builds The current approach was not actually working as the container was not start with in interactive bash shell (or any kind of process that would just keep it running once started). --- README.md | 8 ++++---- devel/container/makecontainerpkg | 27 ++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6dd97193..86ee4770 100644 --- a/README.md +++ b/README.md @@ -106,10 +106,10 @@ locations. Finally, run `podman system migrate` to apply. ### Investigation of build failures -By default, `makecontainerpkg` starts the container via `--rm` so the container -is removed in the end. Set `DEBUG=1` to prevent that. Then one can use e.g. -`podman container start …` and `podman container exec -it … bash` to enter the -container for manual investigation. +By default, `makecontainerpkg` removes the container in the end. Set `DEBUG=1` +to prevent that. Then one can use e.g. `podman container exec -it … bash` to +enter the container for manual investigation. Set `DEBUG=on-failure` to only +keep the container in case of a failure. ### Using Arch-packages on another distribution via a container If you want to cross-compile software on non-Arch distributions you can make use diff --git a/devel/container/makecontainerpkg b/devel/container/makecontainerpkg index ccc70baa..3578aca0 100755 --- a/devel/container/makecontainerpkg +++ b/devel/container/makecontainerpkg @@ -1,9 +1,13 @@ #!/bin/bash set -e +# make basic arguments for cre +pkgname=$(grep -oP '(?<=pkgname=).+(?=$)' PKGBUILD | tr '+' 'p') +uuid=$(cat /proc/sys/kernel/random/uuid) +name=makechrootpkg-$pkgname-$uuid +cre_args=(--name "$name" --workdir "/startdir" -v "$PWD":/startdir -it) + # parse arguments -cre_args=(--workdir "/startdir" -v "$PWD":/startdir) -[[ $DEBUG ]] || script_args+=(--rm) script_args= read_script_args= no_sync= for arg in "$@"; do if [[ $read_script_args ]]; then @@ -27,4 +31,21 @@ if ! [[ $no_sync ]]; then script_sync=$(cat "$bindir/containersync") fi -${CRE:-docker} run "${cre_args[@]}" "${CRE_IMAGE:-archlinux-base-devel}" bash -c "$script_sync $script $script_args" +# invoke containerized build +ec=0 cre=${CRE:-docker} +"$cre" container create "${cre_args[@]}" "${CRE_IMAGE:-archlinux-base-devel}" +"$cre" container start "$name" +"$cre" container exec "$name" bash \ + -c "$script_sync $script $script_args" || ec=$? + +# stop and remove container unless we want to keep it for debugging +[[ $ec == 0 && $DEBUG == on-failure || -z $DEBUG ]] && \ + "$cre" container rm --force --time 0 "$name" + +# log message about commands to use for investigation +[[ $ec != 0 ]] && [[ $DEBUG ]] && echo \ + "You may investigate the failure via: + $cre exec -it '$name' bash + $cre mount '$name'" + +exit $ec