Skip to content

Commit 4b9c310

Browse files
authored
Merge pull request #425 from mbaldessari/fix-uid
Fixes and cleanups
2 parents 4ea84d1 + b86f13b commit 4b9c310

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

scripts/pattern-util.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
#!/bin/bash
2+
function is_available {
3+
command -v $1 >/dev/null 2>&1 || { echo >&2 "$1 is required but it's not installed. Aborting."; exit 1; }
4+
}
25

36
if [ -z "$PATTERN_UTILITY_CONTAINER" ]; then
47
PATTERN_UTILITY_CONTAINER="quay.io/hybridcloudpatterns/utility-container"
58
fi
69

10+
readonly commands=(podman)
11+
for cmd in ${commands[@]}; do is_available "$cmd"; done
12+
713
UNSUPPORTED_PODMAN_VERSIONS="1.6 1.5"
814
for i in ${UNSUPPORTED_PODMAN_VERSIONS}; do
915
# We add a space
@@ -25,15 +31,17 @@ fi
2531
# $HOME is mounted as itself for any files that are referenced with absolute paths
2632
# $HOME is mounted to /root because the UID in the container is 0 and that's where SSH looks for credentials
2733

28-
# Do not quote the ${KUBECONF_ENV} below, otherwise we will pass '' to podman
29-
# which will be confused
34+
# We do not rely on bash's $UID and $GID because on MacOSX $GID is not set
35+
MYUID=$(id -u)
36+
MYGID=$(id -g)
3037
podman run -it --rm --pull=newer \
3138
--security-opt label=disable \
39+
--user "${MYUID}:${MYGID}" \
40+
--userns "keep-id:uid=${MYUID},gid=${MYGID}" \
3241
-e EXTRA_HELM_OPTS \
3342
-e KUBECONFIG \
3443
-v "${HOME}":"${HOME}" \
3544
-v "${HOME}":/pattern-home \
36-
-v "${HOME}":/root \
3745
-w "$(pwd)" \
3846
"$PATTERN_UTILITY_CONTAINER" \
3947
$@

0 commit comments

Comments
 (0)