Skip to content

Commit

Permalink
Merge pull request #1058 from langchain-ai/nc/18jul/cli-dockerfile
Browse files Browse the repository at this point in the history
cli: Add dockerfile command to write dockerfile
  • Loading branch information
nfcampos authored Jul 18, 2024
2 parents 97ae473 + ffe9a6d commit 87e80fe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
15 changes: 15 additions & 0 deletions libs/cli/langgraph_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,21 @@ def build(
_build(runner, set, config, config_json, platform, base_image, pull, tag)


@OPT_CONFIG
@click.argument("save_path", type=click.Path(resolve_path=True))
@cli.command(help="Generate a Dockerfile for langgraph API server")
@log_command
def dockerfile(save_path: pathlib.Path, config: pathlib.Path):
with open(config) as f:
config_json = langgraph_cli.config.validate_config(json.load(f))
with open(save_path, "w") as f:
f.write(
langgraph_cli.config.config_to_docker(
config, config_json, "langchain/langgraph-api"
)
)


def prepare_args_and_stdin(
*,
capabilities: DockerCapabilities,
Expand Down
26 changes: 15 additions & 11 deletions libs/cli/langgraph_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,28 +232,32 @@ def config_to_docker(config_path: pathlib.Path, config: Config, base_image: str)
'[tool.setuptools.package-data]' \\
'"*" = ["**/*"]'; do \\
echo "$line" >> /deps/__outer_{fullpath.name}/pyproject.toml; \\
done
"""
done"""
for fullpath, (relpath, destpath) in local_deps.faux_pkgs.items()
)
local_pkgs_str = os.linesep.join(
f"ADD {relpath} /deps/{fullpath.name}"
for fullpath, relpath in local_deps.real_pkgs.items()
)

installs = f"{os.linesep}{os.linesep}".join(
filter(
None,
[
pip_config_file_str,
pip_pkgs_str,
pip_reqs_str,
local_pkgs_str,
faux_pkgs_str,
],
)
)

return f"""FROM {base_image}:{config['python_version']}
{os.linesep.join(config["dockerfile_lines"])}
{pip_config_file_str}
{pip_pkgs_str}
{pip_reqs_str}
{local_pkgs_str}
{faux_pkgs_str}
{installs}
RUN {pip_install} -e /deps/*
Expand Down
8 changes: 5 additions & 3 deletions libs/cli/tests/unit_tests/test_config.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"python_version": "3.12",
"pip_config_file": "pipconfig.txt",
"dockerfile_lines": ["ARG meow"],
"dockerfile_lines": [
"ARG meow"
],
"dependencies": [
"langchain_openai",
"."
],
"graphs": {
"agent": "tests/unit_tests/agent.py:graph"
"agent": "graphs/agent.py:graph"
},
"env": ".env"
}
}

0 comments on commit 87e80fe

Please sign in to comment.