Skip to content

Commit

Permalink
fix: Clean up entrypoint.sh and fix potential issues (#1613)
Browse files Browse the repository at this point in the history
Backported-from: main
Backported-to: 23.03
  • Loading branch information
achimnol committed Oct 13, 2023
1 parent 90b6595 commit a69fccf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes/1613.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clean up `entrypoint.sh` (our custom container entrypoint), including fixes to avoid non-mandatory recursive file operations on `/home/work`
19 changes: 14 additions & 5 deletions src/ai/backend/runner/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ if [ -z "$LOCAL_USER_ID" ]; then
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."
fi

# NOTE: /home/work may have vfolder bind-mounts containing a LOT of files (e.g., more than 10K!).
# Therefore, we must AVOID any filesystem operation applied RECURSIVELY to /home/work,
# to prevent indefinite "hangs" during a container startup.

if [ $USER_ID -eq 0 ]; then

echo "WARNING: Running the user codes as root is not recommended."
if [ -f /bin/ash ]; then # for alpine
export SHELL=/bin/ash
else
else # for other distros (ubuntu, centos, etc.)
export SHELL=/bin/bash
echo "$LD_PRELOAD" | tr ':' '\n' > /etc/ld.so.preload
unset LD_PRELOAD
Expand Down Expand Up @@ -68,7 +72,7 @@ else
usermod -aG shadow $USER_NAME
fi
export SHELL=/bin/ash
else
else # for other distros (ubuntu, centos, etc.)
echo "$LD_PRELOAD" | tr ':' '\n' > /etc/ld.so.preload
unset LD_PRELOAD
if [ -z "$GROUP_NAME" ]; then
Expand All @@ -80,11 +84,16 @@ else
useradd -s /bin/bash -d "/home/$USER_NAME" -M -r -u $USER_ID -g $GROUP_NAME -o -c "User" $USER_NAME
usermod -aG shadow $USER_NAME
else
cp -R "/home/$USER_NAME/*" /home/work/
cp -R "/home/$USER_NAME/.*" /home/work/
# The image has an existing user name for the given uid.
# Merge the image's existing home directory into the bind-mounted "/home/work" from the scratch space.
# NOTE: Since the image layer and the scratch directory may reside in different filesystems,
# we cannot use hard-links to reduce the copy overhead.
# It assumes that the number/size of files in the image's home directory is not very large.
cp -Rp "/home/$USER_NAME/*" /home/work/
cp -Rp "/home/$USER_NAME/.*" /home/work/
# Rename the user to "work" and let it use "/home/work" as the new home directory.
usermod -s /bin/bash -d /home/work -l work -g $GROUP_NAME $USER_NAME
USER_NAME=work
chown -R $USER_NAME:$GROUP_NAME /home/work
usermod -aG shadow $USER_NAME
fi
export SHELL=/bin/bash
Expand Down

0 comments on commit a69fccf

Please sign in to comment.