Skip to content
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 invenio_cli/cli/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def setup(cli_config, force, no_demo_data, stop_services, services):
def status(ctx, verbose):
"""Checks if the services are up and running.

NOTE: currently only search, DB (postgresql/mysql) and redis are supported.
NOTE: currently only search (opensearch2), DB (postgresql) and redis are supported.
"""
ctx.invoke(services_status_cmd, verbose=verbose)

Expand Down
2 changes: 1 addition & 1 deletion invenio_cli/cli/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def setup(cli_config, force, no_demo_data, stop_services, services):
def status(cli_config, verbose):
"""Checks if the services are up and running.

NOTE: currently only search (OS/ES), DB (postgresql/mysql) and redis are supported.
NOTE: currently only search (opensearch2), DB (postgresql) and redis are supported.
"""
commands = ServicesCommands(cli_config)
services = ["redis", cli_config.get_db_type(), "search"]
Expand Down
27 changes: 11 additions & 16 deletions invenio_cli/helpers/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-FileCopyrightText: 2019-2020 Northwestern University.
# SPDX-FileCopyrightText: 2021 Esteban J. G. Gabancho.
# SPDX-FileCopyrightText: 2024 Graz University of Technology.
# SPDX-FileCopyrightText: 2025-2026 KTH Royal Institute of Technology.
# SPDX-License-Identifier: MIT

"""Invenio-cli configuration file."""
Expand Down Expand Up @@ -95,7 +96,7 @@ def javascript_package_manager(self) -> JavascriptPackageManager:
elif manager_name == PNPM.name:
return PNPM()

return NPM()
return PNPM()

def get_project_dir(self):
"""Returns path to project directory."""
Expand Down Expand Up @@ -166,23 +167,12 @@ def get_web_host(self):
return self.private_config[CLIConfig.CLI_SECTION].get("web_host", "127.0.0.1")

