From 50af5dcedd36640569dd14dccee45057e1aa4222 Mon Sep 17 00:00:00 2001 From: badrogger Date: Wed, 11 Sep 2024 12:49:50 +0000 Subject: [PATCH] Save docker group id --- node_cli/configs/__init__.py | 1 + node_cli/core/docker_config.py | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/node_cli/configs/__init__.py b/node_cli/configs/__init__.py index 36f89004..a4f046af 100644 --- a/node_cli/configs/__init__.py +++ b/node_cli/configs/__init__.py @@ -161,3 +161,4 @@ def _get_env(): TELEGRAF_TEMPLATE_PATH = os.path.join(CONTAINER_CONFIG_PATH, 'telegraf.conf.j2') TELEGRAF_CONFIG_PATH = os.path.join(CONTAINER_CONFIG_PATH, 'telegraf.conf') +NODE_DOCKER_CONFIG_PATH = os.path.join(CONTAINER_CONFIG_PATH, 'docker.json') diff --git a/node_cli/core/docker_config.py b/node_cli/core/docker_config.py index 5b1470c1..d5241be3 100644 --- a/node_cli/core/docker_config.py +++ b/node_cli/core/docker_config.py @@ -1,3 +1,4 @@ +import grp import enum import json import logging @@ -14,7 +15,8 @@ DOCKER_SERVICE_CONFIG_DIR, DOCKER_SERVICE_CONFIG_PATH, DOCKER_SOCKET_PATH, - SKALE_RUN_DIR + NODE_DOCKER_CONFIG_PATH, + SKALE_RUN_DIR, ) from node_cli.utils.helper import run_cmd from node_cli.utils.docker_utils import docker_client, get_containers @@ -26,6 +28,15 @@ Path = typing.Union[str, pathlib.Path] +def get_docker_group_id() -> int: + return grp.getgrnam('docker').gr_gid + + +def save_docker_group_id(group_id: int, path: Optional[Path] = NODE_DOCKER_CONFIG_PATH) -> None: + with open(path, 'w') as node_docker_config: + json.dump({'docker_group_id': group_id}, node_docker_config) + + def get_content(filename: Path) -> Optional[str]: if not os.path.isfile(filename): return None @@ -189,4 +200,8 @@ def configure_docker() -> None: restart_docker_service() wait_for_socket_initialization() + logger.info('Saving docker group id') + group_id = get_docker_group_id() + save_docker_group_id(group_id) + logger.info('Docker configuration finished')