Skip to content

Commit

Permalink
Merge pull request #783 from skalenetwork/beta
Browse files Browse the repository at this point in the history
2.4.1 stable
  • Loading branch information
DmytroNazarenko authored Sep 18, 2024
2 parents 3cb3578 + 5df2f0b commit 45c62fc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion node_cli/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '2.4.0'
__version__ = '2.4.1'

if __name__ == "__main__":
print(__version__)
1 change: 1 addition & 0 deletions node_cli/configs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(NODE_DATA_PATH, 'docker.json')
17 changes: 16 additions & 1 deletion node_cli/core/docker_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import grp
import enum
import json
import logging
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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')
3 changes: 3 additions & 0 deletions node_cli/operations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ def turn_off():

def turn_on(env):
logger.info('Turning on the node...')
if env.get('SKIP_DOCKER_CONFIG') != 'True':
configure_docker()
logger.info('Launching containers on the node...')
compose_up(env)


Expand Down
11 changes: 10 additions & 1 deletion tests/core/host/docker_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
from contextlib import contextmanager
from timeit import default_timer as timer
from node_cli.core.docker_config import get_docker_group_id, save_docker_group_id

import pytest

Expand All @@ -17,7 +18,8 @@
ensure_service_overriden_config,
OverridenConfigExsitsError,
SocketInitTimeoutError,
wait_for_socket_initialization
wait_for_socket_initialization,
NODE_DOCKER_CONFIG_PATH,
)


Expand Down Expand Up @@ -151,3 +153,10 @@ def test_wait_for_socket_initialization(tmp_dir):
pathlib.Path(socket_path).touch()
with in_time(1):
wait_for_socket_initialization(socket_path)


def test_get_save_group_id():
gid = get_docker_group_id()
save_docker_group_id(gid)
with open(NODE_DOCKER_CONFIG_PATH) as config_path:
assert json.load(config_path)['docker_group_id'] == gid

0 comments on commit 45c62fc

Please sign in to comment.