def get_db_type(self):
"""Returns the database type (mysql, postgresql)."""
return self.config[CLIConfig.COOKIECUTTER_SECTION]["database"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't lose anything by keeping this for now right? By keeping this logic that reads it from the file and the one below that writes it to the file, we keep backwards compatibility. This will reduce the corner cases for now.

@Samk13 Samk13 Jun 15, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since database and search are no longer cookiecutter inputs, keeping the current implementation would fail when those keys are missing, so we'd need to get them with fallback values (postgresql/opensearch2) anyway.

Could you give an example of a backwards-compatibility scenario where we'd want to preserve a value other than PostgreSQL/OpenSearch2, given that the generated stack is now fixed to those services for invenioRDM?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here (before) "database" would be retrieved from the config file, so if we don't retrieve it from there and serve postgresql/opensearch2 directly this may contradict what someone had in that config file, right 🤔 ? Or did we change something else along the way? The context being someone using invenio-cli with an instance cookiecutted a couple version back.

I do see we are using get_db_type / get_search_type to fuel the writing now but not before, eh? I'll follow-up tomorrow 😄

@Samk13 Samk13 Jun 15, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this now anyway to keep compatibility and keep everyone happy.

The getters still read existing .invenio values, with fallbacks for new configs where cookiecutter no longer provides them.

The values in write() are hardcoded because it is a classmethod creating the config file, so there is no self/CLIConfig instance to read config from yet.

I will squash all commits once we agree.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I think that's the way to go for this transition. At a later time we can remove even more.

"""Returns the database type."""
return self.config[CLIConfig.COOKIECUTTER_SECTION].get("database", "postgresql")

def get_search_type(self):
"""Returns the search type (opensearch1, elasticsearch7)."""
sections = self.config[CLIConfig.COOKIECUTTER_SECTION]
if "elasticsearch" in sections:
# cookiecutter < v10
version = sections["elasticsearch"]
return f"elasticsearch{version}"
elif "search" in sections:
# cookiecutter >= v10
return sections["search"]
else:
raise InvenioCLIConfigError(
"`search` or `elasticsearch` field not set in .invenio file"
)
"""Returns the search type."""
return self.config[CLIConfig.COOKIECUTTER_SECTION].get("search", "opensearch2")

def get_file_storage(self):
"""Returns the file storage (local, s3, etc.)."""
Expand Down Expand Up @@ -223,11 +213,16 @@ def write(cls, project_dir, flavour, replay):
config_parser[cls.CLI_SECTION] = {}
config_parser[cls.CLI_SECTION]["flavour"] = flavour
config_parser[cls.CLI_SECTION]["logfile"] = "/logs/invenio-cli.log"
config_parser[cls.CLI_SECTION]["javascript_package_manager"] = PNPM.name

# Cookiecutter user input section
config_parser[cls.COOKIECUTTER_SECTION] = {}
for key, value in replay[cls.COOKIECUTTER_SECTION].items():
config_parser[cls.COOKIECUTTER_SECTION][key] = str(value)
# Keep compatibility with older tooling that expects `database` and `search` to exist.
# Backend choice has been removed; PostgreSQL and OpenSearch2 are fixed.
config_parser[cls.COOKIECUTTER_SECTION]["database"] = "postgresql"
config_parser[cls.COOKIECUTTER_SECTION]["search"] = "opensearch2"

# Generated files section
config_parser[cls.FILES_SECTION] = get_created_files(project_dir)
Expand Down
35 changes: 31 additions & 4 deletions tests/helpers/test_cli_config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# SPDX-FileCopyrightText: 2019-2020 CERN.
# SPDX-FileCopyrightText: 2019-2021 Northwestern University.
# SPDX-FileCopyrightText: 2025-2026 KTH Royal Institute of Technology.
# SPDX-License-Identifier: MIT

"""Module config_file tests."""

import os
import tempfile
from configparser import ConfigParser
from pathlib import Path

import pytest
Expand All @@ -29,8 +31,6 @@ def test_cli_config_write():
"author_name": "CERN",
"author_email": "info@my-site.com",
"year": "2022",
"database": "postgresql",
"search": "opensearch1",
"_template": "https://github.com/inveniosoftware/cookiecutter-invenio-rdm.git", # noqa
}
}
Expand Down Expand Up @@ -62,8 +62,6 @@ def config_dir():
"author_name": "CERN",
"author_email": "info@my-site.com",
"year": "2022",
"database": "postgresql",
"search": "opensearch1",
"_template": "https://github.com/inveniosoftware/cookiecutter-invenio-rdm.git", # noqa
}
}
Expand Down Expand Up @@ -116,3 +114,32 @@ def test_cli_config_get_project_shortname(config_dir):
cli_config = CLIConfig(config_dir)

assert cli_config.get_project_shortname() == "my-site"


def test_package_manager_and_service_defaults(tmpdir):
"""Test package manager, database, and search defaults in CLI config."""
project_dir = tmpdir.mkdir("test-project")
flavour = "RDM"
replay = {
"cookiecutter": {
"project_name": "My Site",
"project_shortname": "my-site",
"project_site": "my-site.com",
"github_repo": "my-site/my-site",
"description": "Invenio RDM My Site Instance",
"author_name": "CERN",
"author_email": "info@my-site.com",
"year": "2022",
"_template": "https://github.com/inveniosoftware/cookiecutter-invenio-rdm.git", # noqa
}
}
CLIConfig.write(str(project_dir), flavour, replay)

config = ConfigParser()
config_path = project_dir.join(CLIConfig.CONFIG_FILENAME)
config.read(str(config_path))

assert config.has_option(CLIConfig.CLI_SECTION, "javascript_package_manager")
assert config.get(CLIConfig.CLI_SECTION, "javascript_package_manager") == "pnpm"
assert config.get(CLIConfig.COOKIECUTTER_SECTION, "database") == "postgresql"
assert config.get(CLIConfig.COOKIECUTTER_SECTION, "search") == "opensearch2"