From b23c47cd9c5eacadb22227305150fde1ca7c1f02 Mon Sep 17 00:00:00 2001 From: Bogdan Tintor Date: Mon, 2 Sep 2024 10:01:18 +0200 Subject: [PATCH 1/3] CTX-6321: Implementation of coretex node --version command regarding new changes that we made to our Docker image (storing "version" property of image in Config["Labels"] dictionary). --- coretex/cli/commands/node.py | 2 +- coretex/cli/modules/node.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/coretex/cli/commands/node.py b/coretex/cli/commands/node.py index 98dfd63b..eb0204c0 100644 --- a/coretex/cli/commands/node.py +++ b/coretex/cli/commands/node.py @@ -16,7 +16,6 @@ # along with this program. If not, see . from typing import Optional -from pathlib import Path import click @@ -210,6 +209,7 @@ def logs(tail: Optional[int], follow: bool, timestamps: bool) -> None: @onBeforeCommandExecute(initializeUserSession) @onBeforeCommandExecute(node_module.checkResourceLimitations, excludeSubcommands = ["status"]) @onBeforeCommandExecute(checkEnvironment) +@click.version_option(node_module.getNodeVersion(), "--version", "-v", message = "Coretex %(version)s") def node() -> None: pass diff --git a/coretex/cli/modules/node.py b/coretex/cli/modules/node.py index 80696556..6fe7608d 100644 --- a/coretex/cli/modules/node.py +++ b/coretex/cli/modules/node.py @@ -200,6 +200,35 @@ def shouldUpdate(image: str) -> bool: return True +def getNodeVersion(image: Optional[str] = None) -> str: + if image is None: + try: + nodeConfig = NodeConfiguration.load() + image = nodeConfig.image + except ConfigurationNotFound: + ui.errorEcho("Node configuration not found.") + raise + except InvalidConfiguration as ex: + for error in ex.errors: + ui.errorEcho(error) + raise + + try: + imageJson = docker.imageInspect(image) + except CommandException: + return "Unknown" + + imageConfig = imageJson.get("Config") + if not isinstance(imageConfig, dict): + return "Unknown" + + labels = imageConfig.get("Labels") + if not isinstance(labels, dict): + return "Unknown" + + return str(labels.get("version", "Unknown")) + + def showLogs(tail: Optional[int], follow: bool, timestamps: bool) -> None: docker.getLogs(config_defaults.DOCKER_CONTAINER_NAME, tail, follow, timestamps) From fac0d7cc7e642b37f167d9bd40a99b8383309124 Mon Sep 17 00:00:00 2001 From: Bogdan Tintor Date: Mon, 2 Sep 2024 10:02:03 +0200 Subject: [PATCH 2/3] CTX-6321: Version of Node not Coretex correction. --- coretex/cli/commands/node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coretex/cli/commands/node.py b/coretex/cli/commands/node.py index eb0204c0..2f58d917 100644 --- a/coretex/cli/commands/node.py +++ b/coretex/cli/commands/node.py @@ -209,7 +209,7 @@ def logs(tail: Optional[int], follow: bool, timestamps: bool) -> None: @onBeforeCommandExecute(initializeUserSession) @onBeforeCommandExecute(node_module.checkResourceLimitations, excludeSubcommands = ["status"]) @onBeforeCommandExecute(checkEnvironment) -@click.version_option(node_module.getNodeVersion(), "--version", "-v", message = "Coretex %(version)s") +@click.version_option(node_module.getNodeVersion(), "--version", "-v", message = "Node %(version)s") def node() -> None: pass From 842bde6fc6f98eab7f14f35a25e3ab4063096e16 Mon Sep 17 00:00:00 2001 From: Bogdan Tintor Date: Tue, 3 Sep 2024 16:39:43 +0200 Subject: [PATCH 3/3] CTX-6321: Updated as discussed. --- coretex/cli/modules/node.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/coretex/cli/modules/node.py b/coretex/cli/modules/node.py index 6fe7608d..adc61d7b 100644 --- a/coretex/cli/modules/node.py +++ b/coretex/cli/modules/node.py @@ -200,8 +200,8 @@ def shouldUpdate(image: str) -> bool: return True -def getNodeVersion(image: Optional[str] = None) -> str: - if image is None: +def getNodeVersion() -> str: + if not isRunning(): try: nodeConfig = NodeConfiguration.load() image = nodeConfig.image @@ -212,6 +212,8 @@ def getNodeVersion(image: Optional[str] = None) -> str: for error in ex.errors: ui.errorEcho(error) raise + else: + image = docker.getContainerImageName(config_defaults.DOCKER_CONTAINER_NAME) try: imageJson = docker.imageInspect(image)