Skip to content

Commit a69fccf

Browse files
committed
fix: Clean up entrypoint.sh and fix potential issues (#1613)
Backported-from: main Backported-to: 23.03
1 parent 90b6595 commit a69fccf

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

changes/1613.fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clean up `entrypoint.sh` (our custom container entrypoint), including fixes to avoid non-mandatory recursive file operations on `/home/work`

src/ai/backend/runner/entrypoint.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ if [ -z "$LOCAL_USER_ID" ]; then
1212
echo "WARNING: \$LOCAL_USER_ID is an empty value. This may be a misbehavior of plugins manipulating the evironment variables of new containers and cause unexpected errors."
1313
fi
1414

15+
# NOTE: /home/work may have vfolder bind-mounts containing a LOT of files (e.g., more than 10K!).
16+
# Therefore, we must AVOID any filesystem operation applied RECURSIVELY to /home/work,
17+
# to prevent indefinite "hangs" during a container startup.
18+
1519
if [ $USER_ID -eq 0 ]; then
1620

1721
echo "WARNING: Running the user codes as root is not recommended."
1822
if [ -f /bin/ash ]; then # for alpine
1923
export SHELL=/bin/ash
20-
else
24+
else # for other distros (ubuntu, centos, etc.)
2125
export SHELL=/bin/bash
2226
echo "$LD_PRELOAD" | tr ':' '\n' > /etc/ld.so.preload
2327
unset LD_PRELOAD
@@ -68,7 +72,7 @@ else
6872
usermod -aG shadow $USER_NAME
6973
fi
7074
export SHELL=/bin/ash
71-
else
75+
else # for other distros (ubuntu, centos, etc.)
7276
echo "$LD_PRELOAD" | tr ':' '\n' > /etc/ld.so.preload
7377
unset LD_PRELOAD
7478
if [ -z "$GROUP_NAME" ]; then
@@ -80,11 +84,16 @@ else
8084
useradd -s /bin/bash -d "/home/$USER_NAME" -M -r -u $USER_ID -g $GROUP_NAME -o -c "User" $USER_NAME
8185
usermod -aG shadow $USER_NAME
8286
else
83-
cp -R "/home/$USER_NAME/*" /home/work/
84-
cp -R "/home/$USER_NAME/.*" /home/work/
87+
# The image has an existing user name for the given uid.
88+
# Merge the image's existing home directory into the bind-mounted "/home/work" from the scratch space.
89+
# NOTE: Since the image layer and the scratch directory may reside in different filesystems,
90+
# we cannot use hard-links to reduce the copy overhead.
91+
# It assumes that the number/size of files in the image's home directory is not very large.
92+
cp -Rp "/home/$USER_NAME/*" /home/work/
93+
cp -Rp "/home/$USER_NAME/.*" /home/work/
94+
# Rename the user to "work" and let it use "/home/work" as the new home directory.
8595
usermod -s /bin/bash -d /home/work -l work -g $GROUP_NAME $USER_NAME
8696
USER_NAME=work
87-
chown -R $USER_NAME:$GROUP_NAME /home/work
8897
usermod -aG shadow $USER_NAME
8998
fi
9099
export SHELL=/bin/bash

0 commit comments

Comments
 (0)