Skip to content

Commit 874df6d

Browse files
authored
feat(deployment): Add --setup-only flag to start-clp.sh to set up the package without starting components (resolves #1475). (#1502)
1 parent 2ac456e commit 874df6d

File tree

4 files changed

+96
-76
lines changed

4 files changed

+96
-76
lines changed

components/clp-package-utils/clp_package_utils/controller.py

Lines changed: 75 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,22 @@ def __init__(self, clp_config: CLPConfig) -> None:
8787
self._conf_dir = self._clp_home / "etc"
8888

8989
@abstractmethod
90-
def start(self) -> None:
90+
def set_up_env(self) -> None:
9191
"""
92-
Starts the components.
92+
Sets up all components to run by preparing environment variables, directories, and
93+
configuration files.
9394
"""
9495

9596
@abstractmethod
96-
def stop(self) -> None:
97+
def start(self) -> None:
9798
"""
98-
Stops the components.
99+
Starts the components.
99100
"""
100101

101102
@abstractmethod
102-
def _set_up_env(self) -> None:
103+
def stop(self) -> None:
103104
"""
104-
Sets up all components to run by preparing environment variables, directories, and
105-
configuration files.
105+
Stops the components.
106106
"""
107107

108108
def _set_up_env_for_database(self) -> EnvVarsDict:
@@ -642,75 +642,7 @@ def __init__(self, clp_config: CLPConfig, instance_id: str) -> None:
642642
self._project_name = f"clp-package-{instance_id}"
643643
super().__init__(clp_config)
644644

645-
def start(self) -> None:
646-
"""
647-
Starts CLP's components using Docker Compose.
648-
649-
:raise: Propagates `check_docker_dependencies`'s exceptions.
650-
:raise: Propagates `subprocess.run`'s exceptions.
651-
"""
652-
check_docker_dependencies(
653-
should_compose_project_be_running=False, project_name=self._project_name
654-
)
655-
self._set_up_env()
656-
657-
deployment_type = self._clp_config.get_deployment_type()
658-
logger.info(f"Starting CLP using Docker Compose ({deployment_type} deployment)...")
659-
660-
cmd = ["docker", "compose", "--project-name", self._project_name]
661-
if deployment_type == DeploymentType.BASE:
662-
cmd += ["--file", "docker-compose.base.yaml"]
663-
if self._clp_config.mcp_server is not None:
664-
cmd += ["--profile", "mcp"]
665-
cmd += ["up", "--detach", "--wait"]
666-
subprocess.run(
667-
cmd,
668-
cwd=self._clp_home,
669-
check=True,
670-
)
671-
logger.info("Started CLP.")
672-
673-
def stop(self) -> None:
674-
"""
675-
Stops CLP components deployed via Docker Compose.
676-
677-
:raise: Propagates `subprocess.run`'s exceptions.
678-
"""
679-
try:
680-
check_docker_dependencies(
681-
should_compose_project_be_running=True, project_name=self._project_name
682-
)
683-
except DockerComposeProjectNotRunningError:
684-
logger.info(
685-
"Docker Compose project '%s' is not running. Nothing to stop.",
686-
self._project_name,
687-
)
688-
return
689-
except DockerDependencyError as e:
690-
logger.warning(
691-
'Docker dependencies check failed: "%s". Attempting to stop CLP containers '
692-
"anyway...",
693-
e,
694-
)
695-
else:
696-
logger.info("Stopping all CLP containers using Docker Compose...")
697-
698-
subprocess.run(
699-
["docker", "compose", "--project-name", self._project_name, "down"],
700-
cwd=self._clp_home,
701-
check=True,
702-
)
703-
logger.info("Stopped CLP.")
704-
705-
@staticmethod
706-
def _get_num_workers() -> int:
707-
"""
708-
:return: Number of worker processes to run.
709-
"""
710-
# This will change when we move from single to multi-container workers. See y-scope/clp#1424
711-
return multiprocessing.cpu_count() // 2
712-
713-
def _set_up_env(self) -> None:
645+
def set_up_env(self) -> None:
714646
# Generate container-specific config.
715647
container_clp_config = generate_docker_compose_container_config(self._clp_config)
716648
num_workers = self._get_num_workers()
@@ -796,6 +728,73 @@ def _set_up_env(self) -> None:
796728
continue
797729
env_file.write(f"{key}={value}\n")
798730

731+
def start(self) -> None:
732+
"""
733+
Starts CLP's components using Docker Compose.
734+
735+
:raise: Propagates `check_docker_dependencies`'s exceptions.
736+
:raise: Propagates `subprocess.run`'s exceptions.
737+
"""
738+
check_docker_dependencies(
739+
should_compose_project_be_running=False, project_name=self._project_name
740+
)
741+
742+
deployment_type = self._clp_config.get_deployment_type()
743+
logger.info(f"Starting CLP using Docker Compose ({deployment_type} deployment)...")
744+
745+
cmd = ["docker", "compose", "--project-name", self._project_name]
746+
if deployment_type == DeploymentType.BASE:
747+
cmd += ["--file", "docker-compose.base.yaml"]
748+
if self._clp_config.mcp_server is not None:
749+
cmd += ["--profile", "mcp"]
750+
cmd += ["up", "--detach", "--wait"]
751+
subprocess.run(
752+
cmd,
753+
cwd=self._clp_home,
754+
check=True,
755+
)
756+
logger.info("Started CLP.")
757+
758+
def stop(self) -> None:
759+
"""
760+
Stops CLP components deployed via Docker Compose.
761+
762+
:raise: Propagates `subprocess.run`'s exceptions.
763+
"""
764+
try:
765+
check_docker_dependencies(
766+
should_compose_project_be_running=True, project_name=self._project_name
767+
)
768+
except DockerComposeProjectNotRunningError:
769+
logger.info(
770+
"Docker Compose project '%s' is not running. Nothing to stop.",
771+
self._project_name,
772+
)
773+
return
774+
except DockerDependencyError as e:
775+
logger.warning(
776+
'Docker dependencies check failed: "%s". Attempting to stop CLP containers '
777+
"anyway...",
778+
e,
779+
)
780+
else:
781+
logger.info("Stopping all CLP containers using Docker Compose...")
782+
783+
subprocess.run(
784+
["docker", "compose", "--project-name", self._project_name, "down"],
785+
cwd=self._clp_home,
786+
check=True,
787+
)
788+
logger.info("Stopped CLP.")
789+
790+
@staticmethod
791+
def _get_num_workers() -> int:
792+
"""
793+
:return: Number of worker processes to run.
794+
"""
795+
# This will change when we move from single to multi-container workers. See y-scope/clp#1424
796+
return multiprocessing.cpu_count() // 2
797+
799798

800799
def get_or_create_instance_id(clp_config: CLPConfig) -> str:
801800
"""

components/clp-package-utils/clp_package_utils/scripts/start_clp.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ def main(argv):
3737
action="store_true",
3838
help="Enable debug logging.",
3939
)
40+
args_parser.add_argument(
41+
"--setup-only",
42+
action="store_true",
43+
help="Validate configuration and prepare directories without starting services.",
44+
)
4045

4146
parsed_args = args_parser.parse_args(argv[1:])
4247

@@ -79,6 +84,12 @@ def main(argv):
7984
try:
8085
instance_id = get_or_create_instance_id(clp_config)
8186
controller = DockerComposeController(clp_config, instance_id)
87+
controller.set_up_env()
88+
if parsed_args.setup_only:
89+
logger.info(
90+
"Completed setup. Services not started because `--setup-only` was specified."
91+
)
92+
return 0
8293
controller.start()
8394
except Exception as ex:
8495
if type(ex) == ValueError:

docs/src/user-docs/quick-start/clp-json.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ To start CLP, run:
1717
sbin/start-clp.sh
1818
```
1919

20+
:::{tip}
21+
To validate configuration and prepare directories without launching services, add the
22+
`--setup-only` flag (e.g., `sbin/start-clp.sh --setup-only`).
23+
:::
24+
2025
:::{note}
2126
If CLP fails to start (e.g., due to a port conflict), try adjusting the settings in
2227
`etc/clp-config.yml` and then run the start command again.

docs/src/user-docs/quick-start/clp-text.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ To start CLP, run:
1919
sbin/start-clp.sh
2020
```
2121

22+
:::{tip}
23+
To validate configuration and prepare directories without launching services, add the
24+
`--setup-only` flag (e.g., `sbin/start-clp.sh --setup-only`).
25+
:::
26+
2227
:::{note}
2328
If CLP fails to start (e.g., due to a port conflict), try adjusting the settings in
2429
`etc/clp-config.yml` and then run the start command again.

0 commit comments

Comments
 (0)