Skip to content

Commit cb412fb

Browse files
authored
🔥 Remove env vars from deploy workflow (#93)
1 parent 160b50f commit cb412fb

File tree

2 files changed

+0
-144
lines changed

2 files changed

+0
-144
lines changed

‎src/fastapi_cloud_cli/commands/deploy.py‎

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from fastapi_cloud_cli.utils.apps import AppConfig, get_app_config, write_app_config
2626
from fastapi_cloud_cli.utils.auth import is_logged_in
2727
from fastapi_cloud_cli.utils.cli import get_rich_toolkit, handle_http_errors
28-
from fastapi_cloud_cli.utils.env import validate_environment_variable_name
2928

3029
logger = logging.getLogger(__name__)
3130

@@ -229,12 +228,6 @@ def _get_apps(team_id: str) -> List[AppResponse]:
229228
return [AppResponse.model_validate(app) for app in data]
230229

231230

232-
def _create_environment_variables(app_id: str, env_vars: Dict[str, str]) -> None:
233-
with APIClient() as client:
234-
response = client.patch(f"/apps/{app_id}/environment-variables/", json=env_vars)
235-
response.raise_for_status()
236-
237-
238231
def _stream_build_logs(deployment_id: str) -> Generator[str, None, None]:
239232
with APIClient() as client:
240233
with client.stream(
@@ -399,45 +392,6 @@ def _wait_for_deployment(
399392
last_message_changed_at = time.monotonic() # pragma: no cover
400393

401394

402-
def _setup_environment_variables(toolkit: RichToolkit, app_id: str) -> None:
403-
if not toolkit.confirm("Do you want to setup environment variables?", tag="env"):
404-
return
405-
406-
toolkit.print_line()
407-
408-
env_vars = {}
409-
410-
while True:
411-
key = toolkit.input(
412-
"Enter the environment variable name: [ENTER to skip]", required=False
413-
)
414-
415-
if key.strip() == "":
416-
break
417-
418-
if not validate_environment_variable_name(key):
419-
toolkit.print(
420-
"[error]Invalid environment variable name.",
421-
)
422-
423-
else:
424-
value = toolkit.input(
425-
"Enter the environment variable value:", password=True
426-
)
427-
428-
env_vars[key] = value
429-
430-
toolkit.print_line()
431-
432-
toolkit.print_line()
433-
434-
with toolkit.progress("Setting up environment variables...") as progress:
435-
with handle_http_errors(progress):
436-
_create_environment_variables(app_id, env_vars)
437-
438-
progress.log("Environment variables set up successfully!")
439-
440-
441395
class SignupToWaitingList(BaseModel):
442396
email: EmailStr
443397
name: Optional[str] = None
@@ -605,9 +559,6 @@ def deploy(
605559
logger.debug("No app config found, configuring new app")
606560
app_config = _configure_app(toolkit, path_to_deploy=path_to_deploy)
607561
toolkit.print_line()
608-
609-
_setup_environment_variables(toolkit, app_config.app_id)
610-
toolkit.print_line()
611562
else:
612563
logger.debug("Existing app config found, proceeding with deployment")
613564
toolkit.print("Deploying app...")

‎tests/test_cli_deploy.py‎

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,6 @@ def test_exits_successfully_when_deployment_is_done(
386386
Keys.ENTER,
387387
*"demo",
388388
Keys.ENTER,
389-
Keys.RIGHT_ARROW,
390-
Keys.ENTER,
391389
]
392390

393391
team_data = _get_random_team()
@@ -642,8 +640,6 @@ def _deploy_without_waiting(respx_mock: respx.MockRouter, tmp_path: Path) -> Res
642640
Keys.ENTER,
643641
*"demo",
644642
Keys.ENTER,
645-
Keys.RIGHT_ARROW,
646-
Keys.ENTER,
647643
]
648644

649645
team_data = _get_random_team()
@@ -730,97 +726,6 @@ def test_does_not_duplicate_entry_in_git_ignore(
730726
assert git_ignore_path.read_text() == ".fastapicloud\n"
731727

732728

733-
@pytest.mark.respx(base_url=settings.base_api_url)
734-
def test_creates_environment_variables_during_app_setup(
735-
logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter
736-
) -> None:
737-
steps = [
738-
Keys.ENTER, # Setup and deploy
739-
Keys.ENTER, # Select team
740-
Keys.ENTER, # Create new app
741-
*"demo", # App name
742-
Keys.ENTER,
743-
Keys.ENTER, # Setup environment variables (Yes)
744-
*"API_KEY", # Environment variable name
745-
Keys.ENTER,
746-
*"secret123", # Environment variable value
747-
Keys.ENTER,
748-
Keys.ENTER, # Empty key to finish
749-
Keys.CTRL_C, # Exit before deployment
750-
]
751-
752-
team = _get_random_team()
753-
app_data = _get_random_app(team_id=team["id"])
754-
755-
respx_mock.get("/teams/").mock(return_value=Response(200, json={"data": [team]}))
756-
757-
respx_mock.post("/apps/", json={"name": "demo", "team_id": team["id"]}).mock(
758-
return_value=Response(201, json=app_data)
759-
)
760-
761-
env_vars_request = respx_mock.patch(
762-
f"/apps/{app_data['id']}/environment-variables/", json={"API_KEY": "secret123"}
763-
).mock(return_value=Response(200))
764-
765-
with changing_dir(tmp_path), patch(
766-
"rich_toolkit.container.getchar"
767-
) as mock_getchar:
768-
mock_getchar.side_effect = steps
769-
770-
result = runner.invoke(app, ["deploy"])
771-
772-
assert result.exit_code == 1
773-
assert env_vars_request.called
774-
assert "Environment variables set up successfully!" in result.output
775-
776-
777-
@pytest.mark.respx(base_url=settings.base_api_url)
778-
def test_rejects_invalid_environment_variable_names(
779-
logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter
780-
) -> None:
781-
steps = [
782-
Keys.ENTER, # Setup and deploy
783-
Keys.ENTER, # Select team
784-
Keys.ENTER, # Create new app
785-
*"demo", # App name
786-
Keys.ENTER,
787-
Keys.ENTER, # Setup environment variables (Yes)
788-
*"123-invalid", # Invalid environment variable name (starts with digit, contains hyphen)
789-
Keys.ENTER,
790-
*"VALID_KEY", # Valid environment variable name
791-
Keys.ENTER,
792-
*"value123", # Environment variable value
793-
Keys.ENTER,
794-
Keys.ENTER, # Empty key to finish
795-
Keys.CTRL_C, # Exit before deployment
796-
]
797-
798-
team = _get_random_team()
799-
app_data = _get_random_app(team_id=team["id"])
800-
801-
respx_mock.get("/teams/").mock(return_value=Response(200, json={"data": [team]}))
802-
803-
respx_mock.post("/apps/", json={"name": "demo", "team_id": team["id"]}).mock(
804-
return_value=Response(201, json=app_data)
805-
)
806-
807-
env_vars_request = respx_mock.patch(
808-
f"/apps/{app_data['id']}/environment-variables/", json={"VALID_KEY": "value123"}
809-
).mock(return_value=Response(200))
810-
811-
with changing_dir(tmp_path), patch(
812-
"rich_toolkit.container.getchar"
813-
) as mock_getchar:
814-
mock_getchar.side_effect = steps
815-
816-
result = runner.invoke(app, ["deploy"])
817-
818-
assert result.exit_code == 1
819-
assert env_vars_request.called
820-
assert "Invalid environment variable name." in result.output
821-
assert "Environment variables set up successfully!" in result.output
822-
823-
824729
@pytest.mark.respx(base_url=settings.base_api_url)
825730
def test_shows_error_for_invalid_waitlist_form_data(
826731
logged_out_cli: None, tmp_path: Path, respx_mock: respx.MockRouter

0 commit comments

Comments
 (0)