Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTX-6321: Implementation of coretex node --version command. #263

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
igorperic17 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading