Skip to content

Commit d1662f3

Browse files
committed
chore: fixup setup.sh
Signed-off-by: Maryam Tahhan <mtahhan@redhat.com>
1 parent 8994bbe commit d1662f3

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

.devcontainer/setup.sh

+13-6
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,34 @@ declare -a files=(
1212
"$SCRIPT_DIR/triton-cpu/devcontainer.json"
1313
)
1414

15-
# Get the current user's UID and GID
1615
UID_VAL=$(id -u)
1716
GID_VAL=$(id -g)
17+
USERNAME=$(id -un)
18+
19+
is_podman() {
20+
command -v podman &> /dev/null && podman info &> /dev/null
21+
}
1822

19-
# Function to detect NVIDIA CDI
2023
is_nvidia_cdi_available() {
2124
if command -v nvidia-ctk &> /dev/null && nvidia-ctk cdi list | grep -q "nvidia.com/gpu=all"; then
2225
return 0
2326
fi
2427
return 1
2528
}
2629

27-
# Update devcontainer.json with the correct UID and GID
2830
for var in "${files[@]}"; do
2931
if [ -f "$var" ]; then
30-
sed -i "s/\"--userns=keep-id:uid=[0-9]\+,gid=[0-9]\+\"/\"--userns=keep-id:uid=$UID_VAL,gid=$GID_VAL\"/" "$var"
32+
if is_podman; then
33+
sed -i "s/\"--userns=keep-id:uid=[0-9]\+,gid=[0-9]\+\"/\"--userns=keep-id:uid=$UID_VAL,gid=$GID_VAL\"/" "$var"
34+
fi
3135

32-
# Update devcontainer.json with the correct gpu flags if CDI is available
3336
if is_nvidia_cdi_available; then
3437
sed -i "/--runtime=nvidia/d" "$var"
35-
sed -i "s/\"--gpus all\"/\"--device nvidia.com/gpu=all\"/" "$var"
38+
sed -i "s|\"--gpus all\"|\"--device\",\n \"nvidia.com/gpu=all\"|" "$var"
39+
sed -i "/\"gpu\": \"optional\"/d" "$var"
3640
fi
41+
42+
sed -i "s/\"remoteUser\": \"\${localEnv:USER}\"/\"remoteUser\": \"$USERNAME\"/g" "$var"
43+
sed -i "s/\"containerUser\": \"\${localEnv:USER}\"/\"containerUser\": \"$USERNAME\"/g" "$var"
3744
fi
3845
done

0 commit comments

Comments
 (0)