Skip to content

Commit

Permalink
Update setup-container.sh to save build time. (sonic-net#6541)
Browse files Browse the repository at this point in the history
Description of PR
In setup-container.sh, when building the docker container, the step "User configuration" will hang around several minutes probability because of the bug [moby/moby#5419] of docker, and the whole script will cost about 20 minutes. Using useradd can work around this bug, but usermod can't. In this pr, we use useradd instead of usermod to work around this bug, and save the build time. Now, the whole script will take around 6 minutes.

What is the motivation for this PR?
In setup-container.sh, when building the docker container, the step "User configuration" will hang around several minutes probability because of the bug [moby/moby#5419] of docker, and the whole script will cost about 20 minutes. Using useradd can work around this bug, but usermod can't. In this pr, we use useradd instead of usermod to work around this bug, and save the build time. Now, the whole script will take around 6 minutes.

How did you do it?
In step "User configuration", when getent passwd {{ USER_NAME }} returns True, first delete the user and use useradd to add the user.

How did you verify/test it?
Setup container with new script and run test cases.

Signed-off-by: Yutong Zhang <yutongzhang@microsoft.com>
  • Loading branch information
yutongzhang-microsoft authored and ms-junyi committed Oct 28, 2022
1 parent 8e16b20 commit 97a789a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions setup-container.sh
Expand Up @@ -195,9 +195,12 @@ fi
# User configuration
RUN if getent passwd {{ USER_NAME }}; \
then usermod -o -g {{ GROUP_ID }} -u {{ USER_ID }} -m -d /home/{{ USER_NAME }} {{ USER_NAME }}; \
else useradd -o -g {{ GROUP_ID }} -u {{ USER_ID }} -m -d /home/{{ USER_NAME }} -s /bin/bash {{ USER_NAME }}; \
# Usermod will hang when user_id is large (https://github.com/moby/moby/issues/5419), and it can not work around this issue itself.
# So, we first delete the user and use `useradd -l` to work around this issue.
#then usermod -o -g {{ GROUP_ID }} -u {{ USER_ID }} -m -d /home/{{ USER_NAME }} {{ USER_NAME }}; \
then userdel {{ USER_NAME }}; \
fi
RUN useradd -o -l -g {{ GROUP_ID }} -u {{ USER_ID }} -m -d /home/{{ USER_NAME }} -s /bin/bash {{ USER_NAME }};
# Docker configuration
RUN if getent group {{ DGROUP_NAME }}; \
Expand Down

0 comments on commit 97a789a

Please sign in to comment.