diff --git a/invenio_cli/cli/containers.py b/invenio_cli/cli/containers.py index 54b9c379..cc3a3b4e 100644 --- a/invenio_cli/cli/containers.py +++ b/invenio_cli/cli/containers.py @@ -104,7 +104,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) diff --git a/invenio_cli/cli/services.py b/invenio_cli/cli/services.py index 722615fa..5796f2b2 100644 --- a/invenio_cli/cli/services.py +++ b/invenio_cli/cli/services.py @@ -82,7 +82,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"] diff --git a/invenio_cli/helpers/cli_config.py b/invenio_cli/helpers/cli_config.py index 7373abd3..9d6aef61 100644 --- a/invenio_cli/helpers/cli_config.py +++ b/invenio_cli/helpers/cli_config.py @@ -4,6 +4,7 @@ # Copyright (C) 2019-2020 Northwestern University. # Copyright (C) 2021 Esteban J. G. Gabancho. # Copyright (C) 2024 Graz University of Technology. +# Copyright (C) 2025-2026 KTH Royal Institute of Technology. # # Invenio-Cli is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -99,7 +100,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.""" @@ -169,24 +170,15 @@ def get_web_host(self): """Returns web host.""" 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"] - - 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" - ) + @staticmethod + def get_db_type(): + """Returns the database type.""" + return "postgresql" + + @staticmethod + def get_search_type(): + """Returns the search type.""" + return "opensearch2" def get_file_storage(self): """Returns the file storage (local, s3, etc.).""" @@ -227,11 +219,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`,`search`to exist. + # Database,Search backend choice has been removed and postgresql, opensearch2 is fixed. + config_parser[cls.COOKIECUTTER_SECTION]["database"] = cls.get_db_type() + config_parser[cls.COOKIECUTTER_SECTION]["search"] = cls.get_search_type() # Generated files section config_parser[cls.FILES_SECTION] = get_created_files(project_dir) diff --git a/tests/helpers/test_cli_config.py b/tests/helpers/test_cli_config.py index a3a29a5a..ada7ab6e 100644 --- a/tests/helpers/test_cli_config.py +++ b/tests/helpers/test_cli_config.py @@ -2,6 +2,7 @@ # # Copyright (C) 2019-2020 CERN. # Copyright (C) 2019-2021 Northwestern University. +# Copyright (C) 2025-2026 KTH Royal Institute of Technology. # # Invenio-Cli is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -10,6 +11,7 @@ import os import tempfile +from configparser import ConfigParser from pathlib import Path import pytest @@ -33,8 +35,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 } } @@ -66,8 +66,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 } } @@ -120,3 +118,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"