Skip to content

Commit

Permalink
cleanup cli (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
emrgnt-cmplxty authored Oct 1, 2024
1 parent 090fa12 commit cdf9fd9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 24 deletions.
7 changes: 0 additions & 7 deletions py/cli/commands/kg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
58 changes: 45 additions & 13 deletions py/cli/commands/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"
)
Expand All @@ -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",
Expand All @@ -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`."
Expand Down Expand Up @@ -277,7 +309,7 @@ def image_exists(img):
"-t",
image,
"-f",
f"Dockerfile{'.dev' if dev else ''}",
f"Dockerfile",
".",
],
check=True,
Expand Down
8 changes: 4 additions & 4 deletions py/cli/utils/docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit cdf9fd9

Please sign in to comment.