Skip to content

Commit 399a382

Browse files
committed
feat: add the fn to check if the script is already running in a container
This is needed for CI runs, where we do not want container in container
1 parent 3a9c184 commit 399a382

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/internal/embedded/resources/pattern.sh

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

12+
# We need this check mostly for CI testing, we do not want to run container in container
13+
function is_container() {
14+
[ -n "${KUBERNETES_SERVICE_HOST:-}" ] && return 0
15+
[ -f /.dockerenv ] && return 0
16+
[ -f /run/.containerenv ] && return 0
17+
return 1
18+
}
19+
20+
if is_container; then
21+
echo "Already running in a container"
22+
exec "$@"
23+
fi
24+
1225
if [ -z "${PATTERN_UTILITY_CONTAINER:-}" ]; then
1326
PATTERN_UTILITY_CONTAINER="quay.io/validatedpatterns/utility-container"
1427
fi

0 commit comments

Comments
 (0)