Skip to content

Commit

Permalink
Merge pull request #263 from bogdant36/CTX-6321-i
Browse files Browse the repository at this point in the history
CTX-6321: Implementation of coretex node --version command.
  • Loading branch information
igorperic17 authored Sep 4, 2024
2 parents 35f94bf + 842bde6 commit 0101428
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion coretex/cli/commands/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from typing import Optional
from pathlib import Path

import click

Expand Down Expand Up @@ -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 = "Node %(version)s")
def node() -> None:
pass

Expand Down
31 changes: 31 additions & 0 deletions coretex/cli/modules/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,37 @@ def shouldUpdate(image: str) -> bool:
return True


def getNodeVersion() -> str:
if not isRunning():
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
else:
image = docker.getContainerImageName(config_defaults.DOCKER_CONTAINER_NAME)

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)

Expand Down

0 comments on commit 0101428

Please sign in to comment.