Skip to content

Commit fa03170

Browse files
committed
Detect and run commands directly when already in a container
1 parent 85fad00 commit fa03170

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

scripts/pattern-util.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@ function version {
88
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
99
}
1010

11+
function is_running_in_container {
12+
# Check if we're running inside a podman container
13+
# Podman creates /run/.containerenv in all containers (rootful and rootless)
14+
if [ -f /run/.containerenv ]; then
15+
return 0
16+
fi
17+
# Use systemd-detect-virt if available to detect container environment
18+
if command -v systemd-detect-virt >/dev/null 2>&1; then
19+
if systemd-detect-virt --container >/dev/null 2>&1; then
20+
return 0
21+
fi
22+
fi
23+
return 1
24+
}
25+
26+
# If already running in a container, execute the command directly
27+
if is_running_in_container; then
28+
echo "Detected running inside a container, executing command directly..."
29+
exec "$@"
30+
fi
31+
1132
if [ -z "$PATTERN_UTILITY_CONTAINER" ]; then
1233
PATTERN_UTILITY_CONTAINER="quay.io/validatedpatterns/utility-container"
1334
fi

0 commit comments

Comments
 (0)