mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-22 23:52:23 +02:00
🐛 [CLI] Generate one --build-context argument for each dependency in the docker build command. (#4962)
* Generate one `--build-context` for each dependency in the `docker build` command. * Try and fix test --------- Co-authored-by: Nuno Campos <nuno@langchain.dev>
This commit is contained in:
co-authored by
Nuno Campos
parent
aedf974dfd
commit
1a76f6a92a
@@ -318,10 +318,8 @@ def _build(
|
||||
)
|
||||
# add additional_contexts
|
||||
if additional_contexts:
|
||||
additional_contexts_str = ",".join(
|
||||
f"{k}={v}" for k, v in additional_contexts.items()
|
||||
)
|
||||
args.extend(["--build-context", additional_contexts_str])
|
||||
for k, v in additional_contexts.items():
|
||||
args.extend(["--build-context", f"{k}={v}"])
|
||||
# run docker build
|
||||
runner.run(
|
||||
subp_exec(
|
||||
|
||||
@@ -22,12 +22,14 @@ DEFAULT_DOCKER_CAPABILITIES = DockerCapabilities(
|
||||
|
||||
|
||||
@contextmanager
|
||||
def temporary_config_folder(config_content: dict):
|
||||
def temporary_config_folder(config_content: dict, levels: int = 0):
|
||||
# Create a temporary directory
|
||||
temp_dir = tempfile.mkdtemp()
|
||||
try:
|
||||
# Define the path for the config.json file
|
||||
config_path = Path(temp_dir) / "config.json"
|
||||
config_path = Path(temp_dir) / f"{'a/' * levels}config.json"
|
||||
# Ensure the parent directory exists
|
||||
config_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Write the provided dictionary content to config.json
|
||||
with open(config_path, "w", encoding="utf-8") as config_file:
|
||||
@@ -532,3 +534,38 @@ def test_build_command_shows_wolfi_warning() -> None:
|
||||
assert "Wolfi Linux" in result.output
|
||||
assert "image_distro" in result.output
|
||||
assert "wolfi" in result.output
|
||||
|
||||
|
||||
def test_build_generate_proper_build_context():
|
||||
runner = CliRunner()
|
||||
config_content = {
|
||||
"python_version": "3.11",
|
||||
"graphs": {"agent": "agent.py:graph"},
|
||||
"dependencies": [".", "../../..", "../.."],
|
||||
"image_distro": "wolfi",
|
||||
}
|
||||
|
||||
with temporary_config_folder(config_content, levels=3) as temp_dir:
|
||||
agent_path = temp_dir / "agent.py"
|
||||
agent_path.touch()
|
||||
|
||||
# Mock docker command since we don't want to actually build
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(
|
||||
cli,
|
||||
[
|
||||
"build",
|
||||
"--tag",
|
||||
"test-image",
|
||||
"--config",
|
||||
str(temp_dir / "config.json"),
|
||||
],
|
||||
catch_exceptions=True,
|
||||
)
|
||||
|
||||
build_context_pattern = re.compile(r"--build-context\s+(\w+)=([^\s]+)")
|
||||
|
||||
build_contexts = re.findall(build_context_pattern, result.output)
|
||||
assert (
|
||||
len(build_contexts) == 2
|
||||
), f"Expected 2 build contexts, but found {len(build_contexts)}"
|
||||
|
||||
Reference in New Issue
Block a user