diff --git a/invenio_cli/cli/services.py b/invenio_cli/cli/services.py index 722615fa..a3f7cb68 100644 --- a/invenio_cli/cli/services.py +++ b/invenio_cli/cli/services.py @@ -10,6 +10,7 @@ import click from ..commands import ServicesCommands +from ..helpers.docker_helper import NoOpDockerHelper from .utils import pass_cli_config, run_steps @@ -61,7 +62,14 @@ def setup(cli_config, force, no_demo_data, stop_services, services): """Setup local services.""" # no_demo_data = False (default) means "YES to demo_data" demo_data = not no_demo_data - commands = ServicesCommands(cli_config) + if services: + # use the default docker helper + docker_helper = None + else: + # create a no-op docker helper as services are disabled + docker_helper = NoOpDockerHelper() + + commands = ServicesCommands(cli_config, docker_helper=docker_helper) steps = commands.setup(force, demo_data, stop_services, services) on_fail = "Failed to setup services." on_success = "Successfully setup all services." diff --git a/invenio_cli/helpers/docker_helper.py b/invenio_cli/helpers/docker_helper.py index 31932df3..319461c1 100644 --- a/invenio_cli/helpers/docker_helper.py +++ b/invenio_cli/helpers/docker_helper.py @@ -137,3 +137,30 @@ def execute_cli_command(self, project_shortname, command): output="Web UI container not found. Is it up and running?", status_code=1, ) + + +class NoOpDockerHelper: + """A no-op implementation of DockerHelper that does nothing. + + It is used when services can not be started with docker (e.g. in CI/CD environments) + and has the same interface as DockerHelper. + """ + + def build_images(self, pull=False, cache=True): + """Build images action. Not implemented in NoOpDockerHelper.""" + raise NotImplementedError("Build images is not implemented in NoOpDockerHelper") + + def start_containers(self, app_only=False): + """Start containers according to the specified environment. + + :param app_only: Boot up only ui and api containers. + """ + return ProcessResponse() + + def stop_containers(self): + """Stop currently running containers.""" + return ProcessResponse() + + def destroy_containers(self): + """Stop and remove all containers, volumes and images.""" + return ProcessResponse()