Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/pythainer/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""
import os
import tempfile
import warnings
from pathlib import Path
from typing import Dict, List

Expand All @@ -26,6 +27,7 @@
shell_out,
)

warnings.simplefilter("default", DeprecationWarning)

def render_dockerfile_content(
package_manager: str,
Expand Down Expand Up @@ -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"
Expand All @@ -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}'
Expand Down