File size: 3,053 Bytes
e2812ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

"""Serve OpenEnv environments locally (TO BE IMPLEMENTED)."""

from __future__ import annotations

from pathlib import Path
from typing import Annotated, Optional

import typer

from .._cli_utils import console

# Commands are registered in __main__.py

def serve(

    env_path: Annotated[

        Optional[str],

        typer.Argument(

            help="Path to the environment directory (default: current directory)"

        ),

    ] = None,

    port: Annotated[

        int,

        typer.Option("--port", help="Port to serve on"),

    ] = 8000,

    host: Annotated[

        str,

        typer.Option("--host", help="Host to bind to"),

    ] = "0.0.0.0",

    reload: Annotated[

        bool,

        typer.Option("--reload", help="Enable auto-reload on code changes"),

    ] = False,

) -> None:
    """

    Serve an OpenEnv environment locally.



    TODO: This command is currently not implemented and has been deferred for later.



    Planned functionality:

    - Run environment server locally without Docker

    - Support multiple deployment modes (local, notebook, cluster)

    - Auto-reload for development

    - Integration with environment's [project.scripts] entry point



    For now, use Docker-based serving:

        1. Build the environment: openenv build

        2. Run the container: docker run -p 8000:8000 <image-name>



    Or use uv directly:

        uv run --project . server --port 8000

    """
    console.print("[bold yellow]⚠ This command is not yet implemented[/bold yellow]\n")

    console.print(
        "The [bold cyan]openenv serve[/bold cyan] command has been deferred for later."
    )

    console.print("[bold]Alternative approaches:[/bold]\n")

    console.print("[cyan]Option 1: Docker-based serving (recommended)[/cyan]")
    console.print("  1. Build the environment:")
    console.print("     [dim]$ openenv build[/dim]")
    console.print("  2. Run the Docker container:")
    console.print(
        f"     [dim]$ docker run -p {port}:{port} openenv-<env-name>:latest[/dim]\n"
    )

    console.print("[cyan]Option 2: Direct execution with uv[/cyan]")

    # Determine environment path
    if env_path is None:
        env_path_obj = Path.cwd()
    else:
        env_path_obj = Path(env_path)

    # Check for openenv.yaml
    openenv_yaml = env_path_obj / "openenv.yaml"
    if openenv_yaml.exists():
        console.print("  From your environment directory:")
        console.print(f"     [dim]$ cd {env_path_obj}[/dim]")
        console.print(f"     [dim]$ uv run --project . server --port {port}[/dim]\n")
    else:
        console.print("  From an environment directory with pyproject.toml:")
        console.print(f"     [dim]$ uv run --project . server --port {port}[/dim]\n")

    raise typer.Exit(0)