reworked service mapping
This commit is contained in:
@@ -12,26 +12,30 @@ def manage_containers(project: str, services: list[str]):
|
||||
def wrapper(*args, **kwargs):
|
||||
client = docker.from_env()
|
||||
|
||||
containers: list[Container] = [
|
||||
try:
|
||||
project_containers = (
|
||||
c
|
||||
for c in client.containers.list()
|
||||
if c.labels['com.docker.compose.project'] == project
|
||||
and c.labels['com.docker.compose.service'] in services
|
||||
]
|
||||
try:
|
||||
)
|
||||
service_dict = {
|
||||
c.labels['com.docker.compose.service']: c for c in project_containers
|
||||
}
|
||||
containers: list[Container] = [service_dict[s] for s in services]
|
||||
except Exception as e:
|
||||
raise e
|
||||
else:
|
||||
# Start the containers
|
||||
for container in containers:
|
||||
container.stop()
|
||||
logger.info(f'Stopped container [blue]{container.name}[/]')
|
||||
|
||||
try:
|
||||
# Execute the wrapped function
|
||||
result = func(*args, **kwargs)
|
||||
|
||||
return func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
# Handle exceptions and ensure containers are stopped
|
||||
raise e
|
||||
else:
|
||||
return result
|
||||
finally:
|
||||
# Stop the containers
|
||||
for container in containers:
|
||||
|
||||
Reference in New Issue
Block a user