Переглянути джерело

Adding hosting v1 support (#4309)


Co-authored-by: simon <simon@reflex.dev>
Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
Simon Young 6 місяців тому
батько
коміт
e457d53924
3 змінених файлів з 142 додано та 8 видалено
  1. 7 7
      poetry.lock
  2. 1 1
      pyproject.toml
  3. 134 0
      reflex/reflex.py

+ 7 - 7
poetry.lock

@@ -54,13 +54,13 @@ trio = ["trio (>=0.26.1)"]
 
 [[package]]
 name = "async-timeout"
-version = "5.0.0"
+version = "5.0.1"
 description = "Timeout context manager for asyncio programs"
 optional = false
 python-versions = ">=3.8"
 files = [
-    {file = "async_timeout-5.0.0-py3-none-any.whl", hash = "sha256:904719a4bd6e0520047d0ddae220aabee67b877f7ca17bf8cea20f67f6247ae0"},
-    {file = "async_timeout-5.0.0.tar.gz", hash = "sha256:49675ec889daacfe65ff66d2dde7dd1447a6f4b2f23721022e4ba121f8772a85"},
+    {file = "async_timeout-5.0.1-py3-none-any.whl", hash = "sha256:39e3809566ff85354557ec2398b55e096c8364bacac9405a7a1fa429e77fe76c"},
+    {file = "async_timeout-5.0.1.tar.gz", hash = "sha256:d9321a7a3d5a6a5e187e824d2fa0793ce379a202935782d555d6e9d2735677d3"},
 ]
 
 [[package]]
@@ -2198,13 +2198,13 @@ reflex = ">=0.6.0a"
 
 [[package]]
 name = "reflex-hosting-cli"
-version = "0.1.13"
+version = "0.1.14"
 description = "Reflex Hosting CLI"
 optional = false
 python-versions = "<4.0,>=3.8"
 files = [
-    {file = "reflex_hosting_cli-0.1.13-py3-none-any.whl", hash = "sha256:5bfec7f3d7ce4bbd703989f086494e586a641ef37c9e60e60fb82bdfb07ff227"},
-    {file = "reflex_hosting_cli-0.1.13.tar.gz", hash = "sha256:c5d6afdcfeb74cee046a374ddbd59116ab8ed797dae688fcc744dabae24dc571"},
+    {file = "reflex_hosting_cli-0.1.14-py3-none-any.whl", hash = "sha256:b38676a39708511801bd666e5a9788d8eb4aeb6f9196bea77a8c4c6a6c06492f"},
+    {file = "reflex_hosting_cli-0.1.14.tar.gz", hash = "sha256:8c7721b87dd2ce22db110d905ee01e78e5185f0e6dd521752f70aef6cf17b39f"},
 ]
 
 [package.dependencies]
@@ -3050,4 +3050,4 @@ type = ["pytest-mypy"]
 [metadata]
 lock-version = "2.0"
 python-versions = "^3.9"
-content-hash = "664c8d3c78923d39d1d59227cb43416228ac396a7004344c058377886421c086"
+content-hash = "fe91a9b22081a48be519ed3789e40904bd358a05fd6da912566592aa8d382f31"

+ 1 - 1
pyproject.toml

@@ -49,7 +49,7 @@ wrapt = [
     {version = ">=1.11.0,<2.0", python = "<3.11"},
 ]
 packaging = ">=23.1,<25.0"
-reflex-hosting-cli = ">=0.1.2,<2.0"
+reflex-hosting-cli = ">=0.1.4,<2.0"
 charset-normalizer = ">=3.3.2,<4.0"
 wheel = ">=0.42.0,<1.0"
 build = ">=1.0.3,<2.0"

+ 134 - 0
reflex/reflex.py

@@ -11,6 +11,7 @@ import typer
 import typer.core
 from reflex_cli.deployments import deployments_cli
 from reflex_cli.utils import dependency
+from reflex_cli.v2.deployments import hosting_cli
 
 from reflex import constants
 from reflex.config import environment, get_config
@@ -383,6 +384,14 @@ def login(
     _login()
 
 
+@cli.command()
+def loginv2(loglevel: constants.LogLevel = typer.Option(config.loglevel)):
+    """Authenicate with experimental Reflex hosting service."""
+    from reflex_cli.v2 import cli as hosting_cli
+
+    hosting_cli.login()
+
+
 @cli.command()
 def logout(
     loglevel: constants.LogLevel = typer.Option(
@@ -399,6 +408,22 @@ def logout(
     hosting.delete_token_from_config(include_invitation_code=True)
 
 
+@cli.command()
+def logoutv2(
+    loglevel: constants.LogLevel = typer.Option(
+        config.loglevel, help="The log level to use."
+    ),
+):
+    """Log out of access to Reflex hosting service."""
+    from reflex_cli.v2.utils import hosting
+
+    console.set_log_level(loglevel)
+
+    hosting.log_out_on_browser()
+    console.debug("Deleting access token from config locally")
+    hosting.delete_token_from_config(include_invitation_code=True)
+
+
 db_cli = typer.Typer()
 script_cli = typer.Typer()
 
@@ -599,6 +624,110 @@ def deploy(
     )
 
 
+@cli.command()
+def deployv2(
+    app_name: str = typer.Option(
+        config.app_name,
+        "--app-name",
+        help="The name of the App to deploy under.",
+        hidden=True,
+    ),
+    regions: List[str] = typer.Option(
+        list(),
+        "-r",
+        "--region",
+        help="The regions to deploy to. For multiple envs, repeat this option, e.g. --region sjc --region iad",
+    ),
+    envs: List[str] = typer.Option(
+        list(),
+        "--env",
+        help="The environment variables to set: <key>=<value>. For multiple envs, repeat this option, e.g. --env k1=v2 --env k2=v2.",
+    ),
+    vmtype: Optional[str] = typer.Option(
+        None,
+        "--vmtype",
+        help="Vm type id. Run reflex apps vmtypes list to get options.",
+    ),
+    hostname: Optional[str] = typer.Option(
+        None,
+        "--hostname",
+        help="The hostname of the frontend.",
+        hidden=True,
+    ),
+    interactive: bool = typer.Option(
+        True,
+        help="Whether to list configuration options and ask for confirmation.",
+    ),
+    envfile: Optional[str] = typer.Option(
+        None,
+        "--envfile",
+        help="The path to an env file to use. Will override any envs set manually.",
+        hidden=True,
+    ),
+    loglevel: constants.LogLevel = typer.Option(
+        config.loglevel, help="The log level to use."
+    ),
+    project: Optional[str] = typer.Option(
+        None,
+        "--project",
+        help="project to deploy to",
+        hidden=True,
+    ),
+    token: Optional[str] = typer.Option(
+        None,
+        "--token",
+        help="token to use for auth",
+        hidden=True,
+    ),
+):
+    """Deploy the app to the Reflex hosting service."""
+    from reflex_cli.v2 import cli as hosting_cli
+    from reflex_cli.v2.utils import dependency
+
+    from reflex.utils import export as export_utils
+    from reflex.utils import prerequisites
+
+    # Set the log level.
+    console.set_log_level(loglevel)
+
+    # Only check requirements if interactive.
+    # There is user interaction for requirements update.
+    if interactive:
+        dependency.check_requirements()
+
+    # Check if we are set up.
+    if prerequisites.needs_reinit(frontend=True):
+        _init(name=config.app_name, loglevel=loglevel)
+    prerequisites.check_latest_package_version(constants.ReflexHostingCLI.MODULE_NAME)
+
+    hosting_cli.deploy(
+        app_name=app_name,
+        export_fn=lambda zip_dest_dir,
+        api_url,
+        deploy_url,
+        frontend,
+        backend,
+        zipping: export_utils.export(
+            zip_dest_dir=zip_dest_dir,
+            api_url=api_url,
+            deploy_url=deploy_url,
+            frontend=frontend,
+            backend=backend,
+            zipping=zipping,
+            loglevel=loglevel.subprocess_level(),
+        ),
+        regions=regions,
+        envs=envs,
+        vmtype=vmtype,
+        envfile=envfile,
+        hostname=hostname,
+        interactive=interactive,
+        loglevel=loglevel.subprocess_level(),
+        token=token,
+        project=project,
+    )
+
+
 cli.add_typer(db_cli, name="db", help="Subcommands for managing the database schema.")
 cli.add_typer(script_cli, name="script", help="Subcommands running helper scripts.")
 cli.add_typer(
@@ -606,6 +735,11 @@ cli.add_typer(
     name="deployments",
     help="Subcommands for managing the Deployments.",
 )
+cli.add_typer(
+    hosting_cli,
+    name="apps",
+    help="Subcommands for managing the Deployments.",
+)
 cli.add_typer(
     custom_components_cli,
     name="component",