Skip to content

Commit ed8046a

Browse files
authored
LDR: selectable local mounts (#12092)
1 parent 186ecf0 commit ed8046a

File tree

3 files changed

+51
-14
lines changed

3 files changed

+51
-14
lines changed

localstack-core/localstack/dev/run/__main__.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
PortConfigurator,
2828
SourceVolumeMountConfigurator,
2929
)
30-
from .paths import HostPaths
30+
from .paths import HOST_PATH_MAPPINGS, HostPaths
3131

3232

3333
@click.command("run")
@@ -114,6 +114,14 @@
114114
required=False,
115115
help="Docker network to start the container in",
116116
)
117+
@click.option(
118+
"--local-packages",
119+
"-l",
120+
multiple=True,
121+
required=False,
122+
type=click.Choice(HOST_PATH_MAPPINGS.keys(), case_sensitive=False),
123+
help="Mount specified packages into the container",
124+
)
117125
@click.argument("command", nargs=-1, required=False)
118126
def run(
119127
image: str = None,
@@ -130,6 +138,7 @@ def run(
130138
publish: Tuple = (),
131139
entrypoint: str = None,
132140
network: str = None,
141+
local_packages: list[str] | None = None,
133142
command: str = None,
134143
):
135144
"""
@@ -214,6 +223,16 @@ def run(
214223
│ ├── tests
215224
│ └── ...
216225
226+
You can choose which local source repositories are mounted in. For example, if `moto` and `rolo` are
227+
both present, only mount `rolo` into the container.
228+
229+
\b
230+
python -m localstack.dev.run --local-packages rolo
231+
232+
If both `rolo` and `moto` are available and both should be mounted, use the flag twice.
233+
234+
\b
235+
python -m localstack.dev.run --local-packages rolo --local-packages moto
217236
"""
218237
with console.status("Configuring") as status:
219238
env_vars = parse_env_vars(env)
@@ -288,6 +307,7 @@ def run(
288307
SourceVolumeMountConfigurator(
289308
host_paths=host_paths,
290309
pro=pro,
310+
chosen_packages=local_packages,
291311
)
292312
)
293313
if mount_entrypoints:

localstack-core/localstack/dev/run/configurators.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020
from localstack.utils.run import run
2121
from localstack.utils.strings import md5
2222

23-
from .paths import CommunityContainerPaths, ContainerPaths, HostPaths, ProContainerPaths
23+
from .paths import (
24+
HOST_PATH_MAPPINGS,
25+
CommunityContainerPaths,
26+
ContainerPaths,
27+
HostPaths,
28+
ProContainerPaths,
29+
)
2430

2531

2632
class ConfigEnvironmentConfigurator:
@@ -117,10 +123,12 @@ def __init__(
117123
*,
118124
host_paths: HostPaths = None,
119125
pro: bool = False,
126+
chosen_packages: list[str] | None = None,
120127
):
121128
self.host_paths = host_paths or HostPaths()
122129
self.container_paths = ProContainerPaths() if pro else CommunityContainerPaths()
123130
self.pro = pro
131+
self.chosen_packages = chosen_packages or []
124132

125133
def __call__(self, cfg: ContainerConfiguration):
126134
# localstack source code if available
@@ -142,17 +150,11 @@ def __call__(self, cfg: ContainerConfiguration):
142150
)
143151
)
144152

145-
# moto code if available
146-
self.try_mount_to_site_packages(cfg, self.host_paths.moto_project_dir / "moto")
147-
148-
# postgresql-proxy code if available
149-
self.try_mount_to_site_packages(cfg, self.host_paths.postgresql_proxy / "postgresql_proxy")
150-
151-
# rolo code if available
152-
self.try_mount_to_site_packages(cfg, self.host_paths.rolo_dir / "rolo")
153-
154-
# plux
155-
self.try_mount_to_site_packages(cfg, self.host_paths.workspace_dir / "plux" / "plugin")
153+
# mount local code checkouts if possible
154+
for package_name in self.chosen_packages:
155+
# Unconditional lookup because the CLI rejects incorect items
156+
extractor = HOST_PATH_MAPPINGS[package_name]
157+
self.try_mount_to_site_packages(cfg, extractor(self.host_paths))
156158

157159
# docker entrypoint
158160
if self.pro:

localstack-core/localstack/dev/run/paths.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44
from pathlib import Path
5-
from typing import Optional, Union
5+
from typing import Callable, Optional, Union
66

77

88
class HostPaths:
@@ -49,6 +49,21 @@ def aws_pro_package_dir(self) -> Path:
4949
)
5050

5151

52+
# Type representing how to extract a specific path from a common root path, typically a lambda function
53+
PathMappingExtractor = Callable[[HostPaths], Path]
54+
55+
# Declaration of which local packages can be mounted into the container, and their locations on the host
56+
HOST_PATH_MAPPINGS: dict[
57+
str,
58+
PathMappingExtractor,
59+
] = {
60+
"moto": lambda paths: paths.moto_project_dir / "moto",
61+
"postgresql_proxy": lambda paths: paths.postgresql_proxy / "postgresql_proxy",
62+
"rolo": lambda paths: paths.rolo_dir / "rolo",
63+
"plux": lambda paths: paths.workspace_dir / "plux" / "plugin",
64+
}
65+
66+
5267
class ContainerPaths:
5368
"""Important paths in the container"""
5469

0 commit comments

Comments
 (0)