From cdf9fd9d3ff0337c6d4a29cd9335422c3574ddc0 Mon Sep 17 00:00:00 2001 From: emrgnt-cmplxty <68796651+emrgnt-cmplxty@users.noreply.github.com> Date: Tue, 1 Oct 2024 07:53:16 -0700 Subject: [PATCH] cleanup cli (#1294) --- py/cli/commands/kg.py | 7 ----- py/cli/commands/server.py | 58 ++++++++++++++++++++++++++++-------- py/cli/utils/docker_utils.py | 8 ++--- 3 files changed, 49 insertions(+), 24 deletions(-) diff --git a/py/cli/commands/kg.py b/py/cli/commands/kg.py index 443e672cd..7c1304a01 100644 --- a/py/cli/commands/kg.py +++ b/py/cli/commands/kg.py @@ -9,13 +9,6 @@ @cli.command() -# TODO - add this once we fully implement project names -# @click.option( -# "--project-name", -# required=True, -# default=os.environ["POSTGRES_PROJECT_NAME"], -# help="Project name to create graph for.", -# ) @click.option( "--collection-id", required=True, diff --git a/py/cli/commands/server.py b/py/cli/commands/server.py index 85fc4e539..96c2fe39c 100644 --- a/py/cli/commands/server.py +++ b/py/cli/commands/server.py @@ -87,14 +87,30 @@ def logs(ctx, run_type_filter, offset, limit): def docker_down(volumes, remove_orphans, project_name): """Bring down the Docker Compose setup and attempt to remove the network if necessary.""" result = bring_down_docker_compose(project_name, volumes, remove_orphans) + remove_r2r_network() if result != 0: click.echo( - "An error occurred while bringing down the Docker Compose setup. Attempting to remove the network..." + f"An error occurred while bringing down the {project_name} Docker Compose setup. Attempting to remove the network..." + ) + else: + click.echo( + f"{project_name} Docker Compose setup has been successfully brought down." + ) + + result = bring_down_docker_compose("r2r_full", volumes, remove_orphans) + + # TODO - Clean up the way we do this r2r-down + click.echo(f"Also attempting to bring down the full deployment") + if result != 0: + click.echo( + f"An error occurred while bringing down the r2r_full Docker Compose setup. Attempting to remove the network..." ) else: - click.echo("Docker Compose setup has been successfully brought down.") + click.echo( + f"r2r_full Docker Compose setup has been successfully brought down." + ) @cli.command() @@ -185,8 +201,9 @@ def generate_report(): is_flag=True, help="Run the full R2R compose? This includes Hatchet and Unstructured.", ) -@click.option("--project-name", default="r2r", help="Project name for Docker") -@click.option("--image", help="Docker image to use") +@click.option( + "--project-name", default="r2r", help="Project name for Docker deployment" +) @click.option( "--config-name", default=None, help="Name of the R2R configuration to use" ) @@ -201,12 +218,7 @@ def generate_report(): default=False, help="Run in debug mode. Only for development.", ) -@click.option( - "--dev", - is_flag=True, - default=False, - help="Run in development mode", -) +@click.option("--image", help="Docker image to use") @click.option( "--image-env", default="prod", @@ -218,15 +230,35 @@ async def serve( docker, full, project_name, - image, config_name, config_path, build, - dev, + image, image_env, ): """Start the R2R server.""" load_dotenv() + click.echo("Spinning up an R2R deployment...") + + click.echo(f"Running on {host}:{port}, with docker={docker}") + + if full: + click.echo( + "Running the full R2R compose which includes `Hatchet` and `Unstructured.io`." + ) + if project_name == "r2r": # overwrite project name if full compose + project_name = "r2r_full" + else: + click.echo("Running the lightweight R2R compose.") + + if config_path and config_name: + raise click.UsageError( + "Both `config-path` and `config-name` were provided. Please provide only one." + ) + if build: + click.echo( + "`build` flag detected. Building Docker image from local repository..." + ) if image and image_env: click.echo( "WARNING: Both `image` and `image_env` were provided. Using `image`." @@ -277,7 +309,7 @@ def image_exists(img): "-t", image, "-f", - f"Dockerfile{'.dev' if dev else ''}", + f"Dockerfile", ".", ], check=True, diff --git a/py/cli/utils/docker_utils.py b/py/cli/utils/docker_utils.py index cc7103bcc..594816125 100644 --- a/py/cli/utils/docker_utils.py +++ b/py/cli/utils/docker_utils.py @@ -26,7 +26,7 @@ def bring_down_docker_compose(project_name, volumes, remove_orphans): docker_command += " down" - click.echo("Bringing down Docker Compose setup...") + click.echo(f"Bringing down {project_name} Docker Compose setup...") return os.system(docker_command) @@ -152,9 +152,11 @@ def run_docker_serve( click.secho("R2R now runs on port 7272 by default!", fg="yellow") click.echo("Pulling Docker images...") + click.echo(f"Calling `{pull_command}`") os.system(pull_command) click.echo("Starting Docker Compose setup...") + click.echo(f"Calling `{up_command}`") os.system(up_command) @@ -239,7 +241,7 @@ def check_set_docker_env_vars(): env_vars = { "POSTGRES_PROJECT_NAME": "r2r", - "POSTGRES_HOST": "localhost", + "POSTGRES_HOST": "postgres", "POSTGRES_PORT": "5432", "POSTGRES_DBNAME": "postgres", "POSTGRES_USER": "postgres", @@ -352,8 +354,6 @@ def build_docker_command( pull_command = f"{base_command} pull" up_command = f"{base_command} up -d" - print("base_command = ", base_command) - return pull_command, up_command