[PATCH] kas-container: Move container engine detection after argument parsing

3 views
Skip to first unread message

Jan Kiszka

unread,
Jun 4, 2026, 2:25:45 AMJun 4
to kas-devel, Felix Moessbauer
From: Jan Kiszka <jan.k...@siemens.com>

This allows to run "kas-container --help" even in the absence of a
container engine.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
kas-container | 62 ++++++++++++++++++++++++++-------------------------
1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/kas-container b/kas-container
index 0ef962c..6ab7547 100755
--- a/kas-container
+++ b/kas-container
@@ -319,35 +319,6 @@ setup_kas_dirs()
}
setup_kas_dirs

-KAS_CONTAINER_ENGINE="${KAS_CONTAINER_ENGINE:-${KAS_DOCKER_ENGINE}}"
-if [ -z "${KAS_CONTAINER_ENGINE}" ]; then
- # Try to auto-detect a container engine
- if command -v docker >/dev/null 2>&1 && docker -v 2>/dev/null | grep -q '^Docker'; then
- KAS_CONTAINER_ENGINE=docker
- elif command -v podman >/dev/null 2>&1; then
- KAS_CONTAINER_ENGINE=podman
- else
- fatal_error "no container engine found, need docker or podman"
- fi
-fi
-
-KAS_RUNTIME_ARGS="--log-driver=none --user=root"
-
-case "${KAS_CONTAINER_ENGINE}" in
-docker)
- KAS_CONTAINER_COMMAND="docker"
- enable_unpriv_userns_docker
- check_docker_rootless
- ;;
-podman)
- KAS_CONTAINER_COMMAND="podman"
- KAS_RUNTIME_ARGS="${KAS_RUNTIME_ARGS} --security-opt label=disable"
- ;;
-*)
- fatal_error "unknown container engine '${KAS_CONTAINER_ENGINE}'"
- ;;
-esac
-
# parse kas-container options, leave build system empty to distinguish between
# explicitly set via flag and implicitly via config.
BUILD_SYSTEM=""
@@ -384,7 +355,7 @@ while [ $# -gt 0 ]; do
;;
--runtime-args | --docker-args)
[ $# -gt 0 ] || usage
- KAS_RUNTIME_ARGS="${KAS_RUNTIME_ARGS} $2"
+ KAS_EXTRA_RUNTIME_ARGS=" $2"
shift 2
;;
--ssh-dir)
@@ -485,6 +456,37 @@ while [ $# -gt 0 ]; do
esac
done

+KAS_CONTAINER_ENGINE="${KAS_CONTAINER_ENGINE:-${KAS_DOCKER_ENGINE}}"
+if [ -z "${KAS_CONTAINER_ENGINE}" ]; then
+ # Try to auto-detect a container engine
+ if command -v docker >/dev/null 2>&1 && docker -v 2>/dev/null | grep -q '^Docker'; then
+ KAS_CONTAINER_ENGINE=docker
+ elif command -v podman >/dev/null 2>&1; then
+ KAS_CONTAINER_ENGINE=podman
+ else
+ fatal_error "no container engine found, need docker or podman"
+ fi
+fi
+
+KAS_RUNTIME_ARGS="--log-driver=none --user=root"
+
+case "${KAS_CONTAINER_ENGINE}" in
+docker)
+ KAS_CONTAINER_COMMAND="docker"
+ enable_unpriv_userns_docker
+ check_docker_rootless
+ ;;
+podman)
+ KAS_CONTAINER_COMMAND="podman"
+ KAS_RUNTIME_ARGS="${KAS_RUNTIME_ARGS} --security-opt label=disable"
+ ;;
+*)
+ fatal_error "unknown container engine '${KAS_CONTAINER_ENGINE}'"
+ ;;
+esac
+
+KAS_RUNTIME_ARGS="${KAS_RUNTIME_ARGS}${KAS_EXTRA_RUNTIME_ARGS}"
+
[ -n "${KAS_CMD}" ] || usage

KAS_EXTRA_BITBAKE_ARGS=0
--
2.47.3

MOESSBAUER, Felix

unread,
Jun 4, 2026, 4:18:46 AMJun 4
to Kiszka, Jan, kas-devel
On Thu, 2026-06-04 at 08:25 +0200, Jan Kiszka wrote:
> From: Jan Kiszka <jan.k...@siemens.com>
>
> This allows to run "kas-container --help" even in the absence of a
> container engine.

While this fixes the missing container engine case, it still does not
fix the case that other pre-conditions are met (as in the now dropped
commit): We still call parts of the env sanitization and cleanup logic
(kas_container_cleanup) on --help again.

But I guess the remaining cleanup is simple: Just define functions and
variable declarations prior to the arg parsing. Then, call the
functions right after the arg parsing. Note, that this previously was
not possible due to directly calling functions in arg parsing, but we
don't do that anymore (except for --with-loop-dev, but this can be
delayed as well).

Felix

Jan Kiszka

unread,
Jun 7, 2026, 9:12:16 AM (12 days ago) Jun 7
to Moessbauer, Felix (FT RPD CED OES-DE), kas-devel
On 04.06.26 10:18, Moessbauer, Felix (FT RPD CED OES-DE) wrote:
> On Thu, 2026-06-04 at 08:25 +0200, Jan Kiszka wrote:
>> From: Jan Kiszka <jan.k...@siemens.com>
>>
>> This allows to run "kas-container --help" even in the absence of a
>> container engine.
>
> While this fixes the missing container engine case, it still does not
> fix the case that other pre-conditions are met (as in the now dropped
> commit): We still call parts of the env sanitization and cleanup logic
> (kas_container_cleanup) on --help again.
>

We can further improve on top. I'm looking it it, already found further
cleanup potential. E.g.: Calling setup_kas_dirs prior to the parser loop
prio to the parser has enabled logging with swallow the trace calls
during that function.

> But I guess the remaining cleanup is simple: Just define functions and
> variable declarations prior to the arg parsing. Then, call the
> functions right after the arg parsing. Note, that this previously was
> not possible due to directly calling functions in arg parsing, but we
> don't do that anymore (except for --with-loop-dev, but this can be
> delayed as well).

In fact, I would rather like to get rid of the loop dev thing now. That
will simplify the unprivileged build handling, see the other thread. I
guess I will just propose a removal.

Jan

--
Siemens AG, Foundational Technologies
Linux Expert Center
Reply all
Reply to author
Forward
0 new messages