Skip to content

Commit 4a1aefc

Browse files
wangxinmssonicbld
authored andcommitted
Improve setup-container.sh for Ubuntu 24.04 based docker-sonic-mgmt (#20761)
To support docker-sonic-mgmt based on Ubuntu 24.04, the setup-container.sh needs some minor improvements: 1. The Ubuntu 24.04 docker image as account "ubuntu" by default. Its uid could conflict with the user's uid. This change added code to best effort deleting this default "ubuntu" account. 2. In old docker-sonic-mgmt, python3 is installed in virtual environment. In 2024, the docker-sonic-mgmt was updated to install python3 in global environment. It's no longer necessary to hack the virtual environment. This change adjusted the sequence of conditions for hacking venv, so that the code can fail faster to skip this step. In the future, this piece of code should can be deleted. Signed-off-by: Xin Wang <xiwang5@microsoft.com>
1 parent 79737b1 commit 4a1aefc

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

setup-container.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ FROM {{ IMAGE_ID }}
189189
190190
USER root
191191
192+
# Remove possible default ubuntu user of Ubuntu 24.04
193+
RUN if getent passwd ubuntu; \
194+
then userdel -r ubuntu; \
195+
fi
196+
192197
# Group configuration
193198
RUN if getent group {{ GROUP_NAME }}; \
194199
then groupmod -o -g {{ GROUP_ID }} {{ GROUP_NAME }}; \
@@ -250,9 +255,11 @@ WORKDIR ${HOME}
250255
# 2. The user is not AzDevOps. By default python3 virtual env is installed for AzDevOps user.
251256
# No need to install it again when current user is AzDevOps.
252257
# 3. The python3 virtual env is not installed for AzDevOps. Then, it is not required for other users either.
253-
RUN if ! pip3 list | grep -c pytest >/dev/null && \
254-
[ '{{ USER_NAME }}' != 'AzDevOps' ] && \
255-
[ -d /var/AzDevOps/env-python3 ]; then \
258+
# As of 2025, python3 is installed globally in the docker-sonic-mgmt image. So, this step is not really required.
259+
# Adjust the conditions to fail faster to skip this step.
260+
RUN if [ -d /var/AzDevOps/env-python3 ] \
261+
&& [ '{{ USER_NAME }}' != 'AzDevOps' ] \
262+
&& ! pip3 list | grep -c pytest >/dev/null; then \
256263
/bin/bash -c 'python3 -m venv ${HOME}/env-python3'; \
257264
/bin/bash -c '${HOME}/env-python3/bin/pip install pip --upgrade'; \
258265
/bin/bash -c '${HOME}/env-python3/bin/pip install wheel'; \

0 commit comments

Comments
 (0)