From 6e87242fa03b7a99686b033c044ba53af069394f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frans=20F=C3=BCrst?= Date: Thu, 19 Sep 2024 16:32:06 +0200 Subject: [PATCH] run-in-docker.sh: add (temporary) debug checkmarks Change-Id: I4b9b5dbf3d9d3e2ce77483188fd880c9891f7ded --- scripts/run-in-docker.sh | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/scripts/run-in-docker.sh b/scripts/run-in-docker.sh index c74ed665a46..58922ad2724 100755 --- a/scripts/run-in-docker.sh +++ b/scripts/run-in-docker.sh @@ -24,6 +24,8 @@ set -e CHECKOUT_ROOT="$(git rev-parse --show-toplevel)" +echo >&2 "run-in-docker.sh checkpoint 1" + : "${IMAGE_ID:="$( if [ -n "${IMAGE_ALIAS}" ]; then "${CHECKOUT_ROOT}"/buildscripts/docker_image_aliases/resolve.py "${IMAGE_ALIAS}" @@ -32,8 +34,12 @@ CHECKOUT_ROOT="$(git rev-parse --show-toplevel)" fi )"}" +echo >&2 "run-in-docker.sh checkpoint 2 $IMAGE_ID" + IMAGE_VERSION="$(docker run --rm -v "${CHECKOUT_ROOT}/omd:/tmp" "${IMAGE_ID}" /tmp/distro '-')" +echo >&2 "run-in-docker.sh checkpoint 3 $IMAGE_VERSION" + # in case of worktrees $CHECKOUT_ROOT might not contain the actual repository clone GIT_COMMON_DIR="$(realpath "$(git rev-parse --git-common-dir)")" @@ -110,8 +116,25 @@ if [ -t 0 ]; then echo "Running in Docker container from image ${IMAGE_ID} (cmd=${CMD}) (workdir=${PWD})" fi +echo >&2 "run-in-docker.sh checkpoint 4" + +function cleanup { + echo >&2 "run-in-docker.sh checkpoint 5 $(cat "$CONTAINER_NAME.cid" || echo CID_FILE_NOT_FOUND)" + rm -f "$CONTAINER_NAME.cid" + + # FIXME: eventually created image is not being cleaned up + + ROOT_ARTIFACTS=$(find . -user root) + if [ -n "${ROOT_ARTIFACTS}" ]; then + echo >&2 "WARNING: there are files/directories owned by root:" + echo >&2 "${ROOT_ARTIFACTS}" + fi +} +trap cleanup EXIT + # shellcheck disable=SC2086 docker run -a stdout -a stderr \ + --cidfile "$CONTAINER_NAME.cid" \ --rm \ --name $CONTAINER_NAME \ ${TERMINAL_FLAG} \ @@ -144,11 +167,3 @@ docker run -a stdout -a stderr \ ${DOCKER_RUN_ADDOPTS} \ "${IMAGE_ID}" \ sh -c "${CMD}" - -# FIXME: eventually created image is not being cleaned up - -ROOT_ARTIFACTS=$(find . -user root) -if [ -n "${ROOT_ARTIFACTS}" ]; then - echo >&2 "WARNING: there are files/directories owned by root:" - echo >&2 "${ROOT_ARTIFACTS}" -fi