Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding hosting v1 support #4309

Merged
merged 12 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
134 changes: 134 additions & 0 deletions reflex/reflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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
Expand Down Expand Up @@ -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(
Expand All @@ -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()

Expand Down Expand Up @@ -599,13 +624,122 @@ 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(
deployments_cli,
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",
Expand Down
Loading