Skip to content

Commit

Permalink
Added a date class to store container IDs for the inline handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
orenlab committed Jun 22, 2024
1 parent 2dd678b commit 43090b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 12 additions & 0 deletions app/core/adapters/containers_base_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from dataclasses import dataclass


@dataclass
class ContainerData:
"""
Data class to store container id.
Attributes:
container_id (str): The ID of the container.
"""
container_id: list = None
12 changes: 8 additions & 4 deletions app/core/adapters/docker_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from humanize import naturalsize, naturaltime

from app import config
from app.core.adapters.containers_base_data import ContainerData
from app.core.logs import bot_logger


Expand Down Expand Up @@ -112,9 +113,7 @@ def _naturaltime(timestamp: datetime) -> str:

def __list_containers(self) -> List[str]:
"""
List all docker containers.
This function retrieves a list of all running containers and returns their image tags.
List all docker containers and retrieve their image tags.
Returns:
List[str]: A list of image tags of all running containers.
Expand All @@ -127,10 +126,15 @@ def __list_containers(self) -> List[str]:
# Create a Docker client instance
client = self.__create_docker_client()

# Retrieve a list of all running containers and extract the image tags
# Retrieve a list of all running containers
containers_raw = client.containers.list(all=True)

# Extract the image tags
image_tags = [container.short_id for container in containers_raw]

# Store the image tags in the ContainerData class
ContainerData.container_id = image_tags

# Log the created container list
bot_logger.debug(f"Container list created: {image_tags}")

Expand Down

0 comments on commit 43090b8

Please sign in to comment.