Hosting CLI: remove requirements generation when init, add back timeout for deploy command, remove deploy legacy command (#2179)
This commit is contained in:
parent
93dcc6300d
commit
adb26787c8
@ -185,19 +185,11 @@ class Config(Base):
|
|||||||
# Additional frontend packages to install.
|
# Additional frontend packages to install.
|
||||||
frontend_packages: List[str] = []
|
frontend_packages: List[str] = []
|
||||||
|
|
||||||
# Params to remove eventually.
|
|
||||||
# For rest are for deploy only.
|
|
||||||
# The rxdeploy url.
|
|
||||||
rxdeploy_url: Optional[str] = None
|
|
||||||
|
|
||||||
# The hosting service backend URL.
|
# The hosting service backend URL.
|
||||||
cp_backend_url: str = constants.Hosting.CP_BACKEND_URL
|
cp_backend_url: str = constants.Hosting.CP_BACKEND_URL
|
||||||
# The hosting service frontend URL.
|
# The hosting service frontend URL.
|
||||||
cp_web_url: str = constants.Hosting.CP_WEB_URL
|
cp_web_url: str = constants.Hosting.CP_WEB_URL
|
||||||
|
|
||||||
# The username.
|
|
||||||
username: Optional[str] = None
|
|
||||||
|
|
||||||
# The worker class used in production mode
|
# The worker class used in production mode
|
||||||
gunicorn_worker_class: str = "uvicorn.workers.UvicornH11Worker"
|
gunicorn_worker_class: str = "uvicorn.workers.UvicornH11Worker"
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class RequirementsTxt(SimpleNamespace):
|
|||||||
# The requirements.txt file.
|
# The requirements.txt file.
|
||||||
FILE = "requirements.txt"
|
FILE = "requirements.txt"
|
||||||
# The partial text used to form requirement that pins a reflex version
|
# The partial text used to form requirement that pins a reflex version
|
||||||
DEFAULTS_STUB = f"{Reflex.MODULE_NAME}=="
|
DEFAULTS_STUB = f"{Reflex.MODULE_NAME}>="
|
||||||
|
|
||||||
|
|
||||||
# The deployment URL.
|
# The deployment URL.
|
||||||
|
@ -14,7 +14,6 @@ from datetime import datetime
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
import httpx
|
|
||||||
import typer
|
import typer
|
||||||
import typer.core
|
import typer.core
|
||||||
from alembic.util.exc import CommandError
|
from alembic.util.exc import CommandError
|
||||||
@ -258,47 +257,6 @@ def run(
|
|||||||
_run(env, frontend, backend, frontend_port, backend_port, backend_host, loglevel)
|
_run(env, frontend, backend, frontend_port, backend_port, backend_host, loglevel)
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
|
||||||
def deploy_legacy(
|
|
||||||
dry_run: bool = typer.Option(False, help="Whether to run a dry run."),
|
|
||||||
loglevel: constants.LogLevel = typer.Option(
|
|
||||||
console._LOG_LEVEL, help="The log level to use."
|
|
||||||
),
|
|
||||||
):
|
|
||||||
"""Deploy the app to the Reflex hosting service."""
|
|
||||||
# Set the log level.
|
|
||||||
console.set_log_level(loglevel)
|
|
||||||
|
|
||||||
# Show system info
|
|
||||||
exec.output_system_info()
|
|
||||||
|
|
||||||
# Check if the deploy url is set.
|
|
||||||
if config.rxdeploy_url is None:
|
|
||||||
console.info("This feature is coming soon!")
|
|
||||||
return
|
|
||||||
|
|
||||||
# Compile the app in production mode.
|
|
||||||
export(loglevel=loglevel)
|
|
||||||
|
|
||||||
# Exit early if this is a dry run.
|
|
||||||
if dry_run:
|
|
||||||
return
|
|
||||||
|
|
||||||
# Deploy the app.
|
|
||||||
data = {"userId": config.username, "projectId": config.app_name}
|
|
||||||
original_response = httpx.get(config.rxdeploy_url, params=data)
|
|
||||||
response = original_response.json()
|
|
||||||
frontend = response["frontend_resources_url"]
|
|
||||||
backend = response["backend_resources_url"]
|
|
||||||
|
|
||||||
# Upload the frontend and backend.
|
|
||||||
with open(constants.ComponentName.FRONTEND.zip(), "rb") as f:
|
|
||||||
httpx.put(frontend, data=f) # type: ignore
|
|
||||||
|
|
||||||
with open(constants.ComponentName.BACKEND.zip(), "rb") as f:
|
|
||||||
httpx.put(backend, data=f) # type: ignore
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
def export(
|
def export(
|
||||||
zipping: bool = typer.Option(
|
zipping: bool = typer.Option(
|
||||||
@ -569,7 +527,7 @@ def deploy(
|
|||||||
enabled_regions = pre_deploy_response.enabled_regions
|
enabled_regions = pre_deploy_response.enabled_regions
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
console.error(f"Unable to prepare deployment")
|
console.error(f"Unable to prepare deployment due to: {ex}")
|
||||||
raise typer.Exit(1) from ex
|
raise typer.Exit(1) from ex
|
||||||
|
|
||||||
# The app prefix should not change during the time of preparation
|
# The app prefix should not change during the time of preparation
|
||||||
|
@ -142,6 +142,8 @@ def save_token_to_config(token: str, code: str | None = None):
|
|||||||
if code:
|
if code:
|
||||||
hosting_config["code"] = code
|
hosting_config["code"] = code
|
||||||
try:
|
try:
|
||||||
|
if not os.path.exists(constants.Reflex.DIR):
|
||||||
|
os.makedirs(constants.Reflex.DIR)
|
||||||
with open(constants.Hosting.HOSTING_JSON, "w") as config_file:
|
with open(constants.Hosting.HOSTING_JSON, "w") as config_file:
|
||||||
json.dump(hosting_config, config_file)
|
json.dump(hosting_config, config_file)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
@ -324,22 +326,22 @@ def prepare_deploy(
|
|||||||
enabled_regions=response_json.get("enabled_regions"),
|
enabled_regions=response_json.get("enabled_regions"),
|
||||||
)
|
)
|
||||||
except httpx.RequestError as re:
|
except httpx.RequestError as re:
|
||||||
console.error(f"Unable to prepare launch due to {re}.")
|
console.debug(f"Unable to prepare launch due to {re}.")
|
||||||
raise Exception(str(re)) from re
|
raise Exception(str(re)) from re
|
||||||
except httpx.HTTPError as he:
|
except httpx.HTTPError as he:
|
||||||
console.error(f"Unable to prepare deploy due to {he}.")
|
console.debug(f"Unable to prepare deploy due to {he}.")
|
||||||
raise Exception(f"{he}") from he
|
raise Exception(f"{he}") from he
|
||||||
except json.JSONDecodeError as jde:
|
except json.JSONDecodeError as jde:
|
||||||
console.error(f"Server did not respond with valid json: {jde}")
|
console.debug(f"Server did not respond with valid json: {jde}")
|
||||||
raise Exception("internal errors") from jde
|
raise Exception("internal errors") from jde
|
||||||
except (KeyError, ValidationError) as kve:
|
except (KeyError, ValidationError) as kve:
|
||||||
console.error(f"The server response format is unexpected {kve}")
|
console.debug(f"The server response format is unexpected {kve}")
|
||||||
raise Exception("internal errors") from kve
|
raise Exception("internal errors") from kve
|
||||||
except ValueError as ve:
|
except ValueError as ve:
|
||||||
# This is a recognized client error, currently indicates forbidden
|
# This is a recognized client error, currently indicates forbidden
|
||||||
raise Exception(f"{ve}") from ve
|
raise Exception(f"{ve}") from ve
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
console.error(f"Unexpected error: {ex}.")
|
console.debug(f"Unexpected error: {ex}.")
|
||||||
raise Exception("internal errors") from ex
|
raise Exception("internal errors") from ex
|
||||||
|
|
||||||
|
|
||||||
@ -465,6 +467,7 @@ def deploy(
|
|||||||
headers=authorization_header(token),
|
headers=authorization_header(token),
|
||||||
data=params.dict(exclude_none=True),
|
data=params.dict(exclude_none=True),
|
||||||
files=files,
|
files=files,
|
||||||
|
timeout=HTTP_REQUEST_TIMEOUT,
|
||||||
)
|
)
|
||||||
# If the server explicitly states bad request,
|
# If the server explicitly states bad request,
|
||||||
# display a different error
|
# display a different error
|
||||||
|
@ -61,6 +61,7 @@ def test_deploy_required_args_missing(args):
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def setup_env_authentication(mocker):
|
def setup_env_authentication(mocker):
|
||||||
mocker.patch("reflex.utils.prerequisites.check_initialized")
|
mocker.patch("reflex.utils.prerequisites.check_initialized")
|
||||||
|
mocker.patch("reflex.utils.dependency.check_requirements")
|
||||||
mocker.patch("reflex.utils.hosting.authenticated_token", return_value="fake-token")
|
mocker.patch("reflex.utils.hosting.authenticated_token", return_value="fake-token")
|
||||||
mocker.patch("time.sleep")
|
mocker.patch("time.sleep")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user