feat: requirements file search

This commit is contained in:
2025-12-01 22:12:49 +03:00
parent 1071561708
commit 70fe4cd5c8
+17 -7
View File
@@ -1,10 +1,9 @@
import docker
from ctypes.wintypes import tagSIZE
client = docker.from_env()
running_containers = []
sleeping_containers = []
for c in client.containers.list(all=True):
# sleeping_containers = []
for c in client.containers.list():
info = c.attrs # словарь со всеми данными
image = info["Config"]["Image"] # образ
created = info["Created"] # время создания
@@ -12,9 +11,21 @@ for c in client.containers.list(all=True):
ports = info["NetworkSettings"]["Ports"] # проброшенные порты ЪЪЪ
mounts = info.get("Mounts", []) # маунты
status = c.status # статус контейнера (вкл-выкл)
tags = c.image.tags
ver = c.image.tags[0].split(':')[-1] # версия
workdir = info["Config"].get("WorkingDir") or '/' # рабочая директория
find_cmd = (
f"sh -c \"cd {workdir} 2>/dev/null && "
"find . -maxdepth 3 \\( "
"-name 'requirements*.txt' -o "
"-name 'Pipfile' -o "
"-name 'pyproject.toml' -o "
"-name 'package.json' "
"\\) 2>/dev/null | head -n 5\""
)
req = c.exec_run(find_cmd)[1].decode() # путь до файла с зависимостями
container = {
"name": c.name,
"version": ver,
"image": image,
"id": c.id[:12],
"create_time": created,
@@ -23,6 +34,5 @@ for c in client.containers.list(all=True):
}
if status == "running":
running_containers.append(container)
else:
sleeping_containers.append(container)
print(tags)
# else:
# sleeping_containers.append(container)