diff --git a/src/pythainer/builders/__init__.py b/src/pythainer/builders/__init__.py index e65bf2e..0c22df3 100644 --- a/src/pythainer/builders/__init__.py +++ b/src/pythainer/builders/__init__.py @@ -8,6 +8,7 @@ """ import os import tempfile +import warnings from pathlib import Path from typing import Dict, List @@ -26,6 +27,7 @@ shell_out, ) +warnings.simplefilter("default", DeprecationWarning) def render_dockerfile_content( package_manager: str, @@ -517,19 +519,26 @@ def remove_group_if_gid_exists(self, gid: str) -> None: def remove_user_if_uid_exists( self, uid: str, - gid: str, + gid: str | None = None, ) -> None: """ - Removes a system user by its UID and GID if it exists within the Docker environment. + Removes a system user by its UID if it exists within the Docker environment. Parameters: uid (str): The user ID to potentially remove. - gid (str): The group ID associated with the user. + gid (str | None): DEPRECATED The group ID associated with the user. """ - self.desc(f"Remove user with uid:gid={uid}:{gid} if it already exists.") + if gid is not None: + warnings.warn( + message="The GID argument is deprecated do not set it", + category=DeprecationWarning, + stacklevel=2, + ) + + self.desc(f"Remove user with uid={uid} if it already exists.") command = ( - f"grep :{uid}:{gid}: /etc/passwd && \\\n" - f" (grep :{uid}:{gid}: /etc/passwd | \\\n" + f"grep :{uid}: /etc/passwd && \\\n" + f" (grep :{uid}: /etc/passwd | \\\n" f" cut -d ':' -f 1 | \\\n" f" xargs userdel --remove) || \\\n" f" true" @@ -547,7 +556,7 @@ def create_user(self, username: str) -> None: self.arg(name="UID") self.arg(name="GID") self.remove_group_if_gid_exists(gid="${GID}") - self.remove_user_if_uid_exists(uid="${UID}", gid="${GID}") + self.remove_user_if_uid_exists(uid="${UID}") self.run(command="groupadd -g ${GID} ${USER_NAME}") self.run( command='adduser --disabled-password --uid $UID --gid $GID --gecos "" ${USER_NAME}'