Commit b78f75b4 authored by mohammedabdulwahhab's avatar mohammedabdulwahhab Committed by GitHub
Browse files

fix: Consolidate dynamo start and dynamo serve commands (#405)


Co-authored-by: default avatarmabdulwahhab <mabdulwahhab@nvidia.com>
parent 146f2eef
...@@ -40,7 +40,7 @@ spec: ...@@ -40,7 +40,7 @@ spec:
- name: {{ $.Release.Name }}-{{ .name | lower }} - name: {{ $.Release.Name }}-{{ .name | lower }}
image: {{ $.Values.image }} image: {{ $.Values.image }}
args: args:
- uv run dynamo start --service-name {{ .name }} src.{{ $.Values.dynamoIdentifier }} - uv run dynamo serve --service-name {{ .name }} src.{{ $.Values.dynamoIdentifier }}
command: command:
- sh - sh
- -c - -c
......
...@@ -1784,7 +1784,7 @@ monitoring.options.insecure=true` ...@@ -1784,7 +1784,7 @@ monitoring.options.insecure=true`
args := make([]string, 0) args := make([]string, 0)
args = append(args, "cd", "src", "&&", "uv", "run", "dynamo", "start") args = append(args, "cd", "src", "&&", "uv", "run", "dynamo", "serve")
// todo : remove this line when https://github.com/ai-dynamo/dynamo/issues/345 is fixed // todo : remove this line when https://github.com/ai-dynamo/dynamo/issues/345 is fixed
enableDependsOption := false enableDependsOption := false
......
...@@ -33,13 +33,18 @@ dynamo serve [SERVICE] ...@@ -33,13 +33,18 @@ dynamo serve [SERVICE]
**Flags** **Flags**
- `--file`/`-f` - Path to optional YAML configuration file. An example of the YAML file can be found in the configuration section of the [SDK docs](../sdk/README.md) - `--file`/`-f` - Path to optional YAML configuration file. An example of the YAML file can be found in the configuration section of the [SDK docs](../sdk/README.md)
- `--dry-run` - Print out the dependency graph and values without starting any services. - `--dry-run` - Print out the dependency graph and values without starting any services.
- `--service-name` - Only serve the specified service name. The rest of the discoverable components in the graph are not started.
- `--working-dir` - Specify the directory to find the Service instance - `--working-dir` - Specify the directory to find the Service instance
- Any additional flags that follow Class.key=value will be passed to the service constructor for the target service and parsed. Please see the configuration section of the [SDK docs](../sdk/README.md) for more details. - Any additional flags that follow Class.key=value will be passed to the service constructor for the target service and parsed. Please see the configuration section of the [SDK docs](../sdk/README.md) for more details.
**Example** **Example**
```bash ```bash
cd examples cd examples
# Spin up Frontend, Middle, and Backend components
dynamo serve hello_world:Frontend dynamo serve hello_world:Frontend
# Spin up only the Middle component in the graph that is discoverable from the Frontend service
dynamo serve --service-name Middle hello_world:Frontend
``` ```
## `build` ## `build`
......
...@@ -21,6 +21,7 @@ import logging ...@@ -21,6 +21,7 @@ import logging
import os import os
import sys import sys
import typing as t import typing as t
from typing import Optional
import click import click
import rich import rich
...@@ -171,6 +172,21 @@ def build_serve_command() -> click.Group: ...@@ -171,6 +172,21 @@ def build_serve_command() -> click.Group:
cls=AliasCommand, cls=AliasCommand,
) )
@click.argument("bento", type=click.STRING, default=".") @click.argument("bento", type=click.STRING, default=".")
@click.option(
"--service-name",
type=click.STRING,
required=False,
default="",
envvar="BENTOML_SERVE_SERVICE_NAME",
help="Only serve the specified service. Don't serve any dependencies of this service.",
)
@click.option(
"--depends",
type=click.STRING,
multiple=True,
envvar="BENTOML_SERVE_DEPENDS",
help="list of runners map",
)
@click.option( @click.option(
"-f", "-f",
"--file", "--file",
...@@ -320,6 +336,8 @@ def build_serve_command() -> click.Group: ...@@ -320,6 +336,8 @@ def build_serve_command() -> click.Group:
def serve( def serve(
ctx: click.Context, ctx: click.Context,
bento: str, bento: str,
service_name: str,
depends: Optional[list[str]],
dry_run: bool, dry_run: bool,
development: bool, development: bool,
port: int, port: int,
...@@ -404,6 +422,12 @@ def build_serve_command() -> click.Group: ...@@ -404,6 +422,12 @@ def build_serve_command() -> click.Group:
service_configs[service] = {} service_configs[service] = {}
service_configs[service][key] = value service_configs[service][key] = value
# Process depends
if depends:
runner_map_dict = dict([s.split("=", maxsplit=2) for s in depends or []])
else:
runner_map_dict = {}
if dry_run: if dry_run:
rich.print("[bold]Service Configuration:[/bold]") rich.print("[bold]Service Configuration:[/bold]")
rich.print(json.dumps(service_configs, indent=2)) rich.print(json.dumps(service_configs, indent=2))
...@@ -495,6 +519,8 @@ def build_serve_command() -> click.Group: ...@@ -495,6 +519,8 @@ def build_serve_command() -> click.Group:
reload=reload, reload=reload,
timeout_keep_alive=timeout_keep_alive, timeout_keep_alive=timeout_keep_alive,
timeout_graceful_shutdown=timeout_graceful_shutdown, timeout_graceful_shutdown=timeout_graceful_shutdown,
dependency_map=runner_map_dict,
service_name=service_name,
) )
return cli return cli
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